lrama 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitattributes +2 -0
- data/.github/workflows/codespell.yaml +1 -1
- data/.github/workflows/gh-pages.yml +5 -6
- data/.github/workflows/test.yaml +25 -14
- data/Gemfile +4 -3
- data/NEWS.md +370 -35
- data/README.md +7 -88
- data/Rakefile +3 -2
- data/Steepfile +11 -5
- data/doc/Index.md +1 -1
- data/doc/development/compressed_state_table/parser.rb +2 -0
- data/doc/development/profiling.md +44 -0
- data/exe/lrama +1 -1
- data/lib/lrama/bitmap.rb +18 -5
- data/lib/lrama/command.rb +95 -43
- data/lib/lrama/context.rb +22 -24
- data/lib/lrama/counterexamples/derivation.rb +14 -4
- data/lib/lrama/counterexamples/example.rb +47 -22
- data/lib/lrama/counterexamples/node.rb +30 -0
- data/lib/lrama/counterexamples/path.rb +12 -14
- data/lib/lrama/counterexamples/state_item.rb +24 -1
- data/lib/lrama/counterexamples/triple.rb +27 -9
- data/lib/lrama/counterexamples.rb +216 -88
- data/lib/lrama/diagram.rb +77 -0
- data/lib/lrama/digraph.rb +28 -7
- data/lib/lrama/erb.rb +29 -0
- data/lib/lrama/grammar/auxiliary.rb +6 -1
- data/lib/lrama/grammar/binding.rb +37 -25
- data/lib/lrama/grammar/code/destructor_code.rb +11 -0
- data/lib/lrama/grammar/code/initial_action_code.rb +3 -0
- data/lib/lrama/grammar/code/no_reference_code.rb +3 -0
- data/lib/lrama/grammar/code/printer_code.rb +11 -0
- data/lib/lrama/grammar/code/rule_action.rb +17 -0
- data/lib/lrama/grammar/code.rb +16 -1
- data/lib/lrama/grammar/counter.rb +10 -0
- data/lib/lrama/grammar/destructor.rb +14 -1
- data/lib/lrama/grammar/error_token.rb +14 -1
- data/lib/lrama/grammar/inline/resolver.rb +80 -0
- data/lib/lrama/grammar/inline.rb +3 -0
- data/lib/lrama/grammar/{parameterizing_rule → parameterized}/resolver.rb +19 -8
- data/lib/lrama/grammar/{parameterizing_rule → parameterized}/rhs.rb +7 -2
- data/lib/lrama/grammar/parameterized/rule.rb +36 -0
- data/lib/lrama/grammar/parameterized.rb +5 -0
- data/lib/lrama/grammar/percent_code.rb +12 -1
- data/lib/lrama/grammar/precedence.rb +43 -1
- data/lib/lrama/grammar/printer.rb +9 -0
- data/lib/lrama/grammar/reference.rb +13 -0
- data/lib/lrama/grammar/rule.rb +61 -1
- data/lib/lrama/grammar/rule_builder.rb +84 -69
- data/lib/lrama/grammar/stdlib.y +68 -48
- data/lib/lrama/grammar/symbol.rb +63 -19
- data/lib/lrama/grammar/symbols/resolver.rb +64 -3
- data/lib/lrama/grammar/type.rb +13 -1
- data/lib/lrama/grammar/union.rb +12 -1
- data/lib/lrama/grammar.rb +231 -35
- data/lib/lrama/lexer/location.rb +25 -8
- data/lib/lrama/lexer/token/base.rb +73 -0
- data/lib/lrama/lexer/token/char.rb +15 -2
- data/lib/lrama/lexer/token/empty.rb +14 -0
- data/lib/lrama/lexer/token/ident.rb +2 -2
- data/lib/lrama/lexer/token/instantiate_rule.rb +4 -4
- data/lib/lrama/lexer/token/int.rb +14 -0
- data/lib/lrama/lexer/token/str.rb +11 -0
- data/lib/lrama/lexer/token/tag.rb +2 -2
- data/lib/lrama/lexer/token/token.rb +11 -0
- data/lib/lrama/lexer/token/user_code.rb +63 -37
- data/lib/lrama/lexer/token.rb +6 -56
- data/lib/lrama/lexer.rb +51 -23
- data/lib/lrama/logger.rb +12 -2
- data/lib/lrama/option_parser.rb +63 -9
- data/lib/lrama/options.rb +25 -7
- data/lib/lrama/output.rb +4 -11
- data/lib/lrama/parser.rb +854 -723
- data/lib/lrama/reporter/conflicts.rb +44 -0
- data/lib/lrama/reporter/grammar.rb +39 -0
- data/lib/lrama/reporter/precedences.rb +54 -0
- data/lib/lrama/reporter/profile/call_stack.rb +45 -0
- data/lib/lrama/reporter/profile/memory.rb +44 -0
- data/lib/lrama/reporter/profile.rb +4 -0
- data/lib/lrama/reporter/rules.rb +43 -0
- data/lib/lrama/reporter/states.rb +387 -0
- data/lib/lrama/reporter/terms.rb +44 -0
- data/lib/lrama/reporter.rb +39 -0
- data/lib/lrama/state/action/goto.rb +33 -0
- data/lib/lrama/state/action/reduce.rb +71 -0
- data/lib/lrama/state/action/shift.rb +39 -0
- data/lib/lrama/state/action.rb +5 -0
- data/lib/lrama/state/inadequacy_annotation.rb +140 -0
- data/lib/lrama/{states → state}/item.rb +33 -4
- data/lib/lrama/state/reduce_reduce_conflict.rb +14 -1
- data/lib/lrama/state/resolved_conflict.rb +38 -4
- data/lib/lrama/state/shift_reduce_conflict.rb +14 -1
- data/lib/lrama/state.rb +301 -200
- data/lib/lrama/states.rb +447 -175
- data/lib/lrama/tracer/actions.rb +22 -0
- data/lib/lrama/tracer/closure.rb +30 -0
- data/lib/lrama/tracer/duration.rb +38 -0
- data/lib/lrama/tracer/only_explicit_rules.rb +24 -0
- data/lib/lrama/tracer/rules.rb +23 -0
- data/lib/lrama/tracer/state.rb +33 -0
- data/lib/lrama/tracer.rb +51 -0
- data/lib/lrama/version.rb +2 -1
- data/lib/lrama/warnings/conflicts.rb +27 -0
- data/lib/lrama/warnings/implicit_empty.rb +29 -0
- data/lib/lrama/warnings/name_conflicts.rb +63 -0
- data/lib/lrama/warnings/redefined_rules.rb +23 -0
- data/lib/lrama/warnings/required.rb +23 -0
- data/lib/lrama/warnings/useless_precedence.rb +25 -0
- data/lib/lrama/warnings.rb +33 -0
- data/lib/lrama.rb +5 -5
- data/parser.y +495 -404
- data/rbs_collection.lock.yaml +27 -3
- data/rbs_collection.yaml +2 -0
- data/sig/generated/lrama/bitmap.rbs +12 -4
- data/sig/generated/lrama/counterexamples/derivation.rbs +36 -0
- data/sig/generated/lrama/counterexamples/example.rbs +58 -0
- data/sig/generated/lrama/counterexamples/node.rbs +18 -0
- data/sig/generated/lrama/counterexamples/path.rbs +23 -0
- data/sig/generated/lrama/counterexamples/state_item.rbs +19 -0
- data/sig/generated/lrama/counterexamples/triple.rbs +32 -0
- data/sig/generated/lrama/counterexamples.rbs +98 -0
- data/sig/generated/lrama/diagram.rbs +34 -0
- data/sig/generated/lrama/digraph.rbs +26 -6
- data/sig/generated/lrama/erb.rbs +14 -0
- data/sig/generated/lrama/grammar/auxiliary.rbs +16 -0
- data/sig/generated/lrama/grammar/binding.rbs +18 -12
- data/sig/generated/lrama/grammar/code/destructor_code.rbs +26 -0
- data/sig/{lrama → generated/lrama}/grammar/code/initial_action_code.rbs +6 -0
- data/sig/{lrama → generated/lrama}/grammar/code/no_reference_code.rbs +6 -0
- data/sig/generated/lrama/grammar/code/printer_code.rbs +26 -0
- data/sig/generated/lrama/grammar/code/rule_action.rbs +63 -0
- data/sig/generated/lrama/grammar/code.rbs +38 -0
- data/sig/{lrama → generated/lrama}/grammar/counter.rbs +4 -0
- data/sig/generated/lrama/grammar/destructor.rbs +19 -0
- data/sig/generated/lrama/grammar/error_token.rbs +19 -0
- data/sig/generated/lrama/grammar/inline/resolver.rbs +26 -0
- data/sig/generated/lrama/grammar/parameterized/resolver.rbs +42 -0
- data/sig/generated/lrama/grammar/parameterized/rhs.rbs +21 -0
- data/sig/generated/lrama/grammar/parameterized/rule.rbs +28 -0
- data/sig/{lrama → generated/lrama}/grammar/percent_code.rbs +8 -0
- data/sig/generated/lrama/grammar/precedence.rbs +45 -0
- data/sig/{lrama/grammar/error_token.rbs → generated/lrama/grammar/printer.rbs} +8 -3
- data/sig/generated/lrama/grammar/reference.rbs +31 -0
- data/sig/generated/lrama/grammar/rule.rbs +83 -0
- data/sig/generated/lrama/grammar/rule_builder.rbs +91 -0
- data/sig/generated/lrama/grammar/symbol.rbs +89 -0
- data/sig/generated/lrama/grammar/symbols/resolver.rbs +131 -0
- data/sig/generated/lrama/grammar/type.rbs +21 -0
- data/sig/generated/lrama/grammar/union.rbs +17 -0
- data/sig/generated/lrama/grammar.rbs +289 -0
- data/sig/generated/lrama/lexer/location.rbs +12 -3
- data/sig/generated/lrama/lexer/token/base.rbs +53 -0
- data/sig/generated/lrama/lexer/token/char.rbs +9 -2
- data/sig/generated/lrama/lexer/token/empty.rbs +11 -0
- data/sig/generated/lrama/lexer/token/ident.rbs +2 -2
- data/sig/generated/lrama/lexer/token/instantiate_rule.rbs +5 -5
- data/sig/generated/lrama/lexer/token/int.rbs +13 -0
- data/sig/generated/lrama/lexer/token/str.rbs +10 -0
- data/sig/generated/lrama/lexer/token/tag.rbs +2 -2
- data/sig/generated/lrama/lexer/token/token.rbs +10 -0
- data/sig/generated/lrama/lexer/token/user_code.rbs +2 -2
- data/sig/generated/lrama/lexer/token.rbs +1 -39
- data/sig/generated/lrama/lexer.rbs +54 -0
- data/sig/generated/lrama/logger.rbs +6 -0
- data/sig/generated/lrama/option_parser.rbs +52 -0
- data/sig/{lrama → generated/lrama}/options.rbs +27 -3
- data/sig/generated/lrama/reporter/conflicts.rbs +18 -0
- data/sig/generated/lrama/reporter/grammar.rbs +13 -0
- data/sig/generated/lrama/reporter/precedences.rbs +15 -0
- data/sig/generated/lrama/reporter/profile/call_stack.rbs +19 -0
- data/sig/generated/lrama/reporter/profile/memory.rbs +19 -0
- data/sig/generated/lrama/reporter/rules.rbs +13 -0
- data/sig/generated/lrama/reporter/states.rbs +69 -0
- data/sig/generated/lrama/reporter/terms.rbs +13 -0
- data/sig/generated/lrama/reporter.rbs +13 -0
- data/sig/generated/lrama/state/action/goto.rbs +28 -0
- data/sig/generated/lrama/state/action/reduce.rbs +49 -0
- data/sig/generated/lrama/state/action/shift.rbs +33 -0
- data/sig/generated/lrama/state/inadequacy_annotation.rbs +45 -0
- data/sig/generated/lrama/state/item.rbs +75 -0
- data/sig/generated/lrama/state/reduce_reduce_conflict.rbs +19 -0
- data/sig/generated/lrama/state/resolved_conflict.rbs +38 -0
- data/sig/generated/lrama/state/shift_reduce_conflict.rbs +19 -0
- data/sig/generated/lrama/state.rbs +231 -0
- data/sig/generated/lrama/states.rbs +215 -0
- data/sig/generated/lrama/tracer/actions.rbs +13 -0
- data/sig/generated/lrama/tracer/closure.rbs +13 -0
- data/sig/generated/lrama/tracer/duration.rbs +18 -0
- data/sig/generated/lrama/tracer/only_explicit_rules.rbs +13 -0
- data/sig/generated/lrama/tracer/rules.rbs +13 -0
- data/sig/generated/lrama/tracer/state.rbs +16 -0
- data/sig/generated/lrama/tracer.rbs +23 -0
- data/sig/generated/lrama/version.rbs +5 -0
- data/sig/generated/lrama/warnings/conflicts.rbs +13 -0
- data/sig/generated/lrama/warnings/implicit_empty.rbs +17 -0
- data/sig/generated/lrama/warnings/name_conflicts.rbs +31 -0
- data/sig/generated/lrama/warnings/redefined_rules.rbs +13 -0
- data/sig/generated/lrama/warnings/required.rbs +13 -0
- data/sig/generated/lrama/warnings/useless_precedence.rbs +13 -0
- data/sig/generated/lrama/warnings.rbs +11 -0
- data/sig/railroad_diagrams/railroad_diagrams.rbs +16 -0
- data/template/bison/_yacc.h +8 -0
- data/template/diagram/diagram.html +102 -0
- metadata +126 -66
- data/lib/lrama/counterexamples/production_path.rb +0 -19
- data/lib/lrama/counterexamples/start_path.rb +0 -23
- data/lib/lrama/counterexamples/transition_path.rb +0 -19
- data/lib/lrama/diagnostics.rb +0 -36
- data/lib/lrama/grammar/parameterizing_rule/rule.rb +0 -24
- data/lib/lrama/grammar/parameterizing_rule.rb +0 -5
- data/lib/lrama/grammar_validator.rb +0 -37
- data/lib/lrama/report/duration.rb +0 -27
- data/lib/lrama/report/profile.rb +0 -16
- data/lib/lrama/report.rb +0 -4
- data/lib/lrama/state/reduce.rb +0 -37
- data/lib/lrama/state/shift.rb +0 -15
- data/lib/lrama/states_reporter.rb +0 -362
- data/lib/lrama/trace_reporter.rb +0 -45
- data/sig/generated/lrama/trace_reporter.rbs +0 -25
- data/sig/lrama/counterexamples/derivation.rbs +0 -33
- data/sig/lrama/counterexamples/example.rbs +0 -45
- data/sig/lrama/counterexamples/path.rbs +0 -21
- data/sig/lrama/counterexamples/production_path.rbs +0 -11
- data/sig/lrama/counterexamples/start_path.rbs +0 -13
- data/sig/lrama/counterexamples/state_item.rbs +0 -10
- data/sig/lrama/counterexamples/transition_path.rbs +0 -11
- data/sig/lrama/counterexamples/triple.rbs +0 -20
- data/sig/lrama/counterexamples.rbs +0 -29
- data/sig/lrama/grammar/auxiliary.rbs +0 -10
- data/sig/lrama/grammar/code/destructor_code.rbs +0 -14
- data/sig/lrama/grammar/code/printer_code.rbs +0 -14
- data/sig/lrama/grammar/code/rule_action.rbs +0 -19
- data/sig/lrama/grammar/code.rbs +0 -24
- data/sig/lrama/grammar/destructor.rbs +0 -13
- data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +0 -24
- data/sig/lrama/grammar/parameterizing_rule/rhs.rbs +0 -14
- data/sig/lrama/grammar/parameterizing_rule/rule.rbs +0 -16
- data/sig/lrama/grammar/parameterizing_rule.rbs +0 -6
- data/sig/lrama/grammar/precedence.rbs +0 -13
- data/sig/lrama/grammar/printer.rbs +0 -13
- data/sig/lrama/grammar/reference.rbs +0 -22
- data/sig/lrama/grammar/rule.rbs +0 -45
- data/sig/lrama/grammar/rule_builder.rbs +0 -47
- data/sig/lrama/grammar/symbol.rbs +0 -38
- data/sig/lrama/grammar/symbols/resolver.rbs +0 -60
- data/sig/lrama/grammar/type.rbs +0 -11
- data/sig/lrama/grammar/union.rbs +0 -12
- data/sig/lrama/grammar.rbs +0 -108
- data/sig/lrama/report/duration.rbs +0 -11
- data/sig/lrama/report/profile.rbs +0 -7
- data/sig/lrama/state/reduce.rbs +0 -20
- data/sig/lrama/state/reduce_reduce_conflict.rbs +0 -13
- data/sig/lrama/state/resolved_conflict.rbs +0 -14
- data/sig/lrama/state/shift.rbs +0 -14
- data/sig/lrama/state/shift_reduce_conflict.rbs +0 -13
- data/sig/lrama/state.rbs +0 -79
- data/sig/lrama/states/item.rbs +0 -30
- data/sig/lrama/states.rbs +0 -101
- data/sig/lrama/warning.rbs +0 -16
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class Report
|
|
5
|
-
module Duration
|
|
6
|
-
def self.enable
|
|
7
|
-
@_report_duration_enabled = true
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.enabled?
|
|
11
|
-
!!@_report_duration_enabled
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def report_duration(method_name)
|
|
15
|
-
time1 = Time.now.to_f
|
|
16
|
-
result = yield
|
|
17
|
-
time2 = Time.now.to_f
|
|
18
|
-
|
|
19
|
-
if Duration.enabled?
|
|
20
|
-
puts sprintf("%s %10.5f s", method_name, time2 - time1)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
return result
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/lib/lrama/report/profile.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class Report
|
|
5
|
-
module Profile
|
|
6
|
-
# See "Profiling Lrama" in README.md for how to use.
|
|
7
|
-
def self.report_profile
|
|
8
|
-
require "stackprof"
|
|
9
|
-
|
|
10
|
-
StackProf.run(mode: :cpu, raw: true, out: 'tmp/stackprof-cpu-myapp.dump') do
|
|
11
|
-
yield
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
data/lib/lrama/report.rb
DELETED
data/lib/lrama/state/reduce.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class State
|
|
5
|
-
class Reduce
|
|
6
|
-
# https://www.gnu.org/software/bison/manual/html_node/Default-Reductions.html
|
|
7
|
-
attr_reader :item, :look_ahead, :not_selected_symbols
|
|
8
|
-
attr_accessor :default_reduction
|
|
9
|
-
|
|
10
|
-
def initialize(item)
|
|
11
|
-
@item = item
|
|
12
|
-
@look_ahead = nil
|
|
13
|
-
@not_selected_symbols = []
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def rule
|
|
17
|
-
@item.rule
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def look_ahead=(look_ahead)
|
|
21
|
-
@look_ahead = look_ahead.freeze
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def add_not_selected_symbol(sym)
|
|
25
|
-
@not_selected_symbols << sym
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def selected_look_ahead
|
|
29
|
-
if look_ahead
|
|
30
|
-
look_ahead - @not_selected_symbols
|
|
31
|
-
else
|
|
32
|
-
[]
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
data/lib/lrama/state/shift.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class State
|
|
5
|
-
class Shift
|
|
6
|
-
attr_reader :next_sym, :next_items
|
|
7
|
-
attr_accessor :not_selected
|
|
8
|
-
|
|
9
|
-
def initialize(next_sym, next_items)
|
|
10
|
-
@next_sym = next_sym
|
|
11
|
-
@next_items = next_items
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class StatesReporter
|
|
5
|
-
include Lrama::Report::Duration
|
|
6
|
-
|
|
7
|
-
def initialize(states)
|
|
8
|
-
@states = states
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def report(io, **options)
|
|
12
|
-
report_duration(:report) do
|
|
13
|
-
_report(io, **options)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def _report(io, grammar: false, rules: false, terms: false, states: false, itemsets: false, lookaheads: false, solved: false, counterexamples: false, verbose: false)
|
|
20
|
-
report_unused_rules(io) if rules
|
|
21
|
-
report_unused_terms(io) if terms
|
|
22
|
-
report_conflicts(io)
|
|
23
|
-
report_grammar(io) if grammar
|
|
24
|
-
report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def report_unused_terms(io)
|
|
28
|
-
look_aheads = @states.states.each do |state|
|
|
29
|
-
state.reduces.flat_map do |reduce|
|
|
30
|
-
reduce.look_ahead unless reduce.look_ahead.nil?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
next_terms = @states.states.flat_map do |state|
|
|
35
|
-
state.shifts.map(&:next_sym).select(&:term?)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
unused_symbols = @states.terms.select do |term|
|
|
39
|
-
!(look_aheads + next_terms).include?(term)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
unless unused_symbols.empty?
|
|
43
|
-
io << "#{unused_symbols.count} Unused Terms\n\n"
|
|
44
|
-
unused_symbols.each_with_index do |term, index|
|
|
45
|
-
io << sprintf("%5d %s\n", index, term.id.s_value)
|
|
46
|
-
end
|
|
47
|
-
io << "\n\n"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def report_unused_rules(io)
|
|
52
|
-
used_rules = @states.rules.flat_map(&:rhs)
|
|
53
|
-
|
|
54
|
-
unused_rules = @states.rules.map(&:lhs).select do |rule|
|
|
55
|
-
!used_rules.include?(rule) && rule.token_id != 0
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
unless unused_rules.empty?
|
|
59
|
-
io << "#{unused_rules.count} Unused Rules\n\n"
|
|
60
|
-
unused_rules.each_with_index do |rule, index|
|
|
61
|
-
io << sprintf("%5d %s\n", index, rule.display_name)
|
|
62
|
-
end
|
|
63
|
-
io << "\n\n"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def report_conflicts(io)
|
|
68
|
-
has_conflict = false
|
|
69
|
-
|
|
70
|
-
@states.states.each do |state|
|
|
71
|
-
messages = []
|
|
72
|
-
cs = state.conflicts.group_by(&:type)
|
|
73
|
-
if cs[:shift_reduce]
|
|
74
|
-
messages << "#{cs[:shift_reduce].count} shift/reduce"
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
if cs[:reduce_reduce]
|
|
78
|
-
messages << "#{cs[:reduce_reduce].count} reduce/reduce"
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
unless messages.empty?
|
|
82
|
-
has_conflict = true
|
|
83
|
-
io << "State #{state.id} conflicts: #{messages.join(', ')}\n"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
if has_conflict
|
|
88
|
-
io << "\n\n"
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def report_grammar(io)
|
|
93
|
-
io << "Grammar\n"
|
|
94
|
-
last_lhs = nil
|
|
95
|
-
|
|
96
|
-
@states.rules.each do |rule|
|
|
97
|
-
if rule.empty_rule?
|
|
98
|
-
r = "ε"
|
|
99
|
-
else
|
|
100
|
-
r = rule.rhs.map(&:display_name).join(" ")
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
if rule.lhs == last_lhs
|
|
104
|
-
io << sprintf("%5d %s| %s\n", rule.id, " " * rule.lhs.display_name.length, r)
|
|
105
|
-
else
|
|
106
|
-
io << "\n"
|
|
107
|
-
io << sprintf("%5d %s: %s\n", rule.id, rule.lhs.display_name, r)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
last_lhs = rule.lhs
|
|
111
|
-
end
|
|
112
|
-
io << "\n\n"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
|
|
116
|
-
if counterexamples
|
|
117
|
-
cex = Counterexamples.new(@states)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
@states.states.each do |state|
|
|
121
|
-
# Report State
|
|
122
|
-
io << "State #{state.id}\n\n"
|
|
123
|
-
|
|
124
|
-
# Report item
|
|
125
|
-
last_lhs = nil
|
|
126
|
-
list = itemsets ? state.items : state.kernels
|
|
127
|
-
list.sort_by {|i| [i.rule_id, i.position] }.each do |item|
|
|
128
|
-
if item.empty_rule?
|
|
129
|
-
r = "ε •"
|
|
130
|
-
else
|
|
131
|
-
r = item.rhs.map(&:display_name).insert(item.position, "•").join(" ")
|
|
132
|
-
end
|
|
133
|
-
if item.lhs == last_lhs
|
|
134
|
-
l = " " * item.lhs.id.s_value.length + "|"
|
|
135
|
-
else
|
|
136
|
-
l = item.lhs.id.s_value + ":"
|
|
137
|
-
end
|
|
138
|
-
la = ""
|
|
139
|
-
if lookaheads && item.end_of_rule?
|
|
140
|
-
reduce = state.find_reduce_by_item!(item)
|
|
141
|
-
look_ahead = reduce.selected_look_ahead
|
|
142
|
-
unless look_ahead.empty?
|
|
143
|
-
la = " [#{look_ahead.map(&:display_name).join(", ")}]"
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
last_lhs = item.lhs
|
|
147
|
-
|
|
148
|
-
io << sprintf("%5i %s %s%s\n", item.rule_id, l, r, la)
|
|
149
|
-
end
|
|
150
|
-
io << "\n"
|
|
151
|
-
|
|
152
|
-
# Report shifts
|
|
153
|
-
tmp = state.term_transitions.reject do |shift, _|
|
|
154
|
-
shift.not_selected
|
|
155
|
-
end.map do |shift, next_state|
|
|
156
|
-
[shift.next_sym, next_state.id]
|
|
157
|
-
end
|
|
158
|
-
max_len = tmp.map(&:first).map(&:display_name).map(&:length).max
|
|
159
|
-
tmp.each do |term, state_id|
|
|
160
|
-
io << " #{term.display_name.ljust(max_len)} shift, and go to state #{state_id}\n"
|
|
161
|
-
end
|
|
162
|
-
io << "\n" unless tmp.empty?
|
|
163
|
-
|
|
164
|
-
# Report error caused by %nonassoc
|
|
165
|
-
nl = false
|
|
166
|
-
tmp = state.resolved_conflicts.select do |resolved|
|
|
167
|
-
resolved.which == :error
|
|
168
|
-
end.map do |error|
|
|
169
|
-
error.symbol.display_name
|
|
170
|
-
end
|
|
171
|
-
max_len = tmp.map(&:length).max
|
|
172
|
-
tmp.each do |name|
|
|
173
|
-
nl = true
|
|
174
|
-
io << " #{name.ljust(max_len)} error (nonassociative)\n"
|
|
175
|
-
end
|
|
176
|
-
io << "\n" unless tmp.empty?
|
|
177
|
-
|
|
178
|
-
# Report reduces
|
|
179
|
-
nl = false
|
|
180
|
-
max_len = state.non_default_reduces.flat_map(&:look_ahead).compact.map(&:display_name).map(&:length).max || 0
|
|
181
|
-
max_len = [max_len, "$default".length].max if state.default_reduction_rule
|
|
182
|
-
ary = []
|
|
183
|
-
|
|
184
|
-
state.non_default_reduces.each do |reduce|
|
|
185
|
-
reduce.look_ahead.each do |term|
|
|
186
|
-
ary << [term, reduce]
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
ary.sort_by do |term, reduce|
|
|
191
|
-
term.number
|
|
192
|
-
end.each do |term, reduce|
|
|
193
|
-
rule = reduce.item.rule
|
|
194
|
-
io << " #{term.display_name.ljust(max_len)} reduce using rule #{rule.id} (#{rule.lhs.display_name})\n"
|
|
195
|
-
nl = true
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
if (r = state.default_reduction_rule)
|
|
199
|
-
nl = true
|
|
200
|
-
s = "$default".ljust(max_len)
|
|
201
|
-
|
|
202
|
-
if r.initial_rule?
|
|
203
|
-
io << " #{s} accept\n"
|
|
204
|
-
else
|
|
205
|
-
io << " #{s} reduce using rule #{r.id} (#{r.lhs.display_name})\n"
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
io << "\n" if nl
|
|
209
|
-
|
|
210
|
-
# Report nonterminal transitions
|
|
211
|
-
tmp = []
|
|
212
|
-
max_len = 0
|
|
213
|
-
state.nterm_transitions.each do |shift, next_state|
|
|
214
|
-
nterm = shift.next_sym
|
|
215
|
-
tmp << [nterm, next_state.id]
|
|
216
|
-
max_len = [max_len, nterm.id.s_value.length].max
|
|
217
|
-
end
|
|
218
|
-
tmp.uniq!
|
|
219
|
-
tmp.sort_by! do |nterm, state_id|
|
|
220
|
-
nterm.number
|
|
221
|
-
end
|
|
222
|
-
tmp.each do |nterm, state_id|
|
|
223
|
-
io << " #{nterm.id.s_value.ljust(max_len)} go to state #{state_id}\n"
|
|
224
|
-
end
|
|
225
|
-
io << "\n" unless tmp.empty?
|
|
226
|
-
|
|
227
|
-
if solved
|
|
228
|
-
# Report conflict resolutions
|
|
229
|
-
state.resolved_conflicts.each do |resolved|
|
|
230
|
-
io << " #{resolved.report_message}\n"
|
|
231
|
-
end
|
|
232
|
-
io << "\n" unless state.resolved_conflicts.empty?
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
if counterexamples && state.has_conflicts?
|
|
236
|
-
# Report counterexamples
|
|
237
|
-
examples = cex.compute(state)
|
|
238
|
-
examples.each do |example|
|
|
239
|
-
label0 = example.type == :shift_reduce ? "shift/reduce" : "reduce/reduce"
|
|
240
|
-
label1 = example.type == :shift_reduce ? "Shift derivation" : "First Reduce derivation"
|
|
241
|
-
label2 = example.type == :shift_reduce ? "Reduce derivation" : "Second Reduce derivation"
|
|
242
|
-
|
|
243
|
-
io << " #{label0} conflict on token #{example.conflict_symbol.id.s_value}:\n"
|
|
244
|
-
io << " #{example.path1_item}\n"
|
|
245
|
-
io << " #{example.path2_item}\n"
|
|
246
|
-
io << " #{label1}\n"
|
|
247
|
-
example.derivations1.render_strings_for_report.each do |str|
|
|
248
|
-
io << " #{str}\n"
|
|
249
|
-
end
|
|
250
|
-
io << " #{label2}\n"
|
|
251
|
-
example.derivations2.render_strings_for_report.each do |str|
|
|
252
|
-
io << " #{str}\n"
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
if verbose
|
|
258
|
-
# Report direct_read_sets
|
|
259
|
-
io << " [Direct Read sets]\n"
|
|
260
|
-
direct_read_sets = @states.direct_read_sets
|
|
261
|
-
@states.nterms.each do |nterm|
|
|
262
|
-
terms = direct_read_sets[[state.id, nterm.token_id]]
|
|
263
|
-
next unless terms
|
|
264
|
-
next if terms.empty?
|
|
265
|
-
|
|
266
|
-
str = terms.map {|sym| sym.id.s_value }.join(", ")
|
|
267
|
-
io << " read #{nterm.id.s_value} shift #{str}\n"
|
|
268
|
-
end
|
|
269
|
-
io << "\n"
|
|
270
|
-
|
|
271
|
-
# Report reads_relation
|
|
272
|
-
io << " [Reads Relation]\n"
|
|
273
|
-
@states.nterms.each do |nterm|
|
|
274
|
-
a = @states.reads_relation[[state.id, nterm.token_id]]
|
|
275
|
-
next unless a
|
|
276
|
-
|
|
277
|
-
a.each do |state_id2, nterm_id2|
|
|
278
|
-
n = @states.nterms.find {|n| n.token_id == nterm_id2 }
|
|
279
|
-
io << " (State #{state_id2}, #{n.id.s_value})\n"
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
io << "\n"
|
|
283
|
-
|
|
284
|
-
# Report read_sets
|
|
285
|
-
io << " [Read sets]\n"
|
|
286
|
-
read_sets = @states.read_sets
|
|
287
|
-
@states.nterms.each do |nterm|
|
|
288
|
-
terms = read_sets[[state.id, nterm.token_id]]
|
|
289
|
-
next unless terms
|
|
290
|
-
next if terms.empty?
|
|
291
|
-
|
|
292
|
-
terms.each do |sym|
|
|
293
|
-
io << " #{sym.id.s_value}\n"
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
io << "\n"
|
|
297
|
-
|
|
298
|
-
# Report includes_relation
|
|
299
|
-
io << " [Includes Relation]\n"
|
|
300
|
-
@states.nterms.each do |nterm|
|
|
301
|
-
a = @states.includes_relation[[state.id, nterm.token_id]]
|
|
302
|
-
next unless a
|
|
303
|
-
|
|
304
|
-
a.each do |state_id2, nterm_id2|
|
|
305
|
-
n = @states.nterms.find {|n| n.token_id == nterm_id2 }
|
|
306
|
-
io << " (State #{state.id}, #{nterm.id.s_value}) -> (State #{state_id2}, #{n.id.s_value})\n"
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
io << "\n"
|
|
310
|
-
|
|
311
|
-
# Report lookback_relation
|
|
312
|
-
io << " [Lookback Relation]\n"
|
|
313
|
-
@states.rules.each do |rule|
|
|
314
|
-
a = @states.lookback_relation[[state.id, rule.id]]
|
|
315
|
-
next unless a
|
|
316
|
-
|
|
317
|
-
a.each do |state_id2, nterm_id2|
|
|
318
|
-
n = @states.nterms.find {|n| n.token_id == nterm_id2 }
|
|
319
|
-
io << " (Rule: #{rule.display_name}) -> (State #{state_id2}, #{n.id.s_value})\n"
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
io << "\n"
|
|
323
|
-
|
|
324
|
-
# Report follow_sets
|
|
325
|
-
io << " [Follow sets]\n"
|
|
326
|
-
follow_sets = @states.follow_sets
|
|
327
|
-
@states.nterms.each do |nterm|
|
|
328
|
-
terms = follow_sets[[state.id, nterm.token_id]]
|
|
329
|
-
|
|
330
|
-
next unless terms
|
|
331
|
-
|
|
332
|
-
terms.each do |sym|
|
|
333
|
-
io << " #{nterm.id.s_value} -> #{sym.id.s_value}\n"
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
io << "\n"
|
|
337
|
-
|
|
338
|
-
# Report LA
|
|
339
|
-
io << " [Look-Ahead Sets]\n"
|
|
340
|
-
tmp = []
|
|
341
|
-
max_len = 0
|
|
342
|
-
@states.rules.each do |rule|
|
|
343
|
-
syms = @states.la[[state.id, rule.id]]
|
|
344
|
-
next unless syms
|
|
345
|
-
|
|
346
|
-
tmp << [rule, syms]
|
|
347
|
-
max_len = ([max_len] + syms.map {|s| s.id.s_value.length }).max
|
|
348
|
-
end
|
|
349
|
-
tmp.each do |rule, syms|
|
|
350
|
-
syms.each do |sym|
|
|
351
|
-
io << " #{sym.id.s_value.ljust(max_len)} reduce using rule #{rule.id} (#{rule.lhs.id.s_value})\n"
|
|
352
|
-
end
|
|
353
|
-
end
|
|
354
|
-
io << "\n" unless tmp.empty?
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
# End of Report State
|
|
358
|
-
io << "\n"
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
end
|
data/lib/lrama/trace_reporter.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# rbs_inline: enabled
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
module Lrama
|
|
5
|
-
class TraceReporter
|
|
6
|
-
# @rbs (Lrama::Grammar grammar) -> void
|
|
7
|
-
def initialize(grammar)
|
|
8
|
-
@grammar = grammar
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# @rbs (**Hash[Symbol, bool] options) -> void
|
|
12
|
-
def report(**options)
|
|
13
|
-
_report(**options)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
# @rbs rules: (bool rules, bool actions, bool only_explicit_rules, **untyped _) -> void
|
|
19
|
-
def _report(rules: false, actions: false, only_explicit_rules: false, **_)
|
|
20
|
-
report_rules if rules && !only_explicit_rules
|
|
21
|
-
report_only_explicit_rules if only_explicit_rules
|
|
22
|
-
report_actions if actions
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @rbs () -> void
|
|
26
|
-
def report_rules
|
|
27
|
-
puts "Grammar rules:"
|
|
28
|
-
@grammar.rules.each { |rule| puts rule.display_name }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# @rbs () -> void
|
|
32
|
-
def report_only_explicit_rules
|
|
33
|
-
puts "Grammar rules:"
|
|
34
|
-
@grammar.rules.each do |rule|
|
|
35
|
-
puts rule.display_name_without_action if rule.lhs.first_set.any?
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @rbs () -> void
|
|
40
|
-
def report_actions
|
|
41
|
-
puts "Grammar rules with actions:"
|
|
42
|
-
@grammar.rules.each { |rule| puts rule.with_actions }
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Generated from lib/lrama/trace_reporter.rb with RBS::Inline
|
|
2
|
-
|
|
3
|
-
module Lrama
|
|
4
|
-
class TraceReporter
|
|
5
|
-
# @rbs (Lrama::Grammar grammar) -> void
|
|
6
|
-
def initialize: (Lrama::Grammar grammar) -> void
|
|
7
|
-
|
|
8
|
-
# @rbs (**Hash[Symbol, bool] options) -> void
|
|
9
|
-
def report: (**Hash[Symbol, bool] options) -> void
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
# @rbs rules: (bool rules, bool actions, bool only_explicit_rules, **untyped _) -> void
|
|
14
|
-
def _report: (?rules: untyped, ?actions: untyped, ?only_explicit_rules: untyped, **untyped _) -> untyped
|
|
15
|
-
|
|
16
|
-
# @rbs () -> void
|
|
17
|
-
def report_rules: () -> void
|
|
18
|
-
|
|
19
|
-
# @rbs () -> void
|
|
20
|
-
def report_only_explicit_rules: () -> void
|
|
21
|
-
|
|
22
|
-
# @rbs () -> void
|
|
23
|
-
def report_actions: () -> void
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module Lrama
|
|
2
|
-
class Counterexamples
|
|
3
|
-
class Derivation
|
|
4
|
-
@item: States::Item
|
|
5
|
-
|
|
6
|
-
@left: Derivation?
|
|
7
|
-
|
|
8
|
-
@right: Derivation?
|
|
9
|
-
|
|
10
|
-
attr_reader item: States::Item
|
|
11
|
-
|
|
12
|
-
attr_reader left: Derivation?
|
|
13
|
-
|
|
14
|
-
attr_reader right: Derivation?
|
|
15
|
-
|
|
16
|
-
attr_writer right: Derivation?
|
|
17
|
-
|
|
18
|
-
def initialize: (States::Item item, Derivation? left, ?Derivation? right) -> void
|
|
19
|
-
|
|
20
|
-
def to_s: () -> ::String
|
|
21
|
-
|
|
22
|
-
alias inspect to_s
|
|
23
|
-
|
|
24
|
-
def render_strings_for_report: () -> Array[String]
|
|
25
|
-
|
|
26
|
-
def render_for_report: () -> String
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def _render_for_report: (Derivation derivation, Integer offset, Array[String] strings, Integer index) -> Integer
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Lrama
|
|
2
|
-
class Counterexamples
|
|
3
|
-
class Example
|
|
4
|
-
@path1: ::Array[StartPath | TransitionPath | ProductionPath]
|
|
5
|
-
|
|
6
|
-
@path2: ::Array[StartPath | TransitionPath | ProductionPath]
|
|
7
|
-
|
|
8
|
-
@conflict: (State::ShiftReduceConflict | State::ReduceReduceConflict)
|
|
9
|
-
|
|
10
|
-
@conflict_symbol: Grammar::Symbol
|
|
11
|
-
|
|
12
|
-
@counterexamples: Counterexamples
|
|
13
|
-
|
|
14
|
-
@derivations1: Derivation
|
|
15
|
-
|
|
16
|
-
@derivations2: Derivation
|
|
17
|
-
|
|
18
|
-
attr_reader path1: ::Array[StartPath | TransitionPath | ProductionPath]
|
|
19
|
-
|
|
20
|
-
attr_reader path2: ::Array[StartPath | TransitionPath | ProductionPath]
|
|
21
|
-
|
|
22
|
-
attr_reader conflict: (State::ShiftReduceConflict | State::ReduceReduceConflict)
|
|
23
|
-
|
|
24
|
-
attr_reader conflict_symbol: Grammar::Symbol
|
|
25
|
-
|
|
26
|
-
def initialize: (::Array[StartPath | TransitionPath | ProductionPath]? path1, ::Array[StartPath | TransitionPath | ProductionPath]? path2, (State::ShiftReduceConflict | State::ReduceReduceConflict) conflict, Grammar::Symbol conflict_symbol, Counterexamples counterexamples) -> void
|
|
27
|
-
|
|
28
|
-
def type: () -> (:shift_reduce | :reduce_reduce)
|
|
29
|
-
|
|
30
|
-
def path1_item: () -> States::Item
|
|
31
|
-
|
|
32
|
-
def path2_item: () -> States::Item
|
|
33
|
-
|
|
34
|
-
def derivations1: () -> Derivation
|
|
35
|
-
|
|
36
|
-
def derivations2: () -> Derivation
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def _derivations: (::Array[StartPath | TransitionPath | ProductionPath] paths) -> Derivation
|
|
41
|
-
|
|
42
|
-
def find_derivation_for_symbol: (StateItem state_item, Grammar::Symbol sym) -> Derivation?
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module Lrama
|
|
2
|
-
class Counterexamples
|
|
3
|
-
class Path
|
|
4
|
-
@from_state_item: StateItem?
|
|
5
|
-
|
|
6
|
-
@to_state_item: StateItem
|
|
7
|
-
|
|
8
|
-
def initialize: (StateItem? from_state_item, StateItem to_state_item) -> void
|
|
9
|
-
|
|
10
|
-
def from: () -> StateItem?
|
|
11
|
-
|
|
12
|
-
def to: () -> StateItem
|
|
13
|
-
|
|
14
|
-
def to_s: () -> ::String
|
|
15
|
-
|
|
16
|
-
alias inspect to_s
|
|
17
|
-
|
|
18
|
-
def type: -> bot
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|