class Lexr::Rule

Attributes

pattern[R]
raises[R]
symbol[R]

Public Class Methods

new(pattern, symbol, opts = {}) click to toggle source
# File libs/lexer.rb, line 206
            def initialize(pattern, symbol, opts = {})
                    @pattern, @symbol, @opts = pattern, symbol, opts
  @raises=opts[:raises]
  @counter={}
end

Public Instance Methods

==(other) click to toggle source
# File libs/lexer.rb, line 225
            def ==(other)
                    @pattern == other.pattern &&
                            @symbol == other.symbol &&
                            @opts[:convert_with] == other.converter &&
                            @opts[:ignore] == other.ignore?
end
converter() click to toggle source
# File libs/lexer.rb, line 202
def converter ; @opts[:convert_with] ; end
counter(symbol) click to toggle source
# File libs/lexer.rb, line 232
def counter(symbol)
  @counter[symbol]
end
ignore?() click to toggle source
# File libs/lexer.rb, line 203
def ignore? ; @opts[:ignore] ; end
match(text) click to toggle source
# File libs/lexer.rb, line 216
      def match(text)
        text_matched = self.send :"#{pattern.class.name.downcase}_matcher", text
        return nil unless text_matched
  increment(@opts[:increment])
  decrement(@opts[:decrement])
        value = converter ? converter[text_matched] : text_matched
        Lexr::MatchData.new(text_matched.length, Lexr::Token.new(value, symbol))
end
raises?() click to toggle source
# File libs/lexer.rb, line 204
def raises? ; @opts[:raises] ; end
scan(text) click to toggle source
# File libs/lexer.rb, line 236
def scan(text)
  pat = pattern
  if pattern.is_a?(String)
    pat=/#{Regexp.escape(pattern)}/
  end
  res=text.scan(/#{pat}/)
end
set_counter(counter) click to toggle source
# File libs/lexer.rb, line 212
def set_counter(counter)
  @counter=counter
end

Private Instance Methods

decrement(symbol) click to toggle source
# File libs/lexer.rb, line 253
def decrement(symbol)
  if !symbol.nil?
    @counter[symbol]=0 if @counter[symbol].nil?
    @counter[symbol]-=1
  end
end
increment(symbol) click to toggle source
# File libs/lexer.rb, line 246
def increment(symbol)
  if !symbol.nil?
    @counter[symbol]=0 if @counter[symbol].nil?
    @counter[symbol]+=1
  end
end
regexp_matcher(text) click to toggle source
# File libs/lexer.rb, line 265
      def regexp_matcher(text)
        return nil unless m = text.match(/\A#{pattern}/)
              m[0]
end
string_matcher(text) click to toggle source
# File libs/lexer.rb, line 260
          def string_matcher(text)
            return nil unless text[0..pattern.length-1] == pattern
pattern
    end