Sha256: 558b09cfee96a7b515efa2f210f35b54ae0d2a6ae0f674c326bf9c593724775e

Contents?: true

Size: 993 Bytes

Versions: 18

Compression:

Stored size: 993 Bytes

Contents

require 'strscan'

module Journey
  class Scanner
    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(/\*/)
        [: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

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
challah-0.6.1 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.6.0 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.5.4 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.5.3 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.5.2 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.5.0 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
journey-1.0.2 lib/journey/scanner.rb
challah-0.4.1 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.4.0 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.5 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.4 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.3 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.2 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.1 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.3.0 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.2.1 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
challah-0.2.0 vendor/bundle/gems/journey-1.0.1/lib/journey/scanner.rb
journey-1.0.1 lib/journey/scanner.rb