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.
15 16 17 18 19 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 15 def initialize(source, filename) # rubocop:disable Lint/MissingSuper @source = source @file = filename @visitor = ::Puppet::Pops::Visitor.new(self, 'transform') end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 9 def file @file end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 9 def source @source end |
Instance Method Details
#enumerator ⇒ Object
Gets an enumerator for the statements that were parsed.
37 38 39 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 37 def enumerator @statements end |
#parse ⇒ void
This method returns an undefined value.
Parses the source.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet-strings/yard/parsers/puppet/parser.rb', line 23 def parse begin Puppet[:tasks] = true if Puppet.settings.include?(:tasks) @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact rescue ::Puppet::ParseError => e log.error "Failed to parse #{@file}: #{e.}" @statements = [] end @statements.freeze self end |