class PuppetStrings::Yard::Parsers::Puppet::Parser
Implements the Puppet
language parser.
Attributes
Public Class Methods
Source
# 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
Initializes the parser. @param [String] source The source being parsed. @param [String] filename The file name of the file being parsed. @return [void]
Public Instance Methods
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 37 def enumerator @statements end
Gets an enumerator for the statements that were parsed. @return Returns an enumerator for the statements that were parsed.
Source
# 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.message}" @statements = [] end @statements.freeze self end
Parses the source. @return [void]
Private Instance Methods
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 51 def transform_Factory(o) @visitor.visit(o.current) end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 67 def transform_FunctionDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file) statement.extract_docstring(@lines) statement end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 55 def transform_HostClassDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file) statement.extract_docstring(@lines) statement end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 85 def transform_Object(o) # Ignore anything else (will be compacted out of the resulting array) end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 73 def transform_PlanDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file) statement.extract_docstring(@lines) statement end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 45 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
TODO: Fix the rubocop violations in this file between the following rubocop:disable/enable lines rubocop:disable Naming/MethodName
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 61 def transform_ResourceTypeDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file) statement.extract_docstring(@lines) statement end
Source
# File lib/puppet-strings/yard/parsers/puppet/parser.rb, line 79 def transform_TypeAlias(o) statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file) statement.extract_docstring(@lines) statement end