Class: Walrat::NotPredicate

Inherits:
Predicate show all
Defined in:
lib/walrat/not_predicate.rb

Instance Attribute Summary

Attributes inherited from Predicate

#hash

Instance Method Summary collapse

Methods inherited from Predicate

#eql?, #initialize, #to_parseable

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

This class inherits a constructor from Walrat::Predicate

Instance Method Details

#parse(string, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/walrat/not_predicate.rb', line 27

def parse string, options = {}
  raise ArgumentError, 'nil string' if string.nil?
  catch :ZeroWidthParseSuccess do
    begin
      @parseable.memoizing_parse(string, options)
    rescue ParseError # failed to pass (which is just what we wanted)
      throw :NotPredicateSuccess
    end
  end

  # getting this far means that parsing succeeded (not what we wanted)
  raise ParseError.new('predicate not satisfied ("%s" not allowed) while parsing "%s"' % [@parseable.to_s, string],
                       :line_end => options[:line_start],
                       :column_end => options[:column_start])
end