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

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

Overview

QualifiedReference # i.e. File, FooBar

Direct Known Subclasses

Validation::Checker4_0

Constant Summary collapse

COMMA_SEPARATOR =
', '.freeze

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_ConcatenatedString(o) ⇒ Object



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

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



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

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

#literal_LiteralList(o) ⇒ Object



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

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