Class: PuppetStrings::Yard::Parsers::Puppet::Parser
- Inherits:
-
YARD::Parser::Base
- Object
- YARD::Parser::Base
- PuppetStrings::Yard::Parsers::Puppet::Parser
- Defined in:
- lib/puppet-strings/yard/parsers/puppet/parser.rb
Overview
Implements the Puppet language parser.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#enumerator ⇒ Object
Gets an enumerator for the statements that were parsed.
-
#initialize(source, filename) ⇒ void
constructor
Initializes the parser.
-
#parse ⇒ void
Parses the source.
Constructor Details
#initialize(source, filename) ⇒ void
Initializes the parser.
13 14 15 16 17 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 13 def initialize(source, filename) @source = source @file = filename @visitor = ::Puppet::Pops::Visitor.new(self, 'transform') end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 7 def file @file end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 7 def source @source end |
Instance Method Details
#enumerator ⇒ Object
Gets an enumerator for the statements that were parsed.
39 40 41 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 39 def enumerator @statements end |
#parse ⇒ void
This method returns an undefined value.
Parses the source.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 21 def parse begin Puppet[:tasks] = true if Puppet.settings.include?(:tasks) if Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") < 0 && @file.to_s.match(/^plans\//) log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater." return end @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact rescue ::Puppet::ParseError => ex log.error "Failed to parse #{@file}: #{ex.}" @statements = [] end @statements.freeze self end |