Class: Ibex::Frontend::ActionScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/frontend/action_scanner.rb

Overview

Extracts a balanced Ruby action while ignoring braces inside literals.

Constant Summary collapse

PAIRED_DELIMITERS =

@rbs! type heredoc = { identifier: String, indented: bool, length: Integer, location: Location }

{ "(" => ")", "[" => "]", "{" => "}", "<" => ">" }.freeze
REGEX_PREFIXES =

: Hash[String, String]

"=([{!,:;?&|+-*%^~<>"

Instance Method Summary collapse

Constructor Details

#initialize(cursor) ⇒ ActionScanner

Returns a new instance of ActionScanner.



22
23
24
25
# File 'lib/ibex/frontend/action_scanner.rb', line 22

def initialize(cursor)
  @cursor = cursor
  @pending_heredocs = [] #: Array[heredoc]
end

Instance Method Details

#scanObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ibex/frontend/action_scanner.rb', line 28

def scan
  location = @cursor.location
  @cursor.advance
  start = @cursor.index
  scan_code(1)
  finish = @cursor.index
  @cursor.advance
  Token.new(type: :action, value: @cursor.source[start...finish], location: location)
rescue Ibex::Error
  raise
rescue StandardError => e
  raise Ibex::Error, "#{location}: unable to scan action: #{e.message}"
end