Class: Fast::ExpressionParser
- Inherits:
-
Object
- Object
- Fast::ExpressionParser
- Defined in:
- lib/fast.rb
Overview
ExpressionParser empowers the AST search in Ruby. All classes inheriting Fast::Find have a grammar shortcut that is processed here.
Instance Method Summary collapse
-
#initialize(expression) ⇒ ExpressionParser
constructor
A new instance of ExpressionParser.
-
#parse ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(expression) ⇒ ExpressionParser
Returns a new instance of ExpressionParser.
363 364 365 |
# File 'lib/fast.rb', line 363 def initialize(expression) @tokens = expression.scan TOKENIZER end |
Instance Method Details
#parse ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/fast.rb', line 370 def parse case (token = next_token) when '(' then parse_until_peek(')') when '{' then Any.new(parse_until_peek('}')) when '[' then All.new(parse_until_peek(']')) when /^"/ then FindString.new(token[1..-2]) when /^#\w/ then MethodCall.new(token[1..]) when /^\.\w[\w\d_]+\?/ then InstanceMethodCall.new(token[1..]) when '$' then Capture.new(parse) when '!' then (@tokens.any? ? Not.new(parse) : Find.new(token)) when '?' then Maybe.new(parse) when '^' then Parent.new(parse) when '\\' then FindWithCapture.new(parse) when /^%\d/ then FindFromArgument.new(token[1..]) else Find.new(token) end end |