Class: Dhaka::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/dhaka/parser/channel.rb

Overview

Represents channels for pumping of lookaheads between items

Direct Known Subclasses

PassiveChannel, SpontaneousChannel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grammar, start_item, end_item) ⇒ Channel

Returns a new instance of Channel.



6
7
8
9
10
# File 'lib/dhaka/parser/channel.rb', line 6

def initialize(grammar, start_item, end_item)
  @grammar    = grammar
  @start_item = start_item
  @end_item   = end_item
end

Instance Attribute Details

#end_itemObject (readonly)

:nodoc:



4
5
6
# File 'lib/dhaka/parser/channel.rb', line 4

def end_item
  @end_item
end

#start_itemObject (readonly)

:nodoc:



4
5
6
# File 'lib/dhaka/parser/channel.rb', line 4

def start_item
  @start_item
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dhaka/parser/channel.rb', line 22

def eql? other
  start_item.eql?(other.start_item) && end_item.eql?(other.end_item)
end

#hashObject



26
27
28
# File 'lib/dhaka/parser/channel.rb', line 26

def hash
  start_item.hash ^ end_item.hash
end

#propagate(cargo) ⇒ Object



12
13
14
15
16
# File 'lib/dhaka/parser/channel.rb', line 12

def propagate cargo
  initial_size = end_item.lookaheadset.size
  end_item.lookaheadset.merge(cargo)
  (end_item.lookaheadset.size - initial_size) > 0
end

#to_sObject



18
19
20
# File 'lib/dhaka/parser/channel.rb', line 18

def to_s
  "Channel from #{start_item} to #{end_item}"
end