Sha256: 9314d5edc4ab42adec82b366642ae8e88fdc378887e06f51d979a19ba49b82f6

Contents?: true

Size: 1.23 KB

Versions: 84

Compression:

Stored size: 1.23 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.tr('\\', '')]
            # any char
          when text = @ss.scan(/./)
            [:LITERAL, text]
          end
        end
    end
  end
end

Version data entries

84 entries across 82 versions & 10 rubygems

Version Path
actionpack-4.2.7.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.rc2 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.racecar1 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.rc1 lib/action_dispatch/journey/scanner.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.beta4 lib/action_dispatch/journey/scanner.rb
actionpack-4.2.6 lib/action_dispatch/journey/scanner.rb
actionpack-4.2.6.rc1 lib/action_dispatch/journey/scanner.rb
actionpack-4.2.5.2 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.beta3 lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.beta2 lib/action_dispatch/journey/scanner.rb
activejob-lock-0.0.2 rails/actionpack/lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.beta1.1 lib/action_dispatch/journey/scanner.rb
actionpack-4.2.5.1 lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/scanner.rb
actionpack-5.0.0.beta1 lib/action_dispatch/journey/scanner.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/scanner.rb
actionpack-4.2.5 lib/action_dispatch/journey/scanner.rb