class LexicalRule
The RCTP class for lexical rules.
Attributes
regex[R]
symbol[R]
Public Class Methods
new(symbol, regex, &action)
click to toggle source
Create a lexical rule.
# File lib/lexical_analyzer/lexical_rule.rb, line 10 def initialize(symbol, regex, &action) @symbol = symbol @regex = regex define_singleton_method(:call, &action) if block_given? end
Public Instance Methods
call(value)
click to toggle source
The default rule action.
# File lib/lexical_analyzer/lexical_rule.rb, line 23 def call(value) [symbol, value] end
match(text)
click to toggle source
Does this rule match?
# File lib/lexical_analyzer/lexical_rule.rb, line 18 def match(text) text.match(@regex) end