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
10 def initialize
11   @file = ''
12   @string = ''
13   @use = :unspecified
14 end

Public Instance Methods

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