Sha256: cbc836346b7fcb8e85022afd824265c85383df8815f69a4106845fda5c1957d6

Contents?: true

Size: 1.17 KB

Versions: 77

Compression:

Stored size: 1.17 KB

Contents

require 'strscan'

module ActionDispatch
  module Journey # :nodoc:
    class Scanner # :nodoc:
      def initialize
        @ss = nil
      end

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

      def eos?
        @ss.eos?
      end

      def pos
        @ss.pos
      end

      def pre_match
        @ss.pre_match
      end

      def next_token
        return if @ss.eos?

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

      private

        def scan
          case
            # /
          when text = @ss.scan(/\//)
            [:SLASH, text]
          when text = @ss.scan(/\*\w+/)
            [: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
    end
  end
end

Version data entries

77 entries across 77 versions & 4 rubygems

Version Path
actionpack-4.1.16 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.16.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.15 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.15.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.14.2 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.14.1 lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/scanner.rb
actionpack-4.1.14 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.14.rc2 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.14.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.13 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.13.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.12 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.12.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.11 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.10 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.10.rc4 lib/action_dispatch/journey/scanner.rb
actionpack-4.1.10.rc3 lib/action_dispatch/journey/scanner.rb