Class: Walrat::Predicate
- Inherits:
-
Object
- Object
- Walrat::Predicate
- Includes:
- Memoizing, ParsletCombining
- Defined in:
- lib/walrat/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.
37 38 39 40 41 42 43 |
# File 'lib/walrat/predicate.rb', line 37 def initialize parseable raise ArgumentError, 'nil parseable' if parseable.nil? @parseable = parseable # fixed offset to avoid collisions with @parseable objects @hash = @parseable.hash + hash_offset end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
34 35 36 |
# File 'lib/walrat/predicate.rb', line 34 def hash @hash end |
Instance Method Details
#eql?(other) ⇒ Boolean
53 54 55 |
# File 'lib/walrat/predicate.rb', line 53 def eql? other other.instance_of? self.class and other.parseable.eql? @parseable end |
#parse(string, options = {}) ⇒ Object
49 50 51 |
# File 'lib/walrat/predicate.rb', line 49 def parse string, = {} raise NotImplementedError # subclass responsibility end |
#to_parseable ⇒ Object
45 46 47 |
# File 'lib/walrat/predicate.rb', line 45 def to_parseable self end |