Class: Walrus::Grammar::ParsletOmission

Inherits:
ParsletCombination show all
Defined in:
lib/walrus/grammar/parslet_omission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ParsletCombination

#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

#initialize(parseable) ⇒ ParsletOmission

Raises an ArgumentError if parseable is nil.

Raises:

  • (ArgumentError)


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

#hashObject (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

Returns:

  • (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

Raises:

  • (ArgumentError)


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, options = {})
  raise ArgumentError if string.nil?
  substring = StringResult.new
  substring.start = [options[:line_start], options[:column_start]]
  substring.end   = [options[:line_start], options[: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, options)
  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 => options[:line_start],  :column_start => options[:column_start],
                                      :line_end   => substring.line_end,    :column_end   => substring.column_end)
end