Class: Ibex::Codegen::Ambiguity

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/codegen/ambiguity.rb

Overview

Renders a bounded ambiguity search over every parser conflict.

Constant Summary collapse

SCHEMA_VERSION =

: Integer

1

Instance Method Summary collapse

Constructor Details

#initialize(automaton, max_tokens: LALR::Counterexample::DEFAULT_MAX_TOKENS, max_configurations: LALR::Counterexample::DEFAULT_MAX_CONFIGURATIONS) ⇒ Ambiguity

Returns a new instance of Ambiguity.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ibex/codegen/ambiguity.rb', line 51

def initialize(
  automaton,
  max_tokens: LALR::Counterexample::DEFAULT_MAX_TOKENS,
  max_configurations: LALR::Counterexample::DEFAULT_MAX_CONFIGURATIONS
)
  LALR::ConflictSearchLimits.validate!(
    max_tokens: max_tokens, max_configurations: max_configurations
  )
  @automaton = automaton
  @grammar = automaton.grammar
  @max_tokens = max_tokens
  @max_configurations = max_configurations
  @checks = check_conflicts
end

Instance Method Details

#exit_statusObject



67
68
69
70
71
72
# File 'lib/ibex/codegen/ambiguity.rb', line 67

def exit_status
  return 1 if status == "ambiguous"
  return 2 if status == "inconclusive"

  0
end

#render_textObject



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ibex/codegen/ambiguity.rb', line 88

def render_text
  counts = summary
  lines = [
    "Ibex ambiguity check v#{SCHEMA_VERSION}",
    "Algorithm: #{@automaton.algorithm}",
    "Search budget: #{@max_tokens} tokens, #{@max_configurations} configurations per conflict",
    "Result: #{status}",
    "Conflicts: #{counts.fetch(:conflicts)}, ambiguous: #{counts.fetch(:ambiguous)}, " \
    "exhausted: #{counts.fetch(:configuration_budget_exhausted)}"
  ]
  @checks.each_with_index { |check, index| append_check(lines, check, index + 1) }
  "#{lines.join("\n")}\n"
end

#to_hObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ibex/codegen/ambiguity.rb', line 75

def to_h
  {
    ibex_check: "ambiguity",
    schema_version: SCHEMA_VERSION,
    algorithm: @automaton.algorithm,
    search: { max_tokens: @max_tokens, max_configurations: @max_configurations },
    status: status,
    summary: summary,
    conflicts: @checks
  }
end