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:



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

def end_item
  @end_item
end

#start_itemObject (readonly)

:nodoc:



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

def start_item
  @start_item
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  @start_item.hash ^ @end_item.hash
end

#propagate(cargo) ⇒ Object



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

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

#to_sObject



16
17
18
# File 'lib/parser/channel.rb', line 16

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