Class: Walrus::Grammar::ParsletOmission
- Inherits:
-
ParsletCombination
- Object
- ParsletCombination
- Walrus::Grammar::ParsletOmission
- Defined in:
- lib/walrus/grammar/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.
25 26 27 28 29 |
# File 'lib/walrus/grammar/parslet_omission.rb', line 25 def initialize(parseable) raise ArgumentError if parseable.nil? @parseable = parseable @hash = @parseable.hash + 46 # fixed offset to avoid unwanted collisions with similar classes end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
22 23 24 |
# File 'lib/walrus/grammar/parslet_omission.rb', line 22 def hash @hash end |
Instance Method Details
#eql?(other) ⇒ Boolean
52 53 54 |
# File 'lib/walrus/grammar/parslet_omission.rb', line 52 def eql?(other) other.instance_of? ParsletOmission and other.parseable.eql? @parseable end |
#parse(string, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/walrus/grammar/parslet_omission.rb', line 31 def parse(string, = {}) raise ArgumentError 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 |