Class: Dhaka::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/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/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/parser/channel.rb', line 4

def end_item
  @end_item
end

#start_itemObject (readonly)

:nodoc:



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

def start_item
  @start_item
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  start_item.hash ^ end_item.hash
end

#propagate(cargo) ⇒ Object



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

def propagate cargo
  diff = cargo - end_item.lookaheadset
  end_item.lookaheadset.merge(diff)
  !diff.empty?
end

#to_sObject



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

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