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.
295 296 297 |
# File 'lib/fast.rb', line 295 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
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/fast.rb', line 302 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..-1]) when /^\.\w[\w\d_]+\?/ then InstanceMethodCall.new(token[1..-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..-1]) else Find.new(token) end end |