lib/rhetor/lexical_analyser.rb
# Makes the analyser to recognize some pattern
# @param pattern [String, Regexp] the pattern
# @param name [Symbol] the name of the rule
# @param evaluator [Proc,nil] a proc. This proc will be called
#   if the pattern is encountered. It receives a matched substring
#   and calculates the value of the corresponding token. If this
#   argument is omitted, the value of the token will coincide
#   with the matched substring.
# @raise [InvalidPattern] if the pattern is not valid
# @raise [InvalidRuleName] unless the name of the rule is a symbol
# @raise [RuleAlreadyExists] if the rule with the same name already exists
# @return [void]
#
Makes the analyser to recognize some pattern
Makes the analyser to recognize some pattern
def rule(pattern, name, &evaluator)
      check_rule(pattern, name)
      @used_names.push name
      @evaluator[name] = evaluator
      array_name = "@#{pattern.class.name.downcase}_patterns".intern
      instance_variable_get(array_name)[name] = pattern
    end
def rule ( pattern , name , & evaluator ) check_rule ( pattern , name ) @used_names . push name @evaluator [ name ] = evaluator array_name = "@#{pattern.class.name.downcase}_patterns" . intern instance_variable_get ( array_name ) [ name ] = pattern end
Makes the analyser to recognize some pattern
Makes the analyser to recognize some pattern
None
void
[InvalidPattern] if the pattern is not valid
[ InvalidPattern ] if the pattern is not valid
[InvalidRuleName] unless the name of the rule is a symbol
[ InvalidRuleName ] unless the name of the rule is a symbol
[RuleAlreadyExists] if the rule with the same name already exists
[ RuleAlreadyExists ] if the rule with the same name already exists
pattern
None
name
the name of the rule
the name of the rule
evaluator
a proc. This proc will be called if the pattern is encountered. It receives a matched substring and calculates the value of the corresponding token. If this argument is omitted, the value of the token will coincide with the matched substring.
a proc . This proc will be called if the pattern is encountered . It receives a matched substring and calculates the value of the corresponding token . If this argument is omitted the value of the token will coincide with the matched substring .