Class: Walrus::Grammar::Predicate
- Inherits:
-
Object
- Object
- Walrus::Grammar::Predicate
- Includes:
- Memoizing, ParsletCombining
- Defined in:
- lib/walrus/grammar/predicate.rb
Overview
Predicates parse input without consuming it. On success they throw a subclass-specific symbol (see the AndPredicate and NotPredicate classes). On failure they raise a ParseError.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
-
#initialize(parseable) ⇒ Predicate
constructor
Raises if parseable is nil.
- #parse(string, options = {}) ⇒ Object
- #to_parseable ⇒ Object
Methods included from Memoizing
#check_left_recursion, #memoizing_parse
Methods included from ParsletCombining
#&, #>>, #and?, #and_predicate, #choice, #memoizing_parse, #merge, #not!, #not_predicate, #omission, #one_or_more, #optional, #repeat, #repeat_with_default, #repetition, #repetition_with_default, #sequence, #skip, #zero_or_more, #zero_or_one, #|
Constructor Details
#initialize(parseable) ⇒ Predicate
Raises if parseable is nil.
25 26 27 28 29 |
# File 'lib/walrus/grammar/predicate.rb', line 25 def initialize(parseable) raise ArgumentError if parseable.nil? @parseable = parseable @hash = @parseable.hash + hash_offset # fixed offset to avoid collisions with @parseable objects end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
22 23 24 |
# File 'lib/walrus/grammar/predicate.rb', line 22 def hash @hash end |
Instance Method Details
#eql?(other) ⇒ Boolean
39 40 41 |
# File 'lib/walrus/grammar/predicate.rb', line 39 def eql?(other) other.instance_of? self.class and other.parseable.eql? @parseable end |
#parse(string, options = {}) ⇒ Object
35 36 37 |
# File 'lib/walrus/grammar/predicate.rb', line 35 def parse(string, = {}) raise NotImplementedError # subclass responsibility end |
#to_parseable ⇒ Object
31 32 33 |
# File 'lib/walrus/grammar/predicate.rb', line 31 def to_parseable self end |