Class: RDParser::Rule
- Inherits:
-
Object
- Object
- RDParser::Rule
- Defined in:
- lib/asciitracker/rdparser.rb
Defined Under Namespace
Classes: Match
Instance Method Summary collapse
- #add_match(pattern, block) ⇒ Object
-
#initialize(name, parser) ⇒ Rule
constructor
A new instance of Rule.
- #parse ⇒ Object
Constructor Details
#initialize(name, parser) ⇒ Rule
Returns a new instance of Rule.
102 103 104 105 106 107 |
# File 'lib/asciitracker/rdparser.rb', line 102 def initialize(name, parser) @name = name @parser = parser @matches = [] @lrmatches = [] end |
Instance Method Details
#add_match(pattern, block) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/asciitracker/rdparser.rb', line 109 def add_match(pattern, block) match = Match.new(pattern, block) if pattern[0] == @name pattern.shift @lrmatches << match else @matches << match end end |
#parse ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/asciitracker/rdparser.rb', line 119 def parse match_result = try_matches(@matches) return nil unless match_result loop do result = try_matches(@lrmatches, match_result) return match_result unless result match_result = result end end |