Class | YARD::Parser::SourceParser |
In: |
lib/yard/parser/source_parser.rb
|
Parent: | Object |
Responsible for parsing a source file into the namespace. Parsing also invokes handlers to process the parsed statements and generate any code objects that may be recognized.
SourceParser allows custom parsers to be registered and called when a certain filetype is recognized. To register a parser and hook it up to a set of file extensions, call {register_parser_type}
@see register_parser_type @see Handlers::Base @see CodeObjects::Base
SHEBANG_LINE | = | /\A\s*#!\S+/ |
ENCODING_LINE | = | /\A(?:\s*#*!.*\r?\n)?\s*#+.*coding\s*[:=]{1,2}\s*(\S+)/i |
file | [R] | The filename being parsed by the parser. |
parser_type | [R] | @return [Symbol] the default parser type (defaults to :ruby) |
parser_type | [R] | The parser type associated with the parser instance. This should be set by the {initialize constructor}. |
parser_type_extensions | [R] | @return [Hash] a list of registered parser type extensions @private @since 0.5.6 |
parser_types | [R] | @return [Hash{Symbol=>Object}] a list of registered parser types @private @since 0.5.6 |
Creates a new parser object for code parsing with a specific parser type.
@param [Symbol] parser_type the parser type to use @param [Boolean] load_order_errors whether or not to raise the {LoadOrderError}
Parses a path or set of paths
@param [String, Array<String>] paths a path, glob, or list of paths to
parse
@param [Array<String, Regexp>] excluded a list of excluded path matchers @param [Fixnum] level the logger level to use during parsing. See
{YARD::Logger}
@return the parser object that was used to parse the source.
Finds a parser type that is registered for the extension. If no type is found, the default Ruby type is returned.
@return [Symbol] the parser type to be used for the extension @since 0.5.6
Registers a new parser type.
@example Registering a parser for "java" files
SourceParser.register_parser_type :java, JavaParser, 'java'
@param [Symbol] type a symbolic name for the parser type @param [Base] parser_klass a class that implements parsing and tokenization @param [Array<String>, String, Regexp] extensions a list of extensions or a
regex to match against the file extension
@return [void] @see Parser::Base
Returns the validated parser type. Basically, enforces that :ruby type is never set if the Ripper library is not available
@param [Symbol] type the parser type to set @return [Symbol] the validated parser type @private
The main parser method. This should not be called directly. Instead, use the class methods {parse} and {parse_string}.
@param [String, read, Object] content the source file to parse @return [Object, nil] the parser object used to parse the source