Class: Walrat::ProcParslet

Inherits:
Parslet
  • Object
show all
Defined in:
lib/walrat/proc_parslet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parslet

#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(proc) ⇒ ProcParslet

Returns a new instance of ProcParslet.

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/walrat/proc_parslet.rb', line 29

def initialize proc
  raise ArgumentError, 'nil proc' if proc.nil?
  self.expected_proc = proc
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



27
28
29
# File 'lib/walrat/proc_parslet.rb', line 27

def hash
  @hash
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/walrat/proc_parslet.rb', line 39

def eql?(other)
  other.instance_of? ProcParslet and other.expected_proc == @expected_proc
end

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

Raises:

  • (ArgumentError)


34
35
36
37
# File 'lib/walrat/proc_parslet.rb', line 34

def parse string, options = {}
  raise ArgumentError, 'nil string' if string.nil?
  @expected_proc.call string, options
end