Class: RuboCop::AST::NodePattern::Parser
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::RuboCop::SimpleForwardable ,
Racc::Parser
|
|
Instance Chain:
self,
Racc::Parser
|
|
Inherits: |
Racc::Parser
|
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
Constant Summary
Class Method Summary
- .new(builder = self.class::Builder.new) ⇒ Parser constructor
::RuboCop::SimpleForwardable
- Extended
Instance Method Summary
- #inspect
-
#parse(source) ⇒ NodePattern::Node
(Similar API to
parser
gem) Parses a source and returns the AST. - #enforce_unary(node) private
-
#on_error(token, val, _vstack)
private
Overrides Racc::Parser’s method:
Constructor Details
.new(builder = self.class::Builder.new) ⇒ Parser
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 19
def initialize(builder = self.class::Builder.new) super() @builder = builder end
Instance Method Details
#enforce_unary(node) (private)
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 50
def enforce_unary(node) return node if node.arity == 1 detail = node.loc&.expression&.source || node.to_s raise NodePattern::Invalid, 'parse error, expected unary node pattern ' \ "but got expression matching multiple elements: #{detail}" end
#inspect
[ GitHub ]# File 'lib/rubocop/ast/node_pattern/parser.rb', line 40
def inspect "<##{self.class}>" end
#on_error(token, val, _vstack) (private)
Overrides Racc::Parser’s method:
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 59
def on_error(token, val, _vstack) detail = token_to_str(token) || '?' raise NodePattern::Invalid, "parse error on value #{val.inspect} (#{detail})" end
#parse(source) ⇒ NodePattern::Node
(Similar API to parser
gem)
Parses a source and returns the AST.
# 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. ensure @lexer = nil # Don't keep references end