Class: Citrus::Terminal
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#regexp ⇒ Object
readonly
The actual Regexp object this rule uses to match.
Attributes included from Rule
#extension, #grammar, #label, #name
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#case_sensitive? ⇒ Boolean
Returns
trueif this rule is case sensitive. -
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given
input. -
#initialize(regexp = /^/) ⇒ Terminal
constructor
A new instance of Terminal.
-
#terminal? ⇒ Boolean
Returns
trueif this rule is a Terminal. -
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
Methods included from Rule
#===, #default_options, #elide?, #extend_match, for, #inspect, #needs_paren?, #parse, #test, #to_embedded_s, #to_s
Constructor Details
#initialize(regexp = /^/) ⇒ Terminal
Returns a new instance of Terminal.
881 882 883 |
# File 'lib/citrus.rb', line 881 def initialize(regexp=/^/) @regexp = regexp end |
Instance Attribute Details
#regexp ⇒ Object (readonly)
The actual Regexp object this rule uses to match.
886 887 888 |
# File 'lib/citrus.rb', line 886 def regexp @regexp end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
906 907 908 909 910 911 912 913 |
# File 'lib/citrus.rb', line 906 def ==(other) case other when Regexp @regexp == other else super end end |
#case_sensitive? ⇒ Boolean
Returns true if this rule is case sensitive.
902 903 904 |
# File 'lib/citrus.rb', line 902 def case_sensitive? !@regexp.casefold? end |
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given input.
889 890 891 892 893 894 895 896 897 898 899 |
# File 'lib/citrus.rb', line 889 def exec(input, events=[]) match = input.scan(@regexp) if match events << self events << CLOSE events << match.length end events end |
#terminal? ⇒ Boolean
Returns true if this rule is a Terminal.
918 919 920 |
# File 'lib/citrus.rb', line 918 def terminal? # :nodoc: true end |
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
923 924 925 |
# File 'lib/citrus.rb', line 923 def to_citrus # :nodoc: @regexp.inspect end |