Sha256: 3657bc8e4634bded52852830c59b199a7ede7263eae517eb5f40951eda979b84

Contents?: true

Size: 1.52 KB

Versions: 20

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true
module Puppet::Pops
module Evaluator
# Literal values for
# String (not containing interpolation)
# Numbers
# Booleans
# Undef (produces nil)
# Array
# Hash
# QualifiedName
# Default (produced :default)
# Regular Expression (produces ruby regular expression)
#
# Not considered literal
# QualifiedReference  # i.e. File, FooBar
#
class LiteralEvaluator

  COMMA_SEPARATOR = ', '

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

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

  def literal_Object(o)
    throw :not_literal
  end

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

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

  def literal_LiteralString(o)
    o.value
  end

  def literal_QualifiedName(o)
    o.value
  end

  def literal_LiteralNumber(o)
    o.value
  end

  def literal_LiteralBoolean(o)
    o.value
  end

  def literal_LiteralUndef(o)
    nil
  end

  def literal_LiteralDefault(o)
    :default
  end

  def literal_LiteralRegularExpression(o)
    o.value
  end

  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

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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.0-x86-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.0-x64-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.0-universal-darwin lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.1 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.1-x86-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.1-x64-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.3.1-universal-darwin lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.2.0 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.2.0-x86-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.2.0-x64-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.2.0-universal-darwin lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.1.0 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.1.0-x86-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.1.0-x64-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.1.0-universal-darwin lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.0.1 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.0.1-x86-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.0.1-x64-mingw32 lib/puppet/pops/evaluator/literal_evaluator.rb
puppet-8.0.1-universal-darwin lib/puppet/pops/evaluator/literal_evaluator.rb