Sha256: 4a40e63f0e357a65b36128f059125eb6bcce26ac4c9090c539c4de551be11df5

Contents?: true

Size: 1.44 KB

Versions: 115

Compression:

Stored size: 1.44 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
        # takes advantage of String @- deduping capabilities in Ruby 2.5 upwards
        # see: https://bugs.ruby-lang.org/issues/13077
        def dedup_scan(regex)
          r = @ss.scan(regex)
          r ? -r : nil
        end

        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
    end
  end
end

Version data entries

115 entries across 110 versions & 8 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.3.4/lib/action_dispatch/journey/scanner.rb
actionpack-7.1.5.1 lib/action_dispatch/journey/scanner.rb
actionpack-7.0.8.7 lib/action_dispatch/journey/scanner.rb
actionpack-7.1.5 lib/action_dispatch/journey/scanner.rb
actionpack-7.1.4.2 lib/action_dispatch/journey/scanner.rb
actionpack-7.0.8.6 lib/action_dispatch/journey/scanner.rb
actionpack-6.1.7.10 lib/action_dispatch/journey/scanner.rb
actionpack-6.1.7.9 lib/action_dispatch/journey/scanner.rb
actionpack-7.1.4.1 lib/action_dispatch/journey/scanner.rb
actionpack-7.0.8.5 lib/action_dispatch/journey/scanner.rb
actionpack-7.1.4 lib/action_dispatch/journey/scanner.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.3.4/lib/action_dispatch/journey/scanner.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.8.4/lib/action_dispatch/journey/scanner.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actionpack-7.0.5.1/lib/action_dispatch/journey/scanner.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actionpack-7.0.5.1/lib/action_dispatch/journey/scanner.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actionpack-7.0.5.1/lib/action_dispatch/journey/scanner.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actionpack-7.1.3.4/lib/action_dispatch/journey/scanner.rb
actionpack-7.1.3.4 lib/action_dispatch/journey/scanner.rb
actionpack-7.0.8.4 lib/action_dispatch/journey/scanner.rb
actionpack-6.1.7.8 lib/action_dispatch/journey/scanner.rb