class Citrus::Terminal
A Terminal is a Rule that matches directly on the input stream and may not contain any other rule. Terminals are essentially wrappers for regular expressions. As such, the Citrus notation is identical to Ruby's regular expression notation, e.g.:
/expr/
Character classes and the dot symbol may also be used in Citrus notation for compatibility with other parsing expression implementations, e.g.:
[a-zA-Z] .
Character classes have the same semantics as character classes inside Ruby regular expressions. The dot matches any character, including newlines.
Attributes
regexp[R]
The actual Regexp object this rule uses to match.
Public Class Methods
new(regexp=/^/)
click to toggle source
# File lib/citrus.rb, line 880 def initialize(regexp=/^/) @regexp = regexp end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
Citrus::Rule#==
# File lib/citrus.rb, line 905 def ==(other) case other when Regexp @regexp == other else super end end
Also aliased as: eql?
case_sensitive?()
click to toggle source
Returns true
if this rule is case sensitive.
# File lib/citrus.rb, line 901 def case_sensitive? !@regexp.casefold? end
exec(input, events=[])
click to toggle source
Returns an array of events for this rule on the given input
.
# File lib/citrus.rb, line 888 def exec(input, events=[]) match = input.scan(@regexp) if match events << self events << CLOSE events << match.length end events end