class LexicalAnalyzer
The RCTP class for lexical analysis.
Constants
- VERSION
Attributes
rules[R]
text[R]
Public Class Methods
new(text: "", rules: [])
click to toggle source
Set things up.
# File lib/lexical_analyzer.rb, line 13 def initialize(text: "", rules: []) @text = text @rules = rules end
Public Instance Methods
get(extra=nil)
click to toggle source
Get the next lexical token
# File lib/lexical_analyzer.rb, line 26 def get(extra=nil) (extra ? rules + extra : rules).each do |rule| if match_data = rule.match(text) @text = match_data.post_match return rule.call(match_data.to_s) || get end end false end
renew(text: @text, rules: @rules)
click to toggle source
Reuse an existing lexical analyzer.
# File lib/lexical_analyzer.rb, line 19 def renew(text: @text, rules: @rules) @text = text @rules = rules self end