Class Parser::Base
In: lib/parser/base.rb
Parent: Racc::Parser

Base class for version-specific parsers.

@api public

@!attribute [r] diagnostics

 @return [Parser::Diagnostic::Engine]

@!attribute [r] static_env

 @return [Parser::StaticEnvironment]

Methods

Attributes

builder  [R] 
diagnostics  [R] 
source_buffer  [R] 
static_env  [R] 

Public Class methods

@return [Parser::Base] parser with the default options set.

Parses a string of Ruby code and returns the AST. If the source cannot be parsed, {SyntaxError} is raised and a diagnostic is printed to `stderr`.

@example

 Parser::Base.parse('puts "hello"')

@param [String] string The block of code to parse. @param [String] file The name of the file the code originated from. @param [Numeric] line The initial line number. @return [Parser::AST::Node]

Parses Ruby source code by reading it from a file. If the source cannot be parsed, {SyntaxError} is raised and a diagnostic is printed to `stderr`.

@param [String] filename Path to the file to parse. @return [Parser::AST::Node] @see parse

Parses Ruby source code by reading it from a file and returns the AST and comments. If the source cannot be parsed, {SyntaxError} is raised and a diagnostic is printed to `stderr`.

@param [String] filename Path to the file to parse. @return [Array] @see parse

Parses a string of Ruby code and returns the AST and comments. If the source cannot be parsed, {SyntaxError} is raised and a diagnostic is printed to `stderr`.

@example

 Parser::Base.parse_with_comments('puts "hello"')

@param [String] string The block of code to parse. @param [String] file The name of the file the code originated from. @param [Numeric] line The initial line number. @return [Array]

Public Instance methods

@api private @return [Boolean]

Parses a source buffer and returns the AST.

@param [Parser::Source::Buffer] source_buffer The source buffer to parse. @return [Parser::AST::Node]

Parses a source buffer and returns the AST and the source code comments.

@see parse @see Parser::Source::Comment#associate @return [Array]

Resets the state of the parser.

Parses a source buffer and returns the AST, the source code comments, and the tokens emitted by the lexer. If `recover` is true and a fatal {SyntaxError} is encountered, `nil` is returned instead of the AST, and comments as well as tokens are only returned up to the location of the error.

Currently, token stream format returned by tokenize is not documented, but is considered part of a public API and only changed according to Semantic Versioning.

However, note that the exact token composition of various constructs might vary. For example, a string `"foo"` is represented equally well by `:tSTRING_BEG " :tSTRING_CONTENT foo :tSTRING_END "` and `:tSTRING "foo"`; such details must not be relied upon.

@param [Parser::Source::Buffer] source_buffer @param [Boolean] recover If true, recover from syntax errors. False by default. @return [Array]

[Validate]