Class: Puppet::Parser::E4ParserAdapter
- Defined in:
- lib/puppet/parser/e4_parser_adapter.rb
Overview
Adapts an egrammar/eparser to respond to the public API of the classic parser and makes use of the new evaluator.
Defined Under Namespace
Classes: NullFileWatcher
Instance Method Summary collapse
- #file=(file) ⇒ Object
-
#initialize(file_watcher = nil) ⇒ E4ParserAdapter
constructor
A new instance of E4ParserAdapter.
- #parse(string = nil) ⇒ Object
- #parse_ruby_file ⇒ Object
- #string=(string) ⇒ Object
Constructor Details
#initialize(file_watcher = nil) ⇒ E4ParserAdapter
Returns a new instance of E4ParserAdapter.
18 19 20 21 22 23 24 |
# File 'lib/puppet/parser/e4_parser_adapter.rb', line 18 def initialize(file_watcher = nil) @file_watcher = file_watcher || NullFileWatcher.new @file = '' @string = '' @use = :unspecified @@evaluating_parser ||= Puppet::Pops::Parser::EvaluatingParser.new() end |
Instance Method Details
#file=(file) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/puppet/parser/e4_parser_adapter.rb', line 26 def file=(file) @file = file @use = :file # watch if possible, but only if the file is something worth watching @file_watcher.watch_file(file) if !file.nil? && file != '' end |
#parse(string = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/parser/e4_parser_adapter.rb', line 33 def parse(string = nil) self.string= string if string if @file =~ /\.rb$/ && @use != :string # Will throw an error parse_ruby_file end parse_result = if @use == :string # Parse with a source_file to set in created AST objects (it was either given, or it may be unknown # if caller did not set a file and the present a string. # @@evaluating_parser.parse_string(@string, @file || "unknown-source-location") else @@evaluating_parser.parse_file(@file) end # the parse_result may be # * empty / nil (no input) # * a Model::Program # * a Model::Expression # model = parse_result.nil? ? nil : parse_result.current args = {} Puppet::Pops::Model::AstTransformer.new(@file).merge_location(args, model) ast_code = if model.is_a? Puppet::Pops::Model::Program Puppet::Parser::AST::PopsBridge::Program.new(model, args) else args[:value] = model Puppet::Parser::AST::PopsBridge::Expression.new(args) end # Create the "main" class for the content - this content will get merged with all other "main" content Puppet::Parser::AST::Hostclass.new('', :code => ast_code) end |
#parse_ruby_file ⇒ Object
78 79 80 |
# File 'lib/puppet/parser/e4_parser_adapter.rb', line 78 def parse_ruby_file raise Puppet::ParseError, "Ruby DSL is no longer supported. Attempt to parse #{@file}" end |
#string=(string) ⇒ Object
73 74 75 76 |
# File 'lib/puppet/parser/e4_parser_adapter.rb', line 73 def string=(string) @string = string @use = :string end |