Class: Lexr::Rule
- Inherits:
-
Object
- Object
- Lexr::Rule
- Defined in:
- lib/lexr.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #converter ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(pattern, symbol, opts = {}) ⇒ Rule
constructor
A new instance of Rule.
- #match(text, previous_token = nil) ⇒ Object
Constructor Details
#initialize(pattern, symbol, opts = {}) ⇒ Rule
Returns a new instance of Rule.
74 75 76 |
# File 'lib/lexr.rb', line 74 def initialize(pattern, symbol, opts = {}) @pattern, @symbol, @opts = pattern, symbol, opts end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
69 70 71 |
# File 'lib/lexr.rb', line 69 def pattern @pattern end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
69 70 71 |
# File 'lib/lexr.rb', line 69 def symbol @symbol end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/lexr.rb', line 86 def ==(other) @pattern == other.pattern && @symbol == other.symbol && @opts[:convert_with] == other.converter && @opts[:ignore] == other.ignore? end |
#converter ⇒ Object
71 |
# File 'lib/lexr.rb', line 71 def converter ; @opts[:convert_with] ; end |
#ignore? ⇒ Boolean
72 |
# File 'lib/lexr.rb', line 72 def ignore? ; @opts[:ignore] ; end |
#match(text, previous_token = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/lexr.rb', line 78 def match(text, previous_token = nil) text_matched = self.send :"#{pattern.class.name.downcase}_matcher", text return nil unless text_matched return nil if predecate && !predecate[previous_token] value = converter ? converter[text_matched] : text_matched Lexr::MatchData.new(text_matched.length, Lexr::Token.new(value, symbol)) end |