ibex 0.1.0

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.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +43 -0
  3. data/CHANGELOG.md +30 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +194 -0
  6. data/Rakefile +25 -0
  7. data/Steepfile +10 -0
  8. data/docs/architecture.md +99 -0
  9. data/docs/compat-notes.md +37 -0
  10. data/docs/grammar-reference.md +127 -0
  11. data/docs/lexer-coverage.md +14 -0
  12. data/docs/phase10-extensions.md +27 -0
  13. data/docs/racc-migration.md +47 -0
  14. data/exe/ibex +6 -0
  15. data/gemfiles/Gemfile +7 -0
  16. data/gemfiles/Gemfile.lock +98 -0
  17. data/lib/ibex/analysis/sets.rb +194 -0
  18. data/lib/ibex/analysis.rb +8 -0
  19. data/lib/ibex/cli/counterexample_options.rb +38 -0
  20. data/lib/ibex/cli/outputs.rb +88 -0
  21. data/lib/ibex/cli.rb +333 -0
  22. data/lib/ibex/codegen/dot.rb +52 -0
  23. data/lib/ibex/codegen/html.rb +110 -0
  24. data/lib/ibex/codegen/rbs.rb +54 -0
  25. data/lib/ibex/codegen/report.rb +149 -0
  26. data/lib/ibex/codegen/ruby.rb +235 -0
  27. data/lib/ibex/codegen/symbol_labels.rb +18 -0
  28. data/lib/ibex/error.rb +7 -0
  29. data/lib/ibex/frontend/action_scanner.rb +266 -0
  30. data/lib/ibex/frontend/ast.rb +146 -0
  31. data/lib/ibex/frontend/bootstrap_parser.rb +163 -0
  32. data/lib/ibex/frontend/dsl.rb +196 -0
  33. data/lib/ibex/frontend/generated_parser.rb +434 -0
  34. data/lib/ibex/frontend/generated_parser_base.rb +273 -0
  35. data/lib/ibex/frontend/grammar.y +156 -0
  36. data/lib/ibex/frontend/lexer.rb +165 -0
  37. data/lib/ibex/frontend/parser/declarations.rb +163 -0
  38. data/lib/ibex/frontend/parser/rules.rb +154 -0
  39. data/lib/ibex/frontend/parser.rb +23 -0
  40. data/lib/ibex/frontend/regenerator.rb +41 -0
  41. data/lib/ibex/frontend/source_cursor.rb +94 -0
  42. data/lib/ibex/frontend/token_adapter/declaration_state.rb +248 -0
  43. data/lib/ibex/frontend/token_adapter/delimiter_tracker.rb +37 -0
  44. data/lib/ibex/frontend/token_adapter/rule_state.rb +162 -0
  45. data/lib/ibex/frontend/token_adapter.rb +108 -0
  46. data/lib/ibex/frontend.rb +28 -0
  47. data/lib/ibex/ir/automaton_ir.rb +109 -0
  48. data/lib/ibex/ir/grammar_ir.rb +192 -0
  49. data/lib/ibex/ir/serialize.rb +154 -0
  50. data/lib/ibex/ir.rb +53 -0
  51. data/lib/ibex/lalr/builder.rb +270 -0
  52. data/lib/ibex/lalr/conflict.rb +120 -0
  53. data/lib/ibex/lalr/conflict_search.rb +332 -0
  54. data/lib/ibex/lalr/conflict_search_limits.rb +39 -0
  55. data/lib/ibex/lalr/counterexample.rb +138 -0
  56. data/lib/ibex/lalr/default_reductions.rb +67 -0
  57. data/lib/ibex/lalr.rb +27 -0
  58. data/lib/ibex/normalize/declarations.rb +60 -0
  59. data/lib/ibex/normalize/diagnostics.rb +99 -0
  60. data/lib/ibex/normalize/expander.rb +218 -0
  61. data/lib/ibex/normalize/expression.rb +54 -0
  62. data/lib/ibex/normalize.rb +166 -0
  63. data/lib/ibex/runtime/parser.rb +360 -0
  64. data/lib/ibex/runtime.rb +8 -0
  65. data/lib/ibex/tables.rb +125 -0
  66. data/lib/ibex/version.rb +6 -0
  67. data/lib/ibex.rb +23 -0
  68. data/sig/ibex/analysis/sets.rbs +72 -0
  69. data/sig/ibex/analysis.rbs +6 -0
  70. data/sig/ibex/cli/counterexample_options.rbs +16 -0
  71. data/sig/ibex/cli/outputs.rbs +31 -0
  72. data/sig/ibex/cli.rbs +108 -0
  73. data/sig/ibex/codegen/dot.rbs +19 -0
  74. data/sig/ibex/codegen/html.rbs +35 -0
  75. data/sig/ibex/codegen/rbs.rbs +31 -0
  76. data/sig/ibex/codegen/report.rbs +39 -0
  77. data/sig/ibex/codegen/ruby.rbs +92 -0
  78. data/sig/ibex/codegen/symbol_labels.rbs +11 -0
  79. data/sig/ibex/error.rbs +7 -0
  80. data/sig/ibex/frontend/action_scanner.rbs +74 -0
  81. data/sig/ibex/frontend/ast.rbs +223 -0
  82. data/sig/ibex/frontend/bootstrap_parser.rbs +80 -0
  83. data/sig/ibex/frontend/dsl.rbs +124 -0
  84. data/sig/ibex/frontend/generated_parser.rbs +163 -0
  85. data/sig/ibex/frontend/generated_parser_base.rbs +114 -0
  86. data/sig/ibex/frontend/lexer.rbs +61 -0
  87. data/sig/ibex/frontend/parser/declarations.rbs +56 -0
  88. data/sig/ibex/frontend/parser/rules.rbs +48 -0
  89. data/sig/ibex/frontend/parser.rbs +16 -0
  90. data/sig/ibex/frontend/regenerator.rbs +16 -0
  91. data/sig/ibex/frontend/source_cursor.rbs +73 -0
  92. data/sig/ibex/frontend/token_adapter/declaration_state.rbs +97 -0
  93. data/sig/ibex/frontend/token_adapter/delimiter_tracker.rbs +25 -0
  94. data/sig/ibex/frontend/token_adapter/rule_state.rbs +77 -0
  95. data/sig/ibex/frontend/token_adapter.rbs +67 -0
  96. data/sig/ibex/frontend.rbs +15 -0
  97. data/sig/ibex/ir/automaton_ir.rbs +77 -0
  98. data/sig/ibex/ir/grammar_ir.rbs +143 -0
  99. data/sig/ibex/ir/serialize.rbs +50 -0
  100. data/sig/ibex/ir.rbs +43 -0
  101. data/sig/ibex/lalr/builder.rbs +85 -0
  102. data/sig/ibex/lalr/conflict.rbs +47 -0
  103. data/sig/ibex/lalr/conflict_search.rbs +131 -0
  104. data/sig/ibex/lalr/conflict_search_limits.rbs +29 -0
  105. data/sig/ibex/lalr/counterexample.rbs +53 -0
  106. data/sig/ibex/lalr/default_reductions.rbs +20 -0
  107. data/sig/ibex/lalr.rbs +23 -0
  108. data/sig/ibex/normalize/declarations.rbs +20 -0
  109. data/sig/ibex/normalize/diagnostics.rbs +32 -0
  110. data/sig/ibex/normalize/expander.rbs +66 -0
  111. data/sig/ibex/normalize/expression.rbs +21 -0
  112. data/sig/ibex/normalize.rbs +96 -0
  113. data/sig/ibex/runtime/parser.rbs +167 -0
  114. data/sig/ibex/runtime.rbs +6 -0
  115. data/sig/ibex/tables.rbs +50 -0
  116. data/sig/ibex/version.rbs +6 -0
  117. data/sig/ibex.rbs +6 -0
  118. metadata +161 -0
@@ -0,0 +1,85 @@
1
+ # Generated from lib/ibex/lalr/builder.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Builds canonical LR(1) states and merges states with equal LR(0) cores.
6
+ class Builder
7
+ AUGMENTED_PRODUCTION: Integer
8
+
9
+ ALGORITHMS: Array[Symbol]
10
+
11
+ @resolver: ConflictResolver
12
+
13
+ @productions_by_lhs: Hash[Integer, Array[IR::Production]]
14
+
15
+ @sets: Analysis::Sets
16
+
17
+ @algorithm: Symbol
18
+
19
+ @grammar: IR::Grammar
20
+
21
+ # @rbs (IR::Grammar grammar, ?algorithm: Symbol | String) -> void
22
+ def initialize: (IR::Grammar grammar, ?algorithm: Symbol | String) -> void
23
+
24
+ # @rbs () -> IR::Automaton
25
+ def build: () -> IR::Automaton
26
+
27
+ private
28
+
29
+ # @rbs () -> [Array[item_set], transitions]
30
+ def canonical_collection: () -> [ Array[item_set], transitions ]
31
+
32
+ # @rbs (item_set seed) -> item_set
33
+ def closure: (item_set seed) -> item_set
34
+
35
+ # @rbs (Array[Integer] suffix, Integer inherited) -> Array[Integer]
36
+ def suffix_lookaheads: (Array[Integer] suffix, Integer inherited) -> Array[Integer]
37
+
38
+ # @rbs (item_set items, Array[lr_item] queue, lr_item item) -> void
39
+ def enqueue_item: (item_set items, Array[lr_item] queue, lr_item item) -> void
40
+
41
+ # @rbs (item_set items) -> Array[Integer]
42
+ def next_symbols: (item_set items) -> Array[Integer]
43
+
44
+ # @rbs (item_set items, Integer symbol_id) -> item_set
45
+ def go_to: (item_set items, Integer symbol_id) -> item_set
46
+
47
+ # @rbs (Array[item_set] states, transitions transitions) -> [Array[packed_items], transitions]
48
+ def merge_lalr: (Array[item_set] states, transitions transitions) -> [ Array[packed_items], transitions ]
49
+
50
+ # @rbs (Array[item_set] canonical_states, transitions canonical_transitions) -> [Array[packed_items], transitions]
51
+ def automaton_items: (Array[item_set] canonical_states, transitions canonical_transitions) -> [ Array[packed_items], transitions ]
52
+
53
+ # @rbs (Array[item_set] states) -> Array[packed_items]
54
+ def pack_canonical_items: (Array[item_set] states) -> Array[packed_items]
55
+
56
+ # @rbs (Array[packed_items] states) -> void
57
+ def apply_slr_lookaheads: (Array[packed_items] states) -> void
58
+
59
+ # @rbs (Integer production_id) -> Array[Integer]
60
+ def slr_lookaheads: (Integer production_id) -> Array[Integer]
61
+
62
+ # @rbs (Array[packed_items] merged_items, transitions transitions) -> Array[IR::AutomatonState]
63
+ def build_states: (Array[packed_items] merged_items, transitions transitions) -> Array[IR::AutomatonState]
64
+
65
+ # @rbs (Integer state_id, Array[IR::AutomatonItem] items, Hash[Integer, Integer] transitions) -> IR::AutomatonState
66
+ def build_state: (Integer state_id, Array[IR::AutomatonItem] items, Hash[Integer, Integer] transitions) -> IR::AutomatonState
67
+
68
+ # @rbs (Array[IR::AutomatonItem] items, Hash[Integer, Array[IR::parser_action]] candidates) -> void
69
+ def add_completed_actions: (Array[IR::AutomatonItem] items, Hash[Integer, Array[IR::parser_action]] candidates) -> void
70
+
71
+ # @rbs (Hash[Integer, Array[IR::parser_action]] candidates) ->
72
+ # [Hash[Integer, IR::parser_action], Array[IR::conflict]]
73
+ def resolve_actions: (Hash[Integer, Array[IR::parser_action]] candidates) -> [ Hash[Integer, IR::parser_action], Array[IR::conflict] ]
74
+
75
+ # @rbs (Integer production_id) -> Array[Integer]
76
+ def rhs_for: (Integer production_id) -> Array[Integer]
77
+
78
+ # @rbs (item_set items) -> Array[item_core]
79
+ def core_key: (item_set items) -> Array[item_core]
80
+
81
+ # @rbs (item_set items) -> Array[lr_item]
82
+ def item_key: (item_set items) -> Array[lr_item]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,47 @@
1
+ # Generated from lib/ibex/lalr/conflict.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Applies yacc-compatible precedence and ordering rules to action candidates.
6
+ class ConflictResolver
7
+ # @rbs (IR::Grammar grammar) -> void
8
+ def initialize: (IR::Grammar grammar) -> void
9
+
10
+ # @rbs (Integer token_id, Array[IR::parser_action] candidates) -> [IR::parser_action?, Array[IR::conflict]]
11
+ def resolve: (Integer token_id, Array[IR::parser_action] candidates) -> [ IR::parser_action?, Array[IR::conflict] ]
12
+
13
+ private
14
+
15
+ # @rbs (Array[IR::parser_action] actions) -> Array[IR::reduce_action]
16
+ def reduction_actions: (Array[IR::parser_action] actions) -> Array[IR::reduce_action]
17
+
18
+ # @rbs (Array[IR::reduce_reduce_conflict] conflicts) -> Array[IR::conflict]
19
+ def widen_conflicts: (Array[IR::reduce_reduce_conflict] conflicts) -> Array[IR::conflict]
20
+
21
+ # @rbs (Integer token_id, Array[IR::reduce_action] reductions) ->
22
+ # [IR::reduce_action?, Array[IR::reduce_reduce_conflict]]
23
+ def resolve_reductions: (Integer token_id, Array[IR::reduce_action] reductions) -> [ IR::reduce_action?, Array[IR::reduce_reduce_conflict] ]
24
+
25
+ # @rbs (Integer token_id, IR::shift_action shift, IR::reduce_action reduction) ->
26
+ # [IR::parser_action, IR::shift_reduce_conflict]
27
+ def resolve_shift_reduce: (Integer token_id, IR::shift_action shift, IR::reduce_action reduction) -> [ IR::parser_action, IR::shift_reduce_conflict ]
28
+
29
+ # @rbs (IR::shift_action shift, IR::reduce_action reduction, IR::precedence? token_precedence,
30
+ # IR::precedence? production_precedence) -> [IR::parser_action, IR::conflict_resolution]
31
+ def precedence_choice: (IR::shift_action shift, IR::reduce_action reduction, IR::precedence? token_precedence, IR::precedence? production_precedence) -> [ IR::parser_action, IR::conflict_resolution ]
32
+
33
+ # @rbs (IR::shift_action shift, IR::reduce_action reduction, Symbol associativity) ->
34
+ # [IR::parser_action, IR::conflict_resolution]
35
+ def associativity_choice: (IR::shift_action shift, IR::reduce_action reduction, Symbol associativity) -> [ IR::parser_action, IR::conflict_resolution ]
36
+
37
+ # @rbs (Integer production_id) -> IR::precedence?
38
+ def precedence_for_production: (Integer production_id) -> IR::precedence?
39
+
40
+ # @rbs (Integer token_id) -> String
41
+ def token_name: (Integer token_id) -> String
42
+
43
+ # @rbs (Integer id) -> IR::GrammarSymbol
44
+ def required_symbol_by_id: (Integer id) -> IR::GrammarSymbol
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,131 @@
1
+ # Generated from lib/ibex/lalr/conflict_search.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Searches the parser state space for one input accepted through both sides of a conflict.
6
+ # rubocop:disable Metrics/ClassLength -- inline type contracts make the focused search implementation longer.
7
+ class ConflictSearch
8
+ include ConflictSearchLimits
9
+
10
+ DEFAULT_MAX_TOKENS: Integer
11
+
12
+ DEFAULT_MAX_CONFIGURATIONS: Integer
13
+
14
+ class Configuration < Struct[Array[Integer] | Array[derivation_node]]
15
+ attr_accessor states(): Array[Integer]
16
+
17
+ attr_accessor nodes(): Array[derivation_node]
18
+
19
+ def self.new: (?states: Array[Integer], ?nodes: Array[derivation_node]) -> instance
20
+ | ({ ?states: Array[Integer], ?nodes: Array[derivation_node] }) -> instance
21
+ end
22
+
23
+ @input_tokens: Array[Integer]
24
+
25
+ @explored: Integer
26
+
27
+ @max_configurations: Integer
28
+
29
+ @max_tokens: Integer
30
+
31
+ @lookahead: Integer?
32
+
33
+ @conflict: IR::conflict
34
+
35
+ @state: IR::AutomatonState
36
+
37
+ @grammar: IR::Grammar
38
+
39
+ @automaton: IR::Automaton
40
+
41
+ # @rbs (IR::Automaton automaton, IR::AutomatonState state, IR::conflict conflict,
42
+ # ?max_tokens: Integer, ?max_configurations: Integer) -> void
43
+ def initialize: (IR::Automaton automaton, IR::AutomatonState state, IR::conflict conflict, ?max_tokens: Integer, ?max_configurations: Integer) -> void
44
+
45
+ # @rbs () -> search_result?
46
+ def call: () -> search_result?
47
+
48
+ private
49
+
50
+ # @rbs (Configuration current) -> Array[Configuration]
51
+ def conflict_configurations: (Configuration current) -> Array[Configuration]
52
+
53
+ # @rbs (Array[[Configuration, Array[Integer]]] queue, Hash[Array[Integer], bool] visited,
54
+ # Configuration current, Array[Integer] prefix) -> void
55
+ def enqueue_prefixes: (Array[[ Configuration, Array[Integer] ]] queue, Hash[Array[Integer], bool] visited, Configuration current, Array[Integer] prefix) -> void
56
+
57
+ # @rbs (Configuration current, Array[Integer] prefix) -> search_result?
58
+ def unify_from: (Configuration current, Array[Integer] prefix) -> search_result?
59
+
60
+ # @rbs (search_entry left, search_entry right, Array[Integer] prefix, IR::parser_action left_action,
61
+ # IR::parser_action right_action) -> search_result?
62
+ def search_common_suffix: (search_entry left, search_entry right, Array[Integer] prefix, IR::parser_action left_action, IR::parser_action right_action) -> search_result?
63
+
64
+ # @rbs (Configuration left_config, Configuration right_config) -> [search_entry, search_entry]?
65
+ def accept_with_eof: (Configuration left_config, Configuration right_config) -> [ search_entry, search_entry ]?
66
+
67
+ # @rbs (Array[[Configuration, Configuration, Array[Integer]]] queue,
68
+ # Hash[[Array[Integer], Array[Integer]], bool] visited, Configuration left_config,
69
+ # Configuration right_config, Array[Integer] suffix) -> void
70
+ def enqueue_suffixes: (Array[[ Configuration, Configuration, Array[Integer] ]] queue, Hash[[ Array[Integer], Array[Integer] ], bool] visited, Configuration left_config, Configuration right_config, Array[Integer] suffix) -> void
71
+
72
+ # @rbs (Configuration current, Integer token_id) -> Array[Configuration]
73
+ def shifted_results: (Configuration current, Integer token_id) -> Array[Configuration]
74
+
75
+ # @rbs (Array[Integer] prefix, Array[Integer] suffix, search_entry left, search_entry right,
76
+ # IR::parser_action left_action, IR::parser_action right_action) -> search_result?
77
+ def accepted_result: (Array[Integer] prefix, Array[Integer] suffix, search_entry left, search_entry right, IR::parser_action left_action, IR::parser_action right_action) -> search_result?
78
+
79
+ # @rbs (IR::parser_action action, Configuration current) -> IR::interpretation
80
+ def interpretation: (IR::parser_action action, Configuration current) -> IR::interpretation
81
+
82
+ # @rbs (search_entry left, search_entry right) -> bool
83
+ def accepted_pair?: (search_entry left, search_entry right) -> bool
84
+
85
+ # @rbs (search_entry left, search_entry right) -> bool
86
+ def shifted_pair?: (search_entry left, search_entry right) -> bool
87
+
88
+ # @rbs () -> Array[IR::parser_action]
89
+ def conflict_actions: () -> Array[IR::parser_action]
90
+
91
+ # @rbs (Configuration initial, Integer token_id, ?forced_action: IR::parser_action?, ?stop_at: Integer?,
92
+ # ?branch_conflicts: bool) -> Array[search_entry]
93
+ def advance: (Configuration initial, Integer token_id, ?forced_action: IR::parser_action?, ?stop_at: Integer?, ?branch_conflicts: bool) -> Array[search_entry]
94
+
95
+ # @rbs (Integer state_id, Integer token_id, IR::parser_action? forced, bool branch_conflicts) ->
96
+ # Array[IR::parser_action]
97
+ def actions_for: (Integer state_id, Integer token_id, IR::parser_action? forced, bool branch_conflicts) -> Array[IR::parser_action]
98
+
99
+ # @rbs (IR::conflict conflict) -> Array[IR::parser_action]
100
+ def actions_from: (IR::conflict conflict) -> Array[IR::parser_action]
101
+
102
+ # @rbs (Array[search_entry] results, Array[[Configuration, IR::parser_action?]] queue,
103
+ # Configuration current, IR::parser_action action, Integer token_id) -> void
104
+ def apply_action: (Array[search_entry] results, Array[[ Configuration, IR::parser_action? ]] queue, Configuration current, IR::parser_action action, Integer token_id) -> void
105
+
106
+ # @rbs (Configuration current, Integer state_id, Integer token_id) -> Configuration
107
+ def shift: (Configuration current, Integer state_id, Integer token_id) -> Configuration
108
+
109
+ # @rbs (Configuration current, Integer production_id) -> Configuration?
110
+ def reduce: (Configuration current, Integer production_id) -> Configuration?
111
+
112
+ # @rbs (Array[Integer] states, Array[derivation_node] nodes) -> Configuration
113
+ def configuration: (Array[Integer] states, Array[derivation_node] nodes) -> Configuration
114
+
115
+ # @rbs () -> Integer
116
+ def required_lookahead: () -> Integer
117
+
118
+ # @rbs (Integer id) -> String
119
+ def symbol_name: (Integer id) -> String
120
+
121
+ # @rbs (Configuration left, Configuration right) -> [Array[Integer], Array[Integer]]
122
+ def pair_key: (Configuration left, Configuration right) -> [ Array[Integer], Array[Integer] ]
123
+
124
+ # @rbs () -> Integer
125
+ def count_configuration: () -> Integer
126
+
127
+ # @rbs () -> bool
128
+ def exhausted?: () -> bool
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,29 @@
1
+ # Generated from lib/ibex/lalr/conflict_search_limits.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Validates search limits and measures sentences against the token budget.
6
+ module ConflictSearchLimits
7
+ DEFAULT_MAX_TOKENS: Integer
8
+
9
+ DEFAULT_MAX_CONFIGURATIONS: Integer
10
+
11
+ # @rbs (max_tokens: Integer, max_configurations: Integer) -> void
12
+ def self.validate!: (max_tokens: Integer, max_configurations: Integer) -> void
13
+
14
+ # @rbs (Symbol name, Integer value) -> Integer
15
+ def self.validate_limit!: (Symbol name, Integer value) -> Integer
16
+
17
+ private
18
+
19
+ # @rbs (Array[Integer] prefix, Array[Integer] suffix) -> bool
20
+ def within_token_budget?: (Array[Integer] prefix, Array[Integer] suffix) -> bool
21
+
22
+ # @rbs (Array[Integer] prefix, Array[Integer] suffix) -> bool
23
+ def room_for_token?: (Array[Integer] prefix, Array[Integer] suffix) -> bool
24
+
25
+ # @rbs () -> Integer
26
+ def conflict_lookahead_length: () -> Integer
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ # Generated from lib/ibex/lalr/counterexample.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Produces shortest-path conflict witnesses using Automaton IR only.
6
+ class Counterexample
7
+ DEFAULT_MAX_TOKENS: Integer
8
+
9
+ DEFAULT_MAX_CONFIGURATIONS: Integer
10
+
11
+ # @rbs (IR::Automaton automaton, ?max_tokens: Integer, ?max_configurations: Integer) -> void
12
+ def initialize: (IR::Automaton automaton, ?max_tokens: Integer, ?max_configurations: Integer) -> void
13
+
14
+ # @rbs () -> Array[IR::counterexample]
15
+ def all: () -> Array[IR::counterexample]
16
+
17
+ private
18
+
19
+ # @rbs (IR::AutomatonState state, IR::conflict conflict) -> IR::counterexample
20
+ def build_example: (IR::AutomatonState state, IR::conflict conflict) -> IR::counterexample
21
+
22
+ # @rbs (IR::AutomatonState state, IR::conflict conflict, Hash[Symbol, untyped] result) -> IR::counterexample
23
+ def unifying_example: (IR::AutomatonState state, IR::conflict conflict, Hash[Symbol, untyped] result) -> IR::counterexample
24
+
25
+ # @rbs (IR::AutomatonState state, IR::conflict conflict) -> IR::counterexample
26
+ def reachability_example: (IR::AutomatonState state, IR::conflict conflict) -> IR::counterexample
27
+
28
+ # @rbs (Integer target) -> Array[Integer]
29
+ def shortest_state_path: (Integer target) -> Array[Integer]
30
+
31
+ # @rbs () -> Hash[Integer, Array[Integer]]
32
+ def compute_shortest_yields: () -> Hash[Integer, Array[Integer]]
33
+
34
+ # @rbs (Array[Integer] candidate, Array[Integer]? current) -> bool
35
+ def better_yield?: (Array[Integer] candidate, Array[Integer]? current) -> bool
36
+
37
+ # @rbs (IR::conflict conflict) -> Array[IR::interpretation]
38
+ def interpretations: (IR::conflict conflict) -> Array[IR::interpretation]
39
+
40
+ # @rbs (IR::shift_reduce_conflict conflict) -> IR::interpretation
41
+ def shift_interpretation: (IR::shift_reduce_conflict conflict) -> IR::interpretation
42
+
43
+ # @rbs (Integer production_id) -> IR::interpretation
44
+ def reduce_interpretation: (Integer production_id) -> IR::interpretation
45
+
46
+ # @rbs (Array[Integer] symbol_ids) -> Array[String]
47
+ def names: (Array[Integer] symbol_ids) -> Array[String]
48
+
49
+ # @rbs (Integer id) -> String
50
+ def symbol_name: (Integer id) -> String
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ # Generated from lib/ibex/lalr/default_reductions.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ # Selects size-reducing default actions without changing any terminal cell.
6
+ module DefaultReductions
7
+ private def select_default: (Hash[Integer, IR::parser_action] actions, Array[Integer] terminal_ids) -> IR::parser_action?
8
+
9
+ private def self.select_default: (Hash[Integer, IR::parser_action] actions, Array[Integer] terminal_ids) -> IR::parser_action?
10
+
11
+ ERROR_ACTION: IR::error_action
12
+
13
+ # @rbs (Array[IR::AutomatonState] states, terminal_ids: Array[Integer]) -> Array[IR::AutomatonState]
14
+ def self?.apply: (Array[IR::AutomatonState] states, terminal_ids: Array[Integer]) -> Array[IR::AutomatonState]
15
+
16
+ # @rbs (IR::AutomatonState state, terminal_ids: Array[Integer]) -> IR::AutomatonState
17
+ def self?.optimize: (IR::AutomatonState state, terminal_ids: Array[Integer]) -> IR::AutomatonState
18
+ end
19
+ end
20
+ end
data/sig/ibex/lalr.rbs ADDED
@@ -0,0 +1,23 @@
1
+ # Generated from lib/ibex/lalr.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module LALR
5
+ type lr_item = [ Integer, Integer, Integer ]
6
+
7
+ type item_core = [ Integer, Integer ]
8
+
9
+ type item_set = Set[lr_item]
10
+
11
+ type packed_items = Hash[item_core, Set[Integer]]
12
+
13
+ type transitions = Array[Hash[Integer, Integer]]
14
+
15
+ type derivation_node = Hash[Symbol, untyped]
16
+
17
+ type search_status = :conflict | :shifted | :accepted
18
+
19
+ type search_entry = [ search_status, ConflictSearch::Configuration ]
20
+
21
+ type search_result = { sentence_ids: Array[Integer], lookahead_index: Integer, interpretations: Array[IR::interpretation] }
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # Generated from lib/ibex/normalize/declarations.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ # Declaration extraction used by Normalizer.
5
+ module NormalizeDeclarations
6
+ private
7
+
8
+ # @rbs () -> void
9
+ def read_declarations: () -> void
10
+
11
+ # @rbs (Frontend::AST::declaration declaration) -> void
12
+ def read_declaration: (Frontend::AST::declaration declaration) -> void
13
+
14
+ # @rbs (Frontend::AST::Precedence declaration) -> void
15
+ def read_precedence: (Frontend::AST::Precedence declaration) -> void
16
+
17
+ # @rbs (String name, Frontend::Location location) -> void
18
+ def read_option: (String name, Frontend::Location location) -> void
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ # Generated from lib/ibex/normalize/diagnostics.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ # Static grammar diagnostics used by Normalizer.
5
+ module NormalizeDiagnostics
6
+ private
7
+
8
+ # @rbs () -> void
9
+ def validate_grammar: () -> void
10
+
11
+ # @rbs () -> void
12
+ def warn_duplicate_productions: () -> void
13
+
14
+ # @rbs () -> void
15
+ def warn_unreachable_nonterminals: () -> void
16
+
17
+ # @rbs () -> Set[Integer]
18
+ def reachable_symbol_ids: () -> Set[Integer]
19
+
20
+ # @rbs () -> void
21
+ def warn_unused_terminals: () -> void
22
+
23
+ # @rbs () -> void
24
+ def warn_empty_language: () -> void
25
+
26
+ # @rbs () -> Set[Integer]
27
+ def productive_terminal_ids: () -> Set[Integer]
28
+
29
+ # @rbs (IR::GrammarSymbol grammar_symbol) -> bool
30
+ def productive_terminal?: (IR::GrammarSymbol grammar_symbol) -> bool
31
+ end
32
+ end
@@ -0,0 +1,66 @@
1
+ # Generated from lib/ibex/normalize/expander.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ # Production and EBNF expansion used by Normalizer.
5
+ module NormalizeExpander
6
+ private
7
+
8
+ # @rbs () -> void
9
+ def normalize_user_productions: () -> void
10
+
11
+ # @rbs (Frontend::AST::Rule rule, Frontend::AST::Alternative alternative) -> void
12
+ def normalize_alternative: (Frontend::AST::Rule rule, Frontend::AST::Alternative alternative) -> void
13
+
14
+ # @rbs (Frontend::AST::item item) -> String
15
+ def normalize_item: (Frontend::AST::item item) -> String
16
+
17
+ # @rbs (Frontend::AST::InlineAction item, Integer context_length, Array[IR::named_ref] named_refs) -> String
18
+ def expand_inline_action: (Frontend::AST::InlineAction item, Integer context_length, Array[IR::named_ref] named_refs) -> String
19
+
20
+ # @rbs (Frontend::AST::Optional item) -> String
21
+ def expand_optional: (Frontend::AST::Optional item) -> String
22
+
23
+ # @rbs (Frontend::AST::Star item) -> String
24
+ def expand_star: (Frontend::AST::Star item) -> String
25
+
26
+ # @rbs (Frontend::AST::Plus item) -> String
27
+ def expand_plus: (Frontend::AST::Plus item) -> String
28
+
29
+ # @rbs (Frontend::AST::SeparatedList item) -> String
30
+ def expand_separated_list: (Frontend::AST::SeparatedList item) -> String
31
+
32
+ # @rbs (Frontend::AST::Group item) -> String
33
+ def expand_group: (Frontend::AST::Group item) -> String
34
+
35
+ # @rbs (Integer length) -> String
36
+ def group_value_expression: (Integer length) -> String
37
+
38
+ # @rbs (Frontend::AST::Group group) -> void
39
+ def reject_group_named_references: (Frontend::AST::Group group) -> void
40
+
41
+ # @rbs (Frontend::AST::item item) -> Frontend::AST::SymbolReference?
42
+ def named_reference_in: (Frontend::AST::item item) -> Frontend::AST::SymbolReference?
43
+
44
+ # @rbs (String kind, Frontend::Location location) -> String
45
+ def new_helper: (String kind, Frontend::Location location) -> String
46
+
47
+ # @rbs (String expression, Frontend::Location location) -> IR::Action
48
+ def synthetic_action: (String expression, Frontend::Location location) -> IR::Action
49
+
50
+ # @rbs (Symbol kind, Frontend::AST::item item) -> Hash[Symbol, untyped]
51
+ def synthetic_origin: (Symbol kind, Frontend::AST::item item) -> Hash[Symbol, untyped]
52
+
53
+ # @rbs (Frontend::AST::InlineAction? action, Array[IR::named_ref] named_refs) -> IR::Action?
54
+ def normalize_action: (Frontend::AST::InlineAction? action, Array[IR::named_ref] named_refs) -> IR::Action?
55
+
56
+ # @rbs (Frontend::AST::item item, Array[IR::named_ref] refs, Integer index) -> void
57
+ def add_named_reference: (Frontend::AST::item item, Array[IR::named_ref] refs, Integer index) -> void
58
+
59
+ # @rbs (Frontend::AST::item item) -> Frontend::AST::SymbolReference?
60
+ def unwrap_reference: (Frontend::AST::item item) -> Frontend::AST::SymbolReference?
61
+
62
+ # @rbs (String lhs_name, Array[String] rhs_names, IR::Action? action, String? precedence_name,
63
+ # Hash[Symbol, untyped] origin) -> void
64
+ def add_production: (String lhs_name, Array[String] rhs_names, IR::Action? action, String? precedence_name, Hash[Symbol, untyped] origin) -> void
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ # Generated from lib/ibex/normalize/expression.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ # Deterministically renders frontend EBNF items for production origin metadata.
5
+ module NormalizeExpression
6
+ private def render_reference: (Frontend::AST::SymbolReference item) -> String
7
+
8
+ private def self.render_reference: (Frontend::AST::SymbolReference item) -> String
9
+
10
+ private def render_group: (Frontend::AST::Group item) -> String
11
+
12
+ private def self.render_group: (Frontend::AST::Group item) -> String
13
+
14
+ private def render_separated_list: (Frontend::AST::SeparatedList item) -> String
15
+
16
+ private def self.render_separated_list: (Frontend::AST::SeparatedList item) -> String
17
+
18
+ # @rbs (Frontend::AST::item item) -> String
19
+ def self?.render: (Frontend::AST::item item) -> String
20
+ end
21
+ end
@@ -0,0 +1,96 @@
1
+ # Generated from lib/ibex/normalize.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ # Converts a frontend AST into immutable Grammar IR.
5
+ class Normalizer
6
+ include NormalizeDeclarations
7
+
8
+ include NormalizeExpander
9
+
10
+ include NormalizeDiagnostics
11
+
12
+ RESERVED_NAMES: Array[String]
13
+
14
+ @ast: Frontend::AST::Root
15
+
16
+ @mode: Symbol
17
+
18
+ @symbols: Array[IR::GrammarSymbol]
19
+
20
+ @symbols_by_name: Hash[String, IR::GrammarSymbol]
21
+
22
+ @productions: Array[IR::Production]
23
+
24
+ @warnings: Array[IR::grammar_warning]
25
+
26
+ @helper_sequence: Integer
27
+
28
+ @declared_tokens: Hash[String, IR::location]
29
+
30
+ @precedence: Hash[String, IR::precedence]
31
+
32
+ @precedence_locations: Hash[String, IR::location]
33
+
34
+ @options: IR::grammar_options
35
+
36
+ @expected_conflicts: Integer
37
+
38
+ @conversions: Hash[String, String]
39
+
40
+ @explicit_start: String?
41
+
42
+ @start_name: String
43
+
44
+ @start_location: Frontend::Location?
45
+
46
+ # @rbs (Frontend::AST::Root ast, ?mode: Symbol | String) -> void
47
+ def initialize: (Frontend::AST::Root ast, ?mode: Symbol | String) -> void
48
+
49
+ # @rbs () -> IR::Grammar
50
+ def normalize: () -> IR::Grammar
51
+
52
+ private
53
+
54
+ # @rbs () -> void
55
+ def intern_reserved_symbols: () -> void
56
+
57
+ # @rbs () -> void
58
+ def intern_declared_terminals: () -> void
59
+
60
+ # @rbs () -> void
61
+ def intern_user_nonterminals: () -> void
62
+
63
+ # @rbs (String name, Symbol kind, ?reserved: bool, ?location: IR::location?) -> IR::GrammarSymbol
64
+ def intern: (String name, Symbol kind, ?reserved: bool, ?location: IR::location?) -> IR::GrammarSymbol
65
+
66
+ # @rbs (String name) -> IR::GrammarSymbol?
67
+ def symbol: (String name) -> IR::GrammarSymbol?
68
+
69
+ # @rbs (String name) -> IR::GrammarSymbol
70
+ def required_symbol: (String name) -> IR::GrammarSymbol
71
+
72
+ # @rbs (Frontend::AST::SymbolReference reference) -> IR::GrammarSymbol
73
+ def symbol_for_reference: (Frontend::AST::SymbolReference reference) -> IR::GrammarSymbol
74
+
75
+ # @rbs (String name) -> bool
76
+ def nonterminal_name?: (String name) -> bool
77
+
78
+ # @rbs (Frontend::AST::SymbolReference reference) -> bot
79
+ def undefined_nonterminal: (Frontend::AST::SymbolReference reference) -> bot
80
+
81
+ # @rbs (Frontend::AST::SymbolReference reference) -> void
82
+ def warn_undeclared_terminal: (Frontend::AST::SymbolReference reference) -> void
83
+
84
+ # @rbs () -> Hash[String, String]
85
+ def normalized_user_code: () -> Hash[String, String]
86
+
87
+ # @rbs () -> IR::user_code_chunks
88
+ def normalized_user_code_chunks: () -> IR::user_code_chunks
89
+
90
+ # @rbs (Frontend::Location location, String message) -> bot
91
+ def fail_at: (Frontend::Location location, String message) -> bot
92
+
93
+ # @rbs (IR::location? location, String message) -> bot
94
+ def fail_hash: (IR::location? location, String message) -> bot
95
+ end
96
+ end