Class: Puppet::Parser::ParserFactory
- Defined in:
- lib/puppet/parser/parser_factory.rb
Overview
The ParserFactory makes selection of parser possible. Currently, it is possible to switch between two different parsers:
-
classic_parser, the parser in 3.1
-
eparser, the Expression Based Parser
Class Method Summary collapse
-
.assert_rgen_installed ⇒ Object
Asserts that RGen >= 0.6.6 is installed by checking that certain behavior is available.
-
.classic_parser(environment) ⇒ Object
Creates an instance of the classic parser.
- .code_merger ⇒ Object
-
.evaluating_parser(file_watcher) ⇒ Object
Creates an instance of an E4ParserAdapter that adapts an EvaluatingParser to the 3x way of parsing.
-
.parser(environment) ⇒ Object
Produces a parser instance for the given environment.
Class Method Details
.assert_rgen_installed ⇒ Object
Asserts that RGen >= 0.6.6 is installed by checking that certain behavior is available. Note that this assert is expensive as it also requires puppet/pops (if not already loaded).
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/parser/parser_factory.rb', line 43 def self.assert_rgen_installed @@asserted ||= false return if @@asserted @@asserted = true begin require 'rgen/metamodel_builder' rescue LoadError raise Puppet::DevError.new("The gem 'rgen' version >= 0.7.0 is required when using the setting '--parser future'. Please install 'rgen'.") end # Since RGen is optional, there is nothing specifying its version. # It is not installed in any controlled way, so not possible to use gems to check (it may be installed some other way). # Instead check that "eContainer, and eContainingFeature" has been installed. require 'puppet/pops' begin litstring = Puppet::Pops::Model::LiteralString.new(); container = Puppet::Pops::Model::ArithmeticExpression.new(); container.left_expr = litstring raise "no eContainer" if litstring.eContainer() != container raise "no eContainingFeature" if litstring.eContainingFeature() != :left_expr rescue => e # TODO: RGen can raise exceptions for other reasons! raise Puppet::DevError.new("The gem 'rgen' version >= 0.7.0 is required when using '--parser future'. An older version is installed, please update.") end end |
.classic_parser(environment) ⇒ Object
Creates an instance of the classic parser.
21 22 23 24 25 |
# File 'lib/puppet/parser/parser_factory.rb', line 21 def self.classic_parser(environment) # avoid expensive require if already loaded require 'puppet/parser' unless defined? Puppet::Parser::Parser Puppet::Parser::Parser.new(environment) end |
.code_merger ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/puppet/parser/parser_factory.rb', line 68 def self.code_merger if Puppet[:parser] == 'future' Puppet::Pops::Parser::CodeMerger.new else Puppet::Parser::CodeMerger.new end end |
.evaluating_parser(file_watcher) ⇒ Object
Creates an instance of an E4ParserAdapter that adapts an EvaluatingParser to the 3x way of parsing.
30 31 32 33 34 35 36 37 38 |
# File 'lib/puppet/parser/parser_factory.rb', line 30 def self.evaluating_parser(file_watcher) # Since RGen is optional, test that it is installed assert_rgen_installed() unless defined?(Puppet::Pops::Parser::E4ParserAdapter) require 'puppet/parser/e4_parser_adapter' require 'puppet/pops/parser/code_merger' end E4ParserAdapter.new(file_watcher) end |