Class: Puppet::Pops::Evaluator::LiteralEvaluator

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

Overview

AccessExpresion

Direct Known Subclasses

Validation::Checker4_0

Constant Summary collapse

COMMA_SEPARATOR =
', '

Instance Method Summary collapse

Constructor Details

#initializeLiteralEvaluator

Returns a new instance of LiteralEvaluator.



21
22
23
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 21

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

Instance Method Details

#literal(ast) ⇒ Object



25
26
27
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 25

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

#literal_AccessExpression(o) ⇒ Object



73
74
75
76
77
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 73

def literal_AccessExpression(o)
  # to prevent parameters with [[]] like Optional[[String]]
  throw :not_literal if o.keys.size == 1 && o.keys[0].is_a?(Model::LiteralList)
  o.keys.map { |v| literal(v) }
end

#literal_ConcatenatedString(o) ⇒ Object



83
84
85
86
87
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 83

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?(Model::LiteralString)
  o.segments[0].value
end

#literal_Factory(o) ⇒ Object



33
34
35
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 33

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

#literal_LiteralBoolean(o) ⇒ Object



53
54
55
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 53

def literal_LiteralBoolean(o)
  o.value
end

#literal_LiteralDefault(o) ⇒ Object



61
62
63
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 61

def literal_LiteralDefault(o)
  :default
end

#literal_LiteralHash(o) ⇒ Object



93
94
95
96
97
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 93

def literal_LiteralHash(o)
  o.entries.each_with_object({}) do |entry, result|
    result[literal(entry.key)] = literal(entry.value)
  end
end

#literal_LiteralList(o) ⇒ Object



89
90
91
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 89

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

#literal_LiteralNumber(o) ⇒ Object



49
50
51
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 49

def literal_LiteralNumber(o)
  o.value
end

#literal_LiteralRegularExpression(o) ⇒ Object



65
66
67
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 65

def literal_LiteralRegularExpression(o)
  o.value
end

#literal_LiteralString(o) ⇒ Object



41
42
43
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 41

def literal_LiteralString(o)
  o.value
end

#literal_LiteralUndef(o) ⇒ Object



57
58
59
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 57

def literal_LiteralUndef(o)
  nil
end

#literal_Object(o) ⇒ Object



29
30
31
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 29

def literal_Object(o)
  throw :not_literal
end

#literal_Program(o) ⇒ Object



37
38
39
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 37

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

#literal_QualifiedName(o) ⇒ Object



45
46
47
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 45

def literal_QualifiedName(o)
  o.value
end

#literal_QualifiedReference(o) ⇒ Object



69
70
71
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 69

def literal_QualifiedReference(o)
  o.value
end

#literal_UnaryMinusExpression(o) ⇒ Object



79
80
81
# File 'lib/puppet/pops/evaluator/literal_evaluator.rb', line 79

def literal_UnaryMinusExpression(o)
  -literal(o.expr)
end