class Journey::Scanner
Public Class Methods
new()
click to toggle source
# File lib/journey/scanner.rb, line 5 def initialize @ss = nil end
Public Instance Methods
eos?()
click to toggle source
# File lib/journey/scanner.rb, line 13 def eos? @ss.eos? end
next_token()
click to toggle source
# File lib/journey/scanner.rb, line 25 def next_token return if @ss.eos? until token = scan || @ss.eos?; end token end
pos()
click to toggle source
# File lib/journey/scanner.rb, line 17 def pos @ss.pos end
pre_match()
click to toggle source
# File lib/journey/scanner.rb, line 21 def pre_match @ss.pre_match end
scan_setup(str)
click to toggle source
# File lib/journey/scanner.rb, line 9 def scan_setup str @ss = StringScanner.new str end
Private Instance Methods
scan()
click to toggle source
# File lib/journey/scanner.rb, line 33 def scan case # / when text = @ss.scan(/\//) [:SLASH, text] when text = @ss.scan(/\*/) [:STAR, text] when text = @ss.scan(/\(/) [:LPAREN, text] when text = @ss.scan(/\)/) [:RPAREN, text] when text = @ss.scan(/\|/) [:OR, text] when text = @ss.scan(/\./) [:DOT, text] when text = @ss.scan(/:\w+/) [:SYMBOL, text] when text = @ss.scan(/[\w%\-~]+/) [:LITERAL, text] # any char when text = @ss.scan(/./) [:LITERAL, text] end end