Class: Parser::Base

Inherits:
Racc::Parser
  • Object
show all
Defined in:
sorbet/rbi/parser@3.3.7.4.rbi

Overview

Base class for version-specific parsers.

source://parser//lib/parser/base.rb#16

Direct Known Subclasses

Ruby33

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder = T.unsafe(nil)) ⇒ Base

source://parser//lib/parser/base.rb#126

Parameters:



676
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 676

def initialize(builder = T.unsafe(nil)); end

Class Method Details

.default_parserParser::Base

source://parser//lib/parser/base.rb#84

Returns:



807
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 807

def default_parser; end

.parse(string, file = T.unsafe(nil), line = T.unsafe(nil)) ⇒ Parser::AST::Node

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.

source://parser//lib/parser/base.rb#30

Examples:

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

Parameters:

  • string (String)

    The block of code to parse.

  • file (String) (defaults to: T.unsafe(nil))

    The name of the file the code originated from.

  • line (Numeric) (defaults to: T.unsafe(nil))

    The initial line number.

Returns:



822
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 822

def parse(string, file = T.unsafe(nil), line = T.unsafe(nil)); end

.parse_file(filename) ⇒ 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.

source://parser//lib/parser/base.rb#64

Parameters:

  • filename (String)

    Path to the file to parse.

Returns:

See Also:



834
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 834

def parse_file(filename); end

.parse_file_with_comments(filename) ⇒ Array

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.

source://parser//lib/parser/base.rb#77

Parameters:

  • filename (String)

    Path to the file to parse.

Returns:

See Also:



846
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 846

def parse_file_with_comments(filename); end

.parse_with_comments(string, file = T.unsafe(nil), line = T.unsafe(nil)) ⇒ Array

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.

source://parser//lib/parser/base.rb#49

Examples:

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

Parameters:

  • string (String)

    The block of code to parse.

  • file (String) (defaults to: T.unsafe(nil))

    The name of the file the code originated from.

  • line (Numeric) (defaults to: T.unsafe(nil))

    The initial line number.

Returns:



861
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 861

def parse_with_comments(string, file = T.unsafe(nil), line = T.unsafe(nil)); end

Instance Method Details

#builderObject

source://parser//lib/parser/base.rb#114



681
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 681

def builder; end

#contextObject

source://parser//lib/parser/base.rb#117



686
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 686

def context; end

#current_arg_stackObject

source://parser//lib/parser/base.rb#119



691
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 691

def current_arg_stack; end

#diagnosticsParser::Diagnostic::Engine

source://parser//lib/parser/base.rb#113



697
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 697

def diagnostics; end

#lexerObject

source://parser//lib/parser/base.rb#112



702
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 702

def lexer; end

#max_numparam_stackObject

source://parser//lib/parser/base.rb#118



707
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 707

def max_numparam_stack; end

#parse(source_buffer) ⇒ Parser::AST::Node?

Parses a source buffer and returns the AST, or nil in case of a non fatal error.

source://parser//lib/parser/base.rb#186

Parameters:

Returns:



716
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 716

def parse(source_buffer); end

#parse_with_comments(source_buffer) ⇒ Array

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

source://parser//lib/parser/base.rb#204

Returns:

See Also:

  • #parse
  • Source::Comment#associate


726
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 726

def parse_with_comments(source_buffer); end

#pattern_hash_keysObject

source://parser//lib/parser/base.rb#121



731
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 731

def pattern_hash_keys; end

#pattern_variablesObject

source://parser//lib/parser/base.rb#120



736
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 736

def pattern_variables; end

#resetObject

Resets the state of the parser.

source://parser//lib/parser/base.rb#167



743
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 743

def reset; end

#source_bufferObject

source://parser//lib/parser/base.rb#116



748
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 748

def source_buffer; end

#static_envParser::StaticEnvironment

source://parser//lib/parser/base.rb#115



754
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 754

def static_env; end

#tokenize(source_buffer, recover = T.unsafe(nil)) ⇒ Array

Parses a source buffer and returns the AST, the source code comments, and the tokens emitted by the lexer. In case of a fatal error, a SyntaxError is raised, unless recover is true. In case of an error (non-fatal or recovered), 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.

source://parser//lib/parser/base.rb#233

Parameters:

  • source_buffer (Parser::Source::Buffer)
  • recover (Boolean) (defaults to: T.unsafe(nil))

    If true, recover from syntax errors. False by default.

Returns:



778
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 778

def tokenize(source_buffer, recover = T.unsafe(nil)); end