Class: Dhaka::Conflict

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

Overview

Represents parser shift-reduce and reduce-reduce conflicts and encapsulates logic for resolving them.

Direct Known Subclasses

ReduceReduceConflict, ShiftReduceConflict

Instance Method Summary collapse

Constructor Details

#initialize(state, lookahead, new_action) ⇒ Conflict

:nodoc:



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

def initialize(state, lookahead, new_action)
  @lookahead, @new_action, @state = lookahead, new_action, state
end

Instance Method Details

#build_conflict_messageObject



8
9
10
11
12
13
14
# File 'lib/dhaka/parser/conflict.rb', line 8

def build_conflict_message
  lines = ["Parser Conflict at State:", @state.to_s(:hide_lookaheads => true)]
  lines << "Existing: #{@state.actions[@lookahead.name]}"
  lines << "New: #{@new_action}"
  lines << "Lookahead: #{@lookahead}"
  lines.join("\n")
end