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.
388 389 390 |
# File 'lib/fast.rb', line 388 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
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/fast.rb', line 395 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 |