Class Citrus::Terminal

  1. lib/citrus.rb
Parent: Object

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.

Methods

public class

  1. new

public instance

  1. ==
  2. case_sensitive?
  3. eql?
  4. exec

Included modules

  1. Rule

Attributes

regexp [R] The actual Regexp object this rule uses to match.

Public class methods

new (regexp=/^/)
[show source]
     # File lib/citrus.rb, line 881
881:     def initialize(regexp=/^/)
882:       @regexp = regexp
883:     end

Public instance methods

== (other)
[show source]
     # File lib/citrus.rb, line 906
906:     def ==(other)
907:       case other
908:       when Regexp
909:         @regexp == other
910:       else
911:         super
912:       end
913:     end
case_sensitive? ()

Returns true if this rule is case sensitive.

[show source]
     # File lib/citrus.rb, line 902
902:     def case_sensitive?
903:       !@regexp.casefold?
904:     end
eql? (other)

Alias for #==

exec (input, events=[])

Returns an array of events for this rule on the given input.

[show source]
     # File lib/citrus.rb, line 889
889:     def exec(input, events=[])
890:       match = input.scan(@regexp)
891: 
892:       if match
893:         events << self
894:         events << CLOSE
895:         events << match.length
896:       end
897: 
898:       events
899:     end