Class: Walrat::ParsletOmission

Inherits:
ParsletCombination show all
Defined in:
lib/walrat/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)


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

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

Returns:

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

Raises:

  • (ArgumentError)


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, options = {}
  raise ArgumentError, 'nil string' 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