Sha256: 6dab7a8ada691ae120445a56d56c38d49963d39605d69ade849cefcff22a85ea

Contents?: true

Size: 445 Bytes

Versions: 9

Compression:

Stored size: 445 Bytes

Contents

require 'dentaku/token'

module Dentaku
  class TokenScanner
    def initialize(category, regexp, converter=nil)
      @category  = category
      @regexp    = %r{\A(#{ regexp })}i
      @converter = converter
    end

    def scan(string)
      if m = @regexp.match(string)
        value = raw = m.to_s
        value = @converter.call(raw) if @converter

        return Token.new(@category, value, raw)
      end

      false
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dentaku-0.2.10 lib/dentaku/token_scanner.rb
dentaku-0.2.9 lib/dentaku/token_scanner.rb
dentaku-0.2.8 lib/dentaku/token_scanner.rb
dentaku-0.2.7 lib/dentaku/token_scanner.rb
dentaku-0.2.6 lib/dentaku/token_scanner.rb
dentaku-0.2.5 lib/dentaku/token_scanner.rb
dentaku-0.2.4 lib/dentaku/token_scanner.rb
dentaku-0.2.3 lib/dentaku/token_scanner.rb
dentaku-0.2.2 lib/dentaku/token_scanner.rb