Sha256: 341dcd87834b46858134ba8f79c87101d82428ec3ac661ddabc0c1d3469b619a

Contents?: true

Size: 1.21 KB

Versions: 90

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

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

Version data entries

90 entries across 90 versions & 5 rubygems

Version Path
actionpack-5.2.8.1 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.8 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.7.1 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.7 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.6.3 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.6.2 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.6.1 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.6 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.6 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.5 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.5 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.4 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.3 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.2 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.1 lib/action_dispatch/journey/scanner.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4 lib/action_dispatch/journey/scanner.rb
actionpack-5.2.4.rc1 lib/action_dispatch/journey/scanner.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/scanner.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/scanner.rb