123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Journey::Scanner

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/journey/scanner.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newScanner

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 8

def initialize
  @ss = nil
end

Instance Attribute Details

#eos?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 16

def eos?
  @ss.eos?
end

Instance Method Details

#dedup_scan(regex) (private)

takes advantage of ::String @- deduping capabilities in Ruby 2.5 upwards see: bugs.ruby-lang.org/issues/13077

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 38

def dedup_scan(regex)
  r = @ss.scan(regex)
  r ? -r : nil
end

#next_token

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 28

def next_token
  return if @ss.eos?

  until token = scan || @ss.eos?; end
  token
end

#pos

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 20

def pos
  @ss.pos
end

#pre_match

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 24

def pre_match
  @ss.pre_match
end

#scan (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 43

def scan
  case
    # /
  when @ss.skip(/\//)
    [:SLASH, "/"]
  when @ss.skip(/\(/)
    [:LPAREN, "("]
  when @ss.skip(/\)/)
    [:RPAREN, ")"]
  when @ss.skip(/\|/)
    [:OR, "|"]
  when @ss.skip(/\./)
    [:DOT, "."]
  when text = dedup_scan(/:\w+/)
    [:SYMBOL, text]
  when text = dedup_scan(/\*\w+/)
    [:STAR, text]
  when text = @ss.scan(/(?:[\w%\-~!$&'*,;=@]|\\[:()])/)
    text.tr! "\\", ""
    [:LITERAL, -text]
    # any char
  when text = dedup_scan(/./)
    [:LITERAL, text]
  end
end

#scan_setup(str)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/scanner.rb', line 12

def scan_setup(str)
  @ss = StringScanner.new(str)
end