Class: SDL4R::Tokenizer::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/sdl4r/tokenizer.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_type, regex, options = {}, &block) ⇒ Matcher

:nodoc: all



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sdl4r/tokenizer.rb', line 43

def initialize(token_type, regex, options = {}, &block)
  options = {
    :next_mode => nil,
    :push_back_eol => false,
    :error => nil,
  }.merge(options)

  @token_type = token_type
  @regex = regex
  @next_mode = options[:next_mode]
  @push_back_eol = options[:push_back_eol]
  @error = options[:error]

  if block_given?
    instance_eval(&block)
  end
end

Instance Attribute Details

#errorObject (readonly)

If nil, this Matcher is normal, otherwise it is meant to detect errors and this returns a message.



68
69
70
# File 'lib/sdl4r/tokenizer.rb', line 68

def error
  @error
end

#next_modeObject (readonly)

Returns the value of attribute next_mode.



60
61
62
# File 'lib/sdl4r/tokenizer.rb', line 60

def next_mode
  @next_mode
end

#push_back_eolObject (readonly)

Indicates whether the matched token tends to match the end of line character and whether it should be pushed back in this cases.



64
65
66
# File 'lib/sdl4r/tokenizer.rb', line 64

def push_back_eol
  @push_back_eol
end

#regexObject (readonly)

Returns the value of attribute regex.



60
61
62
# File 'lib/sdl4r/tokenizer.rb', line 60

def regex
  @regex
end

#token_typeObject (readonly)

Returns the value of attribute token_type.



60
61
62
# File 'lib/sdl4r/tokenizer.rb', line 60

def token_type
  @token_type
end

Instance Method Details

#process_token(token) ⇒ Object

Called when a token is found in order to remove meaningless characters, etc.



71
72
73
# File 'lib/sdl4r/tokenizer.rb', line 71

def process_token(token)
  token
end