Class: Puppet::Pops::Evaluator::JsonStrictLiteralEvaluator
- 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
', '
Instance Method Summary collapse
-
#initialize ⇒ JsonStrictLiteralEvaluator
constructor
A new instance of JsonStrictLiteralEvaluator.
- #literal(ast) ⇒ Object
- #literal_ConcatenatedString(o) ⇒ Object
- #literal_Factory(o) ⇒ Object
- #literal_LiteralBoolean(o) ⇒ Object
- #literal_LiteralHash(o) ⇒ Object
- #literal_LiteralList(o) ⇒ Object
- #literal_LiteralNumber(o) ⇒ Object
- #literal_LiteralString(o) ⇒ Object
- #literal_LiteralUndef(o) ⇒ Object
- #literal_Object(o) ⇒ Object
- #literal_Program(o) ⇒ Object
- #literal_QualifiedName(o) ⇒ Object
Constructor Details
#initialize ⇒ JsonStrictLiteralEvaluator
Returns a new instance of JsonStrictLiteralEvaluator.
26 27 28 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 26 def initialize @@literal_visitor ||= Puppet::Pops::Visitor.new(self, "literal", 0, 0) end |
Instance Method Details
#literal(ast) ⇒ Object
30 31 32 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 30 def literal(ast) @@literal_visitor.visit_this_0(self, ast) end |
#literal_ConcatenatedString(o) ⇒ Object
66 67 68 69 70 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 66 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
38 39 40 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 38 def literal_Factory(o) literal(o.model) end |
#literal_LiteralBoolean(o) ⇒ Object
58 59 60 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 58 def literal_LiteralBoolean(o) o.value end |
#literal_LiteralHash(o) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 76 def literal_LiteralHash(o) o.entries.each_with_object({}) do |entry, result| key = literal(entry.key) throw :not_literal unless key.is_a?(String) result[key] = literal(entry.value) end end |
#literal_LiteralList(o) ⇒ Object
72 73 74 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 72 def literal_LiteralList(o) o.values.map { |v| literal(v) } end |
#literal_LiteralNumber(o) ⇒ Object
54 55 56 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 54 def literal_LiteralNumber(o) o.value end |
#literal_LiteralString(o) ⇒ Object
46 47 48 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 46 def literal_LiteralString(o) o.value end |
#literal_LiteralUndef(o) ⇒ Object
62 63 64 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 62 def literal_LiteralUndef(o) nil end |
#literal_Object(o) ⇒ Object
34 35 36 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 34 def literal_Object(o) throw :not_literal end |
#literal_Program(o) ⇒ Object
42 43 44 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 42 def literal_Program(o) literal(o.body) end |
#literal_QualifiedName(o) ⇒ Object
50 51 52 |
# File 'lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb', line 50 def literal_QualifiedName(o) o.value end |