class PuppetStrings::Yard::Parsers::Puppet::Parser
Implements the Puppet language parser.
Attributes
file[R]
source[R]
Public Class Methods
new(source, filename)
click to toggle source
Initializes the parser. @param [String] source The source being parsed. @param [String] filename The file name of the file being parsed. @return [void]
# 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
Public Instance Methods
enumerator()
click to toggle source
Gets an enumerator for the statements that were parsed. @return Returns an enumerator for the statements that were parsed.
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 34 def enumerator @statements end
parse()
click to toggle source
Parses the source. @return [void]
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 21 def parse begin @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact rescue ::Puppet::ParseError => ex log.error "Failed to parse #{@file}: #{ex.message}" @statements = [] end @statements.freeze self end
Private Instance Methods
transform_Factory(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 45 def transform_Factory(o) @visitor.visit(o.current) end
transform_FunctionDefinition(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 61 def transform_FunctionDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file) statement.extract_docstring(@lines) statement end
transform_HostClassDefinition(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 49 def transform_HostClassDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file) statement.extract_docstring(@lines) statement end
transform_Object(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 67 def transform_Object(o) # Ignore anything else (will be compacted out of the resulting array) end
transform_Program(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 39 def transform_Program(o) # Cache the lines of the source text; we'll use this to locate comments @lines = o.source_text.lines.to_a o.definitions.map { |d| @visitor.visit(d) } end
transform_ResourceTypeDefinition(o)
click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 55 def transform_ResourceTypeDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file) statement.extract_docstring(@lines) statement end