Class: RuboCop::AST::NodePattern::Parser

Inherits:
Racc::Parser
  • Object
show all
Extended by:
SimpleForwardable
Defined in:
lib/rubocop/ast/node_pattern/parser.rb,
lib/rubocop/ast/node_pattern/with_meta.rb

Overview

Parser for NodePattern Note: class reopened in ‘parser.racc`

Doc on how this fits in the compiling process:

/docs/modules/ROOT/pages/node_pattern.adoc

Direct Known Subclasses

WithMeta

Defined Under Namespace

Classes: WithMeta

Constant Summary collapse

Builder =
NodePattern::Builder
Lexer =
NodePattern::Lexer

Instance Method Summary collapse

Methods included from SimpleForwardable

def_delegators

Constructor Details

#initialize(builder = self.class::Builder.new) ⇒ Parser

Returns a new instance of Parser.



19
20
21
22
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 19

def initialize(builder = self.class::Builder.new)
  super()
  @builder = builder
end

Instance Method Details

#inspectObject



40
41
42
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 40

def inspect
  "<##{self.class}>"
end

#parse(source) ⇒ NodePattern::Node

(Similar API to ‘parser` gem) Parses a source and returns the AST.

Parameters:

  • source_buffer (Parser::Source::Buffer, String)

    The source buffer to parse.

Returns:



31
32
33
34
35
36
37
38
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 31

def parse(source)
  @lexer = self.class::Lexer.new(source)
  do_parse
rescue Lexer::Error => e
  raise NodePattern::Invalid, e.message
ensure
  @lexer = nil # Don't keep references
end