Class: Ibex::Codegen::Explain
- Inherits:
-
Object
- Object
- Ibex::Codegen::Explain
- Defined in:
- lib/ibex/codegen/explain.rb
Overview
Renders a selected conflict explanation from Automaton IR and counterexamples. rubocop:disable Metrics/ClassLength -- inline contracts and two stable output formats stay near selection policy.
Constant Summary collapse
- SCHEMA_VERSION =
: Integer
1
Instance Method Summary collapse
-
#initialize(automaton, state: nil, token: nil, max_tokens: LALR::Counterexample::DEFAULT_MAX_TOKENS, max_configurations: LALR::Counterexample::DEFAULT_MAX_CONFIGURATIONS) ⇒ Explain
constructor
A new instance of Explain.
- #render_text ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(automaton, state: nil, token: nil, max_tokens: LALR::Counterexample::DEFAULT_MAX_TOKENS, max_configurations: LALR::Counterexample::DEFAULT_MAX_CONFIGURATIONS) ⇒ Explain
Returns a new instance of Explain.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ibex/codegen/explain.rb', line 40 def initialize(automaton, state: nil, token: nil, max_tokens: LALR::Counterexample::DEFAULT_MAX_TOKENS, max_configurations: LALR::Counterexample::DEFAULT_MAX_CONFIGURATIONS) @automaton = automaton @grammar = automaton.grammar @state_selector = state @token_query = token @max_tokens = max_tokens @max_configurations = max_configurations @labels = SymbolLabels.build(@grammar) @token_selector = resolve_token(token) validate_state! @entries = select_entries end |
Instance Method Details
#render_text ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ibex/codegen/explain.rb', line 80 def render_text automaton = @automaton #: IR::Automaton entries = @entries #: Array[explain_entry] state_selector = @state_selector #: Integer? token_selector = @token_selector #: IR::GrammarSymbol? lines = [ "Ibex conflict explanation v#{SCHEMA_VERSION}", "Algorithm: #{automaton.algorithm}", "State selector: #{state_selector || 'all'}", "Token selector: #{token_selector ? token_label(token_selector, query: @token_query) : 'all'}", "Search budget: #{@max_tokens} tokens, #{@max_configurations} configurations", "Matched conflicts: #{entries.length}", "" ] if entries.empty? lines << "No conflicts matched the selectors." else entries.each_with_index { |entry, index| append_conflict(lines, entry, index + 1) } end "#{lines.join("\n")}\n" end |
#to_h ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ibex/codegen/explain.rb', line 55 def to_h entries = @entries #: Array[explain_entry] automaton = @automaton #: IR::Automaton = entries.count { |entry| entry.fetch(:example).fetch(:unifying) } inconclusive = entries.count { |entry| entry.fetch(:example).fetch(:inconclusive) } { ibex_explain: "conflicts", schema_version: SCHEMA_VERSION, algorithm: automaton.algorithm, selectors: { state: @state_selector, token: @token_selector && token_reference(@token_selector, query: @token_query) }, search: { max_tokens: @max_tokens, max_configurations: @max_configurations }, summary: { matched_conflicts: entries.length, unifying_counterexamples: , nonunifying_witnesses: entries.length - - inconclusive, inconclusive_searches: inconclusive }, conflicts: entries.map { |entry| conflict_document(entry) } } end |