Class: Puppet::Pops::Evaluator::JsonStrictLiteralEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb

Overview

Literal values for

* String
* Numbers
* Booleans
* Undef (produces nil)
* Array
* Hash where keys must be Strings
* QualifiedName

Not considered literal:

* QualifiedReference  # i.e. File, FooBar
* Default is not accepted as being literal
* Regular Expression is not accepted as being literal
* Hash with non String keys
* String with interpolation

Constant Summary collapse

COMMA_SEPARATOR =

include Puppet::Pops::Utils

', '.freeze

Instance Method Summary collapse

Constructor Details

#initializeJsonStrictLiteralEvaluator

Returns a new instance of JsonStrictLiteralEvaluator.



24
25
26
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 24

def initialize
  @@literal_visitor ||= Puppet::Pops::Visitor.new(self, "literal", 0, 0)
end

Instance Method Details

#literal(ast) ⇒ Object



28
29
30
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 28

def literal(ast)
  @@literal_visitor.visit_this_0(self, ast)
end

#literal_ConcatenatedString(o) ⇒ Object



64
65
66
67
68
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 64

def literal_ConcatenatedString(o)
  # use double quoted string value if there is no interpolation
  throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Puppet::Pops::Model::LiteralString)
  o.segments[0].value
end

#literal_Factory(o) ⇒ Object



36
37
38
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 36

def literal_Factory(o)
  literal(o.model)
end

#literal_LiteralBoolean(o) ⇒ Object



56
57
58
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 56

def literal_LiteralBoolean(o)
  o.value
end

#literal_LiteralHash(o) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 74

def literal_LiteralHash(o)
  o.entries.reduce({}) do |result, entry|
    key = literal(entry.key)
    throw :not_literal unless key.is_a?(String)
    result[key] = literal(entry.value)
    result
  end
end

#literal_LiteralList(o) ⇒ Object



70
71
72
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 70

def literal_LiteralList(o)
  o.values.map {|v| literal(v) }
end

#literal_LiteralNumber(o) ⇒ Object



52
53
54
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 52

def literal_LiteralNumber(o)
  o.value
end

#literal_LiteralString(o) ⇒ Object



44
45
46
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 44

def literal_LiteralString(o)
  o.value
end

#literal_LiteralUndef(o) ⇒ Object



60
61
62
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 60

def literal_LiteralUndef(o)
  nil
end

#literal_Object(o) ⇒ Object



32
33
34
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 32

def literal_Object(o)
  throw :not_literal
end

#literal_Program(o) ⇒ Object



40
41
42
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 40

def literal_Program(o)
  literal(o.body)
end

#literal_QualifiedName(o) ⇒ Object



48
49
50
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 48

def literal_QualifiedName(o)
  o.value
end