Class: Ibex::LALR::Counterexample
- Inherits:
-
Object
- Object
- Ibex::LALR::Counterexample
- Defined in:
- lib/ibex/lalr/counterexample.rb
Overview
Produces shortest-path conflict witnesses using Automaton IR only.
Constant Summary collapse
- DEFAULT_MAX_TOKENS =
: Integer
ConflictSearch::DEFAULT_MAX_TOKENS
- DEFAULT_MAX_CONFIGURATIONS =
: Integer
ConflictSearch::DEFAULT_MAX_CONFIGURATIONS
Instance Method Summary collapse
- #all ⇒ Object
- #for_conflict(state_id, conflict_index) ⇒ Object
-
#initialize(automaton, max_tokens: DEFAULT_MAX_TOKENS, max_configurations: DEFAULT_MAX_CONFIGURATIONS) ⇒ Counterexample
constructor
A new instance of Counterexample.
Constructor Details
#initialize(automaton, max_tokens: DEFAULT_MAX_TOKENS, max_configurations: DEFAULT_MAX_CONFIGURATIONS) ⇒ Counterexample
Returns a new instance of Counterexample.
11 12 13 14 15 16 17 18 |
# File 'lib/ibex/lalr/counterexample.rb', line 11 def initialize(automaton, max_tokens: DEFAULT_MAX_TOKENS, max_configurations: DEFAULT_MAX_CONFIGURATIONS) ConflictSearchLimits.validate!(max_tokens: max_tokens, max_configurations: max_configurations) @automaton = automaton @grammar = automaton.grammar @max_tokens = max_tokens @max_configurations = max_configurations @shortest_yields = compute_shortest_yields end |
Instance Method Details
#all ⇒ Object
21 22 23 24 25 |
# File 'lib/ibex/lalr/counterexample.rb', line 21 def all @automaton.states.flat_map do |state| state.conflicts.map { |conflict| build_example(state, conflict) } end end |
#for_conflict(state_id, conflict_index) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ibex/lalr/counterexample.rb', line 28 def for_conflict(state_id, conflict_index) state = @automaton.states.find { |candidate| candidate.id == state_id } raise ArgumentError, "unknown automaton state #{state_id}" unless state unless conflict_index.is_a?(Integer) && conflict_index >= 0 && conflict_index < state.conflicts.length raise ArgumentError, "conflict index #{conflict_index.inspect} is invalid for automaton state #{state_id}" end conflict = state.conflicts.fetch(conflict_index) build_example(state, conflict) end |