Class: Walrat::ParsletOmission
- Inherits:
-
ParsletCombination
- Object
- ParsletCombination
- Walrat::ParsletOmission
- Defined in:
- lib/walrat/parslet_omission.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
-
#initialize(parseable) ⇒ ParsletOmission
constructor
Raises an ArgumentError if parseable is nil.
- #parse(string, options = {}) ⇒ Object
Methods inherited from ParsletCombination
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) ⇒ ParsletOmission
Raises an ArgumentError if parseable is nil.
30 31 32 33 34 35 36 |
# File 'lib/walrat/parslet_omission.rb', line 30 def initialize parseable raise ArgumentError, 'nil parseable' if parseable.nil? @parseable = parseable # fixed offset to avoid unwanted collisions with similar classes @hash = @parseable.hash + 46 end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
27 28 29 |
# File 'lib/walrat/parslet_omission.rb', line 27 def hash @hash end |
Instance Method Details
#eql?(other) ⇒ Boolean
65 66 67 |
# File 'lib/walrat/parslet_omission.rb', line 65 def eql?(other) other.instance_of? ParsletOmission and other.parseable.eql? @parseable end |
#parse(string, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/walrat/parslet_omission.rb', line 38 def parse string, = {} raise ArgumentError, 'nil string' if string.nil? substring = StringResult.new substring.start = [[:line_start], [:column_start]] substring.end = [[:line_start], [:column_start]] # possibly should catch these here as well #catch :NotPredicateSuccess do #catch :AndPredicateSuccess do # one of the fundamental problems is that if a parslet throws such a # symbol any info about already skipped material is lost (because the # symbols contain nothing) # this may be one reason to change these to exceptions... catch :ZeroWidthParseSuccess do substring = @parseable.memoizing_parse(string, ) end # not enough to just return a ZeroWidthParseSuccess here; that could # cause higher levels to stop parsing and in any case there'd be no # clean way to embed the scanned substring in the symbol raise SkippedSubstringException.new(substring, :line_start => [:line_start], :column_start => [:column_start], :line_end => substring.line_end, :column_end => substring.column_end) end |