403Webshell
Server IP : 77.68.64.21  /  Your IP : 216.73.217.59
Web Server : Apache
System : Linux hp3-wp-1011352.hostingp3.local 3.10.0-1160.144.1.el7.tuxcare.els9.x86_64 #1 SMP Fri Jul 10 17:06:31 UTC 2026 x86_64
User : csh2516497 ( 2094697)
PHP Version : 8.3.30
Disable Function : shell_exec,exec,system,popen,set_time_limit
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/ruby/vendor_ruby/puppet/pops/parser/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/ruby/vendor_ruby/puppet/pops/parser/egrammar.ra
# vim: syntax=ruby

# Parser using the Pops model, expression based

class Puppet::Pops::Parser::Parser

token STRING DQPRE DQMID DQPOST
token WORD
token LBRACK  RBRACK LBRACE RBRACE SYMBOL FARROW COMMA TRUE
token FALSE EQUALS APPENDS DELETES LESSEQUAL NOTEQUAL DOT COLON LLCOLLECT RRCOLLECT
token QMARK LPAREN RPAREN ISEQUAL GREATEREQUAL GREATERTHAN LESSTHAN
token IF ELSE
token DEFINE ELSIF VARIABLE CLASS INHERITS NODE BOOLEAN
token NAME SEMIC CASE DEFAULT AT ATAT LCOLLECT RCOLLECT CLASSREF
token NOT OR AND UNDEF PARROW PLUS MINUS TIMES DIV LSHIFT RSHIFT UMINUS
token MATCH NOMATCH REGEX IN_EDGE OUT_EDGE IN_EDGE_SUB OUT_EDGE_SUB
token IN UNLESS PIPE
token LAMBDA SELBRACE
token NUMBER
token HEREDOC SUBLOCATE
token RENDER_STRING RENDER_EXPR EPP_START EPP_END EPP_END_TRIM
token FUNCTION
token LOW

prechigh
  left  HIGH
  left  SEMIC
  left  PIPE
  left  LPAREN
  left  RPAREN
  left  AT ATAT
  left  DOT
  left  CALL
  nonassoc EPP_START
  left  LBRACK LISTSTART
  left  RBRACK
  left  QMARK
  left  LCOLLECT LLCOLLECT
  right NOT
  nonassoc UMINUS
  left  IN
  left  MATCH NOMATCH
  left  TIMES DIV MODULO
  left  MINUS PLUS
  left  LSHIFT RSHIFT
  left  NOTEQUAL ISEQUAL
  left  GREATEREQUAL GREATERTHAN LESSTHAN LESSEQUAL
  left  AND
  left  OR
  right APPENDS DELETES EQUALS
  left  LBRACE
  left  SELBRACE
  left  RBRACE
  left  IN_EDGE OUT_EDGE IN_EDGE_SUB OUT_EDGE_SUB
  left  TITLE_COLON
  left  CASE_COLON
  left  FARROW
  left  COMMA
  nonassoc RENDER_EXPR
  nonassoc RENDER_STRING
  left  LOW
preclow

rule
# Produces [Model::BlockExpression, Model::Expression, nil] depending on multiple statements, single statement or empty
program
  : statements { result = create_program(Factory.block_or_expression(*val[0])) }
  | epp_expression { result = create_program(Factory.block_or_expression(*val[0])) }
  | nil

# Produces a semantic model (non validated, but semantically adjusted).
statements
  : syntactic_statements { result = transform_calls(val[0]) }

# Change may have issues with nil; i.e. program is a sequence of nils/nops
# Simplified from original which had validation for top level constructs - see statement rule
# Produces Array<Model::Expression>
syntactic_statements
  : syntactic_statement                            { result = [val[0]]}
  | syntactic_statements SEMIC syntactic_statement { result = val[0].push val[2] }
  | syntactic_statements syntactic_statement       { result = val[0].push val[1] }

# Produce a single expression or Array of expression
syntactic_statement
  : any_expression                            { result = val[0] }
  | syntactic_statement COMMA any_expression  { result = aryfy(val[0]).push val[2] }

any_expression
  : relationship_expression

relationship_expression
  : resource_expression                                     =LOW  { result = val[0] }
  | relationship_expression IN_EDGE      relationship_expression  { result = val[0].relop(val[1][:value], val[2]); loc result, val[1] }
  | relationship_expression IN_EDGE_SUB  relationship_expression  { result = val[0].relop(val[1][:value], val[2]); loc result, val[1] }
  | relationship_expression OUT_EDGE     relationship_expression  { result = val[0].relop(val[1][:value], val[2]); loc result, val[1] }
  | relationship_expression OUT_EDGE_SUB relationship_expression  { result = val[0].relop(val[1][:value], val[2]); loc result, val[1] }

#---EXPRESSION
#
# Produces Model::Expression
expression
  : higher_precedence
  | expression LBRACK       expressions RBRACK =LBRACK { result = val[0][*val[2]]         ; loc result, val[0], val[3] }
  | expression IN           expression                 { result = val[0].in val[2]        ; loc result, val[1] }
  | expression MATCH        expression                 { result = val[0] =~  val[2]       ; loc result, val[1] }
  | expression NOMATCH      expression                 { result = val[0].mne val[2]       ; loc result, val[1] }
  | expression PLUS         expression                 { result = val[0] +   val[2]       ; loc result, val[1] }
  | expression MINUS        expression                 { result = val[0] -   val[2]       ; loc result, val[1] }
  | expression DIV          expression                 { result = val[0] /   val[2]       ; loc result, val[1] }
  | expression TIMES        expression                 { result = val[0] *   val[2]       ; loc result, val[1] }
  | expression MODULO       expression                 { result = val[0] %   val[2]       ; loc result, val[1] }
  | expression LSHIFT       expression                 { result = val[0] <<  val[2]       ; loc result, val[1] }
  | expression RSHIFT       expression                 { result = val[0] >>  val[2]       ; loc result, val[1] }
  |            MINUS        expression         =UMINUS { result = val[1].minus()          ; loc result, val[0] }
  | expression NOTEQUAL     expression                 { result = val[0].ne  val[2]       ; loc result, val[1] }
  | expression ISEQUAL      expression                 { result = val[0] ==  val[2]       ; loc result, val[1] }
  | expression GREATERTHAN  expression                 { result = val[0] >   val[2]       ; loc result, val[1] }
  | expression GREATEREQUAL expression                 { result = val[0] >=  val[2]       ; loc result, val[1] }
  | expression LESSTHAN     expression                 { result = val[0] <   val[2]       ; loc result, val[1] }
  | expression LESSEQUAL    expression                 { result = val[0] <=  val[2]       ; loc result, val[1] }
  |            NOT          expression                 { result = val[1].not              ; loc result, val[0] }
  | expression AND          expression                 { result = val[0].and val[2]       ; loc result, val[1] }
  | expression OR           expression                 { result = val[0].or  val[2]       ; loc result, val[1] }
  | expression EQUALS       expression                 { result = val[0].set(val[2])      ; loc result, val[1] }
  | expression APPENDS      expression                 { result = val[0].plus_set(val[2]) ; loc result, val[1] }
  | expression DELETES      expression                 { result = val[0].minus_set(val[2]); loc result, val[1] }
  | expression QMARK selector_entries                  { result = val[0].select(*val[2])  ; loc result, val[0] }
  |            LPAREN       expression RPAREN          { result = val[1].paren()          ; loc result, val[0] }

#---EXPRESSIONS
#   (e.g. argument list)
#
# This expression list can not contain function calls without parentheses around arguments
# Produces Array<Model::Expression>
expressions
  : expression                   { result = [val[0]] }
  | expressions COMMA expression { result = val[0].push(val[2]) }

# These go through a chain of left recursion, ending with primary_expression
higher_precedence
  : call_function_expression

primary_expression
  : literal_expression
  | variable
  | call_method_with_lambda_expression
  | collection_expression
  | case_expression
  | if_expression
  | unless_expression
  | definition_expression
  | hostclass_expression
  | node_definition_expression
  | epp_render_expression
  | function_definition

# Allways have the same value
literal_expression
  : array
  | boolean
  | default
  | hash
  | regex
  | text_or_name
  | number
  | type
  | undef

text_or_name
  : name       { result = val[0] }
  | quotedtext { result = val[0] }

#---CALL FUNCTION
#
# Produces Model::CallNamedFunction

call_function_expression
  : primary_expression LPAREN expressions endcomma RPAREN {
      result = Factory.CALL_NAMED(val[0], true, val[2])
      loc result, val[0], val[4]
    }
  | primary_expression LPAREN RPAREN {
      result = Factory.CALL_NAMED(val[0], true, [])
      loc result, val[0], val[2]
    }
  | primary_expression LPAREN expressions endcomma RPAREN lambda {
      result = Factory.CALL_NAMED(val[0], true, val[2])
      loc result, val[0], val[4]
      result.lambda = val[5]
    }
  | primary_expression LPAREN RPAREN  lambda {
      result = Factory.CALL_NAMED(val[0], true, [])
      loc result, val[0], val[2]
      result.lambda = val[3]
    }
  | primary_expression = LOW { result = val[0] }

#---CALL METHOD
#
call_method_with_lambda_expression
  : call_method_expression         =LOW { result = val[0] }
  | call_method_expression lambda  { result = val[0]; val[0].lambda = val[1] }

  call_method_expression
    : named_access LPAREN expressions RPAREN { result = Factory.CALL_METHOD(val[0], val[2]); loc result, val[1], val[3] }
    | named_access LPAREN RPAREN             { result = Factory.CALL_METHOD(val[0], []); loc result, val[1], val[3] }
    | named_access =LOW                      { result = Factory.CALL_METHOD(val[0], []); loc result, val[0] }

  # TODO: It may be of value to access named elements of types too
  named_access
    : expression DOT NAME {
        result = val[0].dot(Factory.fqn(val[2][:value]))
        loc result, val[1], val[2]
      }

#---LAMBDA
#
# This is a temporary switch while experimenting with concrete syntax
# One should be picked for inclusion in puppet.

# Lambda with parameters to the left of the body
lambda
  : lambda_parameter_list lambda_rest {
      result = Factory.LAMBDA(val[0], val[1])
#      loc result, val[1] # TODO
    }

lambda_rest
  : LBRACE statements RBRACE { result = val[1] }
  | LBRACE RBRACE { result = nil }

# Produces Array<Model::Parameter>
lambda_parameter_list
  : PIPE PIPE                     { result = [] }
  | PIPE parameters endcomma PIPE { result = val[1] }

#---CONDITIONALS
#

#--IF
#
# Produces Model::IfExpression
if_expression
  : IF if_part {
      result = val[1]
      loc(result, val[0], val[1])
    }

  # Produces Model::IfExpression
  if_part
    : expression LBRACE statements RBRACE else {
        result = Factory.IF(val[0], Factory.block_or_expression(*val[2]), val[4])
        loc(result, val[0], (val[4] ? val[4] : val[3]))
      }
    | expression LBRACE RBRACE else {
        result = Factory.IF(val[0], nil, val[3])
        loc(result, val[0], (val[3] ? val[3] : val[2]))
      }

  # Produces [Model::Expression, nil] - nil if there is no else or elsif part
  else
    : # nothing
    | ELSIF if_part {
        result = val[1]
        loc(result, val[0], val[1])
      }
    | ELSE LBRACE statements RBRACE {
        result = Factory.block_or_expression(*val[2])
        loc result, val[0], val[3]
      }
    | ELSE LBRACE RBRACE {
        result = nil # don't think a nop is needed here either
      }

#--UNLESS
#
# Changed from Puppet 3x where there is no else part on unless
#
unless_expression
  : UNLESS expression LBRACE statements RBRACE unless_else {
      result = Factory.UNLESS(val[1], Factory.block_or_expression(*val[3]), val[5])
      loc result, val[0], val[4]
    }
  | UNLESS expression LBRACE RBRACE unless_else {
      result = Factory.UNLESS(val[1], nil, nil)
      loc result, val[0], val[4]
    }

  # Different from else part of if, since "elsif" is not supported, but 'else' is
  #
  # Produces [Model::Expression, nil] - nil if there is no else or elsif part
  unless_else
    : # nothing
    | ELSE LBRACE statements RBRACE {
        result = Factory.block_or_expression(*val[2])
        loc result, val[0], val[3]
      }
    | ELSE LBRACE RBRACE {
        result = nil # don't think a nop is needed here either
      }

#--- CASE EXPRESSION
#
# Produces Model::CaseExpression
case_expression
  : CASE expression LBRACE case_options RBRACE {
      result = Factory.CASE(val[1], *val[3])
      loc result, val[0], val[4]
    }

  # Produces Array<Model::CaseOption>
  case_options
    : case_option               { result = [val[0]] }
    | case_options case_option { result = val[0].push val[1] }

  # Produced Model::CaseOption (aka When)
  case_option
    : expressions case_colon LBRACE statements RBRACE {
        result = Factory.WHEN(val[0], val[3])
        loc result, val[1], val[4]
      }
    | expressions case_colon LBRACE RBRACE = LOW {
        result = Factory.WHEN(val[0], nil)
        loc result, val[1], val[3]
      }

  case_colon: COLON =CASE_COLON { result = val[0] }

  # This special construct is required or racc will produce the wrong result when the selector entry
  # LHS is generalized to any expression (LBRACE looks like a hash). Thus it is not possible to write
  # a selector with a single entry where the entry LHS is a hash.
  # The SELBRACE token is a LBRACE that follows a QMARK, and this is produced by the lexer with a lookback
  # Produces Array<Model::SelectorEntry>
  #
  selector_entries
    : selector_entry
    | SELBRACE selector_entry_list endcomma RBRACE {
        result = val[1]
      }

  # Produces Array<Model::SelectorEntry>
  selector_entry_list
    : selector_entry                           { result = [val[0]] }
    | selector_entry_list COMMA selector_entry { result = val[0].push val[2] }

  # Produces a Model::SelectorEntry
  # This FARROW wins over FARROW in Hash
  selector_entry
    : expression FARROW expression { result = Factory.MAP(val[0], val[2]) ; loc result, val[1] }

#---RESOURCE
#
# Produces [Model::ResourceExpression, Model::ResourceDefaultsExpression]

# The resource expression parses a generalized syntax and then selects the correct
# resulting model based on the combinatoin of the LHS and what follows.
# It also handled exported and virtual resources, and the class case
#
resource_expression
  : expression =LOW {
      result = val[0]
    }
  | at expression LBRACE resourceinstances endsemi RBRACE {
      result = case Factory.resource_shape(val[1])
      when :resource, :class
        tmp = Factory.RESOURCE(Factory.fqn(token_text(val[1])), val[3])
        tmp.form = val[0]
        tmp
      when :defaults
        error val[1], "A resource default can not be virtual or exported"
      when :override
        error val[1], "A resource override can not be virtual or exported"
      else
        error val[1], "Expression is not valid as a resource, resource-default, or resource-override"
      end
      loc result, val[1], val[4]
    }
  | at expression LBRACE attribute_operations endcomma RBRACE {
      result = case Factory.resource_shape(val[1])
      when :resource, :class, :defaults, :override
        error val[1], "Defaults are not virtualizable"
      else
        error val[1], "Expression is not valid as a resource, resource-default, or resource-override"
      end
    }
  | expression LBRACE resourceinstances endsemi RBRACE {
      result = case Factory.resource_shape(val[0])
      when :resource, :class
        Factory.RESOURCE(Factory.fqn(token_text(val[0])), val[2])
      when :defaults
        error val[1], "A resource default can not specify a resource name"
      when :override
        error val[1], "A resource override does not allow override of name of resource"
      else
        error val[1], "Expression is not valid as a resource, resource-default, or resource-override"
      end
      loc result, val[0], val[4]
    }
  | expression LBRACE attribute_operations endcomma RBRACE {
      result = case Factory.resource_shape(val[0])
      when :resource, :class
        # This catches deprecated syntax.
        # If the attribute operations does not include +>, then the found expression
        # is actually a LEFT followed by LITERAL_HASH
        #
        unless tmp = transform_resource_wo_title(val[0], val[2])
          error val[1], "Syntax error resource body without title or hash with +>"
        end
        tmp
      when :defaults
        Factory.RESOURCE_DEFAULTS(val[0], val[2])
      when :override
        # This was only done for override in original - TODO shuld it be here at all
        Factory.RESOURCE_OVERRIDE(val[0], val[2])
      else
        error val[0], "Expression is not valid as a resource, resource-default, or resource-override"
      end
      loc result, val[0], val[4]
    }
  | at CLASS LBRACE resourceinstances endsemi RBRACE {
        result = Factory.RESOURCE(Factory.fqn(token_text(val[1])), val[3])
        result.form = val[0]
        loc result, val[1], val[5]
    }
  | CLASS LBRACE resourceinstances endsemi RBRACE {
        result = Factory.RESOURCE(Factory.fqn(token_text(val[0])), val[2])
        loc result, val[0], val[4]
    }

  resourceinst
    : expression title_colon attribute_operations endcomma { result = Factory.RESOURCE_BODY(val[0], val[2]) }

  title_colon : COLON =TITLE_COLON { result = val[0] }

  resourceinstances
    : resourceinst                         { result = [val[0]] }
    | resourceinstances SEMIC resourceinst { result = val[0].push val[2] }

  # Produces Symbol corresponding to resource form
  #
  at
    : AT    { result = :virtual  }
    | AT AT { result = :exported }
    | ATAT  { result = :exported }

#---COLLECTION
#
# A Collection is a predicate applied to a set of objects with an implied context (used variables are
# attributes of the object.
# i.e. this is equivalent for source.select(QUERY).apply(ATTRIBUTE_OPERATIONS)
#
# Produces Model::CollectExpression
#
collection_expression
  : expression collect_query LBRACE attribute_operations endcomma RBRACE {
      result = Factory.COLLECT(val[0], val[1], val[3])
      loc result, val[0], val[5]
    }
  | expression collect_query =LOW {
      result = Factory.COLLECT(val[0], val[1], [])
      loc result, val[0], val[1]
    }

  collect_query
    : LCOLLECT  optional_query RCOLLECT  { result = Factory.VIRTUAL_QUERY(val[1])   ; loc result, val[0], val[2] }
    | LLCOLLECT optional_query RRCOLLECT { result = Factory.EXPORTED_QUERY(val[1])  ; loc result, val[0], val[2] }

  optional_query
    : nil
    | expression

#---ATTRIBUTE OPERATIONS
#
# (Not an expression)
#
# Produces Array<Model::AttributeOperation>
#
attribute_operations
  :                                                { result = [] }
  | attribute_operation                            { result = [val[0]] }
  | attribute_operations COMMA attribute_operation { result = val[0].push(val[2]) }

  # Produces String
  # QUESTION: Why is BOOLEAN valid as an attribute name?
  #
  attribute_name
    : NAME
    | keyword
    | BOOLEAN

  # In this version, illegal combinations are validated instead of producing syntax errors
  # (Can give nicer error message "+> is not applicable to...")
  # Produces Model::AttributeOperation
  #
  attribute_operation
    : attribute_name FARROW expression {
        result = Factory.ATTRIBUTE_OP(val[0][:value], :'=>', val[2])
        loc result, val[0], val[2]
      }
    | attribute_name PARROW expression {
        result = Factory.ATTRIBUTE_OP(val[0][:value], :'+>', val[2])
        loc result, val[0], val[2]
      }

#---DEFINE
#
# Produces Model::Definition
#
definition_expression
  : DEFINE classname parameter_list LBRACE opt_statements RBRACE {
      result = add_definition(Factory.DEFINITION(classname(val[1][:value]), val[2], val[4]))
      loc result, val[0], val[5]
      # New lexer does not keep track of this, this is done in validation
      if @lexer.respond_to?(:'indefine=')
        @lexer.indefine = false
      end
    }

#---HOSTCLASS
#
# Produces Model::HostClassDefinition
#
hostclass_expression
  : CLASS stacked_classname parameter_list classparent LBRACE opt_statements RBRACE {
      # Remove this class' name from the namestack as all nested classes have been parsed
      namepop
      result = add_definition(Factory.HOSTCLASS(classname(val[1][:value]), val[2], token_text(val[3]), val[5]))
      loc result, val[0], val[6]
    }

  # Record the classname so nested classes gets a fully qualified name at parse-time
  # This is a separate rule since racc does not support intermediate actions.
  #
  stacked_classname
    : classname { namestack(val[0][:value]) ; result = val[0] }

  opt_statements
    : statements
    | nil

  # Produces String, name or nil result
  classparent
    : nil
    | INHERITS classnameordefault { result = val[1] }

  # Produces String (this construct allows a class to be named "default" and to be referenced as
  # the parent class.
  # TODO: Investigate the validity
  # Produces a String (classname), or a token (DEFAULT).
  #
  classnameordefault
    : classname
    | DEFAULT

#---NODE
#
# Produces Model::NodeDefinition
#
node_definition_expression
  : NODE hostnames nodeparent LBRACE statements RBRACE {
      result = add_definition(Factory.NODE(val[1], val[2], val[4]))
      loc result, val[0], val[5]
    }
  | NODE hostnames nodeparent LBRACE RBRACE {
      result = add_definition(Factory.NODE(val[1], val[2], nil))
      loc result, val[0], val[4]
    }

  # Hostnames is not a list of names, it is a list of name matchers (including a Regexp).
  # (The old implementation had a special "Hostname" object with some minimal validation)
  #
  # Produces Array<Model::LiteralExpression>
  #
  hostnames
    : hostname                 { result = [result] }
    | hostnames COMMA hostname { result = val[0].push(val[2]) }

  # Produces a LiteralExpression (string, :default, or regexp)
  # String with interpolation is validated for better error message
  hostname
    : dotted_name { result = val[0] }
    | quotedtext  { result = val[0] }
    | DEFAULT     { result = Factory.literal(:default); loc result, val[0] }
    | regex

  dotted_name
    : NAME        { result = Factory.literal(val[0][:value]); loc result, val[0] }
    | dotted_name DOT NAME { result = Factory.concat(val[0], '.', val[2][:value]); loc result, val[0], val[2] }

  # Produces Expression, since hostname is an Expression
  nodeparent
    : nil
    | INHERITS hostname { result = val[1] }

#---FUNCTION DEFINITION
#
function_definition
  : FUNCTION { result = Factory.QNAME(val[0][:value]) ; loc result, val[0] }
  # For now the function word will just be reserved, in the future it will
  # produce a function definition
  # FUNCTION classname parameter_list LBRACE opt_statements RBRACE {
  #   result = add_definition(Factory.FUNCTION(val[1][:value], val[2], val[4]))
  #   loc result, val[0], val[5]
  # }

#---NAMES AND PARAMETERS COMMON TO SEVERAL RULES
#   Produces String
#   TODO: The error that "class" is not a valid classname is bad - classname rule is also used for other things
classname
  : NAME  { result = val[0] }
  | CLASS { error val[0], "'class' is not a valid classname" }

# Produces Array<Model::Parameter>
parameter_list
  : nil                               { result = [] }
  | LPAREN  RPAREN                    { result = [] }
  | LPAREN parameters endcomma RPAREN { result = val[1] }

# Produces Array<Model::Parameter>
parameters
  : parameter                  { result = [val[0]] }
  | parameters COMMA parameter { result = val[0].push(val[2]) }

# Produces Model::Parameter
parameter
  : VARIABLE EQUALS expression { result = Factory.PARAM(val[0][:value], val[2]) ; loc result, val[0] }
  | VARIABLE                   { result = Factory.PARAM(val[0][:value]); loc result, val[0] }

#--RESTRICTED EXPRESSIONS
#  i.e. where one could have expected an expression, but the set is limited

## What is allowed RHS of match operators (see expression)
#match_rvalue
#  : regex
#  | text_or_name

#--VARIABLE
#
variable
  : VARIABLE { result = Factory.fqn(val[0][:value]).var ; loc result, val[0] }

#---LITERALS (dynamic and static)
#

array
  : LBRACK expressions       RBRACK { result = Factory.LIST(val[1]); loc result, val[0], val[2] }
  | LBRACK expressions COMMA RBRACK { result = Factory.LIST(val[1]); loc result, val[0], val[3] }
  | LBRACK                   RBRACK { result = Factory.literal([]) ; loc result, val[0] }
  | LISTSTART expressions       RBRACK { result = Factory.LIST(val[1]); loc result, val[0], val[2] }
  | LISTSTART expressions COMMA RBRACK { result = Factory.LIST(val[1]); loc result, val[0], val[3] }
  | LISTSTART                   RBRACK { result = Factory.literal([]) ; loc result, val[0] }

hash
  : LBRACE hashpairs RBRACE       { result = Factory.HASH(val[1]); loc result, val[0], val[2] }
  | LBRACE hashpairs COMMA RBRACE { result = Factory.HASH(val[1]); loc result, val[0], val[3] }
  | LBRACE RBRACE                 { result = Factory.literal({}) ; loc result, val[0], val[3] }

  hashpairs
    : hashpair                 { result = [val[0]] }
    | hashpairs COMMA hashpair { result = val[0].push val[2] }

  hashpair
    : expression FARROW expression { result = Factory.KEY_ENTRY(val[0], val[2]); loc result, val[1] }

quotedtext
  : string
  | dq_string
  | heredoc

string
  : STRING  { result = Factory.literal(val[0][:value]) ; loc result, val[0] }
  | WORD    { result = Factory.literal(val[0][:value]) ; loc result, val[0] }

dq_string       : dqpre dqrval           { result = Factory.string(val[0], *val[1]) ; loc result, val[0], val[1][-1] }
dqpre           : DQPRE                  { result = Factory.literal(val[0][:value]); loc result, val[0] }
dqpost          : DQPOST                 { result = Factory.literal(val[0][:value]); loc result, val[0] }
dqmid           : DQMID                  { result = Factory.literal(val[0][:value]); loc result, val[0] }
dqrval          : text_expression dqtail { result = [val[0]] + val[1] }
text_expression : expression             { result = Factory.TEXT(val[0]) }

dqtail
  : dqpost        { result = [val[0]] }
  | dqmid dqrval  { result = [val[0]] + val[1] }

heredoc
  : HEREDOC sublocated_text  { result = Factory.HEREDOC(val[0][:value], val[1]); loc result, val[0] }

sublocated_text
  : SUBLOCATE string    { result = Factory.SUBLOCATE(val[0], val[1]); loc result, val[0] }
  | SUBLOCATE dq_string { result = Factory.SUBLOCATE(val[0], val[1]); loc result, val[0] }

epp_expression
  : EPP_START epp_parameters_list statements { result = Factory.EPP(val[1], val[2]); loc result, val[0] }

epp_parameters_list
  :                                  =LOW{ result = nil }
  | PIPE PIPE                        { result = [] }
  | PIPE parameters endcomma PIPE    { result = val[1] }

epp_render_expression
  : RENDER_STRING                  { result = Factory.RENDER_STRING(val[0][:value]); loc result, val[0] }
  | RENDER_EXPR expression epp_end { result = Factory.RENDER_EXPR(val[1]); loc result, val[0], val[2] }
  | RENDER_EXPR LBRACE statements RBRACE epp_end { result = Factory.RENDER_EXPR(Factory.block_or_expression(*val[2])); loc result, val[0], val[4] }

epp_end
  : EPP_END
  | EPP_END_TRIM

number   : NUMBER   { result = Factory.NUMBER(val[0][:value]) ; loc result, val[0] }
name     : NAME     { result = Factory.QNAME_OR_NUMBER(val[0][:value]) ; loc result, val[0] }
type     : CLASSREF { result = Factory.QREF(val[0][:value])  ; loc result, val[0] }
undef    : UNDEF    { result = Factory.literal(:undef); loc result, val[0] }
default  : DEFAULT  { result = Factory.literal(:default); loc result, val[0] }

          # Assumes lexer produces a Boolean value for booleans, or this will go wrong and produce a literal string
          # with the text 'true'.
          #TODO: could be changed to a specific boolean literal factory method to prevent this possible glitch.
boolean  : BOOLEAN { result = Factory.literal(val[0][:value]) ; loc result, val[0] }

regex
  : REGEX { result = Factory.literal(val[0][:value]); loc result, val[0] }

#---MARKERS, SPECIAL TOKENS, SYNTACTIC SUGAR, etc.

endcomma
  : #
  | COMMA { result = nil }

endsemi
  : #
  | SEMIC

keyword
  : AND
  | CASE
  | CLASS
  | DEFAULT
  | DEFINE
  | ELSE
  | ELSIF
  | IF
  | IN
  | INHERITS
  | NODE
  | OR
  | UNDEF
  | UNLESS

nil
  : { result = nil}

end

---- header ----
require 'puppet'
require 'puppet/pops'

module Puppet
  class ParseError < Puppet::Error; end
  class ImportError < Racc::ParseError; end
  class AlreadyImportedError < ImportError; end
end

---- inner ----

# Make emacs happy
# Local Variables:
# mode: ruby
# End:

Youez - 2016 - github.com/yon3zu
LinuXploit