class Puppet::Parser::E4ParserAdapter

Adapts an egrammar/eparser to respond to the public API of the classic parser and makes use of the new evaluator.

Public Class Methods

new() click to toggle source
   # File lib/puppet/parser/e4_parser_adapter.rb
11 def initialize
12   @file = ''
13   @string = ''
14   @use = :unspecified
15 end

Public Instance Methods

file=(file) click to toggle source
   # File lib/puppet/parser/e4_parser_adapter.rb
17 def file=(file)
18   @file = file
19   @use = :file
20 end
parse(string = nil) click to toggle source
   # File lib/puppet/parser/e4_parser_adapter.rb
22 def parse(string = nil)
23   self.string= string if string
24   parser = Pops::Parser::EvaluatingParser.singleton
25   model =
26   if @use == :string
27     # Parse with a source_file to set in created AST objects (it was either given, or it may be unknown
28     # if caller did not set a file and the present a string.
29     #
30     parser.parse_string(@string, @file || "unknown-source-location")
31   else
32     parser.parse_file(@file)
33   end
34 
35   # the parse_result may be
36   # * empty / nil (no input)
37   # * a Model::Program
38   # * a Model::Expression
39   #
40   args = {}
41   Pops::Model::AstTransformer.new(@file).merge_location(args, model)
42 
43   ast_code =
44   if model.is_a? Pops::Model::Program
45     AST::PopsBridge::Program.new(model, args)
46   else
47     args[:value] = model
48     AST::PopsBridge::Expression.new(args)
49   end
50 
51   # Create the "main" class for the content - this content will get merged with all other "main" content
52   AST::Hostclass.new('', :code => ast_code)
53 end
string=(string) click to toggle source
   # File lib/puppet/parser/e4_parser_adapter.rb
55 def string=(string)
56   @string = string
57   @use = :string
58 end