Class: Lrama::State::ResolvedConflict

Inherits:
Struct
  • Object
show all
Defined in:
lib/lrama/state/resolved_conflict.rb

Overview

  • symbol: A symbol under discussion

  • reduce: A reduce under discussion

  • which: For which a conflict is resolved. :shift, :reduce or :error (for nonassociative)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#reduceObject

Returns the value of attribute reduce

Returns:

  • (Object)

    the current value of reduce



6
7
8
# File 'lib/lrama/state/resolved_conflict.rb', line 6

def reduce
  @reduce
end

#same_precObject

Returns the value of attribute same_prec

Returns:

  • (Object)

    the current value of same_prec



6
7
8
# File 'lib/lrama/state/resolved_conflict.rb', line 6

def same_prec
  @same_prec
end

#symbolObject

Returns the value of attribute symbol

Returns:

  • (Object)

    the current value of symbol



6
7
8
# File 'lib/lrama/state/resolved_conflict.rb', line 6

def symbol
  @symbol
end

#whichObject

Returns the value of attribute which

Returns:

  • (Object)

    the current value of which



6
7
8
# File 'lib/lrama/state/resolved_conflict.rb', line 6

def which
  @which
end

Instance Method Details

#report_messageObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lrama/state/resolved_conflict.rb', line 7

def report_message
  s = symbol.display_name
  r = reduce.rule.precedence_sym.display_name
  case
  when which == :shift && same_prec
    msg = "resolved as #{which} (%right #{s})"
  when which == :shift
    msg = "resolved as #{which} (#{r} < #{s})"
  when which == :reduce && same_prec
    msg = "resolved as #{which} (%left #{s})"
  when which == :reduce
    msg = "resolved as #{which} (#{s} < #{r})"
  when which == :error
    msg = "resolved as an #{which} (%nonassoc #{s})"
  else
    raise "Unknown direction. #{self}"
  end

  "Conflict between rule #{reduce.rule.id} and token #{s} #{msg}."
end