ibex 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +247 -104
- data/docs/architecture.md +322 -28
- data/docs/cst-migration.md +107 -0
- data/docs/cst.md +213 -0
- data/docs/development.md +129 -0
- data/docs/editor-setup.md +25 -0
- data/docs/error-ux.md +60 -0
- data/docs/grammar-reference.md +458 -18
- data/docs/lexer-migration.md +51 -0
- data/docs/racc-migration.md +34 -6
- data/docs/release-readiness.md +163 -0
- data/docs/stability.md +124 -0
- data/examples/README.md +60 -0
- data/examples/calculator.y +44 -0
- data/examples/csv.y +32 -0
- data/examples/ini.y +70 -0
- data/examples/json.y +48 -0
- data/examples/tiny_language.y +75 -0
- data/lib/ibex/analysis/sets.rb +5 -4
- data/lib/ibex/artifact_set.rb +63 -0
- data/lib/ibex/cli/ambiguity.rb +66 -0
- data/lib/ibex/cli/counterexample_options.rb +6 -2
- data/lib/ibex/cli/coverage.rb +173 -0
- data/lib/ibex/cli/debug.rb +106 -0
- data/lib/ibex/cli/diagnostics.rb +116 -0
- data/lib/ibex/cli/documentation.rb +67 -0
- data/lib/ibex/cli/error_messages.rb +177 -0
- data/lib/ibex/cli/explain.rb +76 -0
- data/lib/ibex/cli/formatting.rb +386 -0
- data/lib/ibex/cli/generation_artifacts.rb +138 -0
- data/lib/ibex/cli/generation_error_messages.rb +39 -0
- data/lib/ibex/cli/grammar_tests.rb +122 -0
- data/lib/ibex/cli/ir_tools.rb +184 -0
- data/lib/ibex/cli/lsp.rb +33 -0
- data/lib/ibex/cli/outputs.rb +91 -8
- data/lib/ibex/cli/racc_migration.rb +87 -0
- data/lib/ibex/cli/samples.rb +92 -0
- data/lib/ibex/cli/watch.rb +103 -0
- data/lib/ibex/cli.rb +506 -37
- data/lib/ibex/codegen/action_locations.rb +103 -0
- data/lib/ibex/codegen/action_method_source.rb +210 -0
- data/lib/ibex/codegen/action_source.rb +118 -0
- data/lib/ibex/codegen/ambiguity.rb +173 -0
- data/lib/ibex/codegen/cst_metadata.rb +171 -0
- data/lib/ibex/codegen/documentation.rb +170 -0
- data/lib/ibex/codegen/explain.rb +312 -0
- data/lib/ibex/codegen/generated_action_abi.rb +288 -0
- data/lib/ibex/codegen/html.rb +94 -10
- data/lib/ibex/codegen/mermaid.rb +43 -0
- data/lib/ibex/codegen/railroad.rb +197 -0
- data/lib/ibex/codegen/railroad_documentation.rb +59 -0
- data/lib/ibex/codegen/rbs.rb +323 -2
- data/lib/ibex/codegen/report.rb +46 -6
- data/lib/ibex/codegen/ruby.rb +334 -59
- data/lib/ibex/codegen/ruby_actions.rb +143 -0
- data/lib/ibex/codegen/ruby_ast.rb +121 -0
- data/lib/ibex/codegen/ruby_error_messages.rb +28 -0
- data/lib/ibex/codegen/ruby_lexer.rb +83 -0
- data/lib/ibex/codegen/ruby_syntax.rb +90 -0
- data/lib/ibex/codegen/ruby_table_metadata.rb +57 -0
- data/lib/ibex/codegen/ruby_value_printers.rb +56 -0
- data/lib/ibex/codegen/symbol_labels.rb +1 -1
- data/lib/ibex/coverage/collector.rb +188 -0
- data/lib/ibex/coverage/event_stream.rb +97 -0
- data/lib/ibex/coverage/report.rb +259 -0
- data/lib/ibex/coverage/runtime_event_validator.rb +160 -0
- data/lib/ibex/coverage.rb +13 -0
- data/lib/ibex/error_messages/parser.rb +159 -0
- data/lib/ibex/error_messages/parser_v2.rb +198 -0
- data/lib/ibex/error_messages/renderer.rb +65 -0
- data/lib/ibex/error_messages/sentence_search.rb +196 -0
- data/lib/ibex/error_messages/update.rb +169 -0
- data/lib/ibex/error_messages.rb +165 -0
- data/lib/ibex/frontend/ast.rb +145 -6
- data/lib/ibex/frontend/bootstrap_parser.rb +47 -4
- data/lib/ibex/frontend/diagnostic.rb +81 -0
- data/lib/ibex/frontend/diagnostic_recovery.rb +268 -0
- data/lib/ibex/frontend/dsl.rb +66 -7
- data/lib/ibex/frontend/formatter.rb +407 -0
- data/lib/ibex/frontend/generated_parser.rb +614 -190
- data/lib/ibex/frontend/generated_parser_base.rb +164 -30
- data/lib/ibex/frontend/generated_parser_includes.rb +61 -0
- data/lib/ibex/frontend/generated_parser_metadata.rb +61 -0
- data/lib/ibex/frontend/generated_parser_parameters.rb +60 -0
- data/lib/ibex/frontend/generation.rb +33 -0
- data/lib/ibex/frontend/lexer.rb +162 -10
- data/lib/ibex/frontend/lexer_recovery.rb +84 -0
- data/lib/ibex/frontend/parser/declarations.rb +247 -11
- data/lib/ibex/frontend/parser/parameters.rb +82 -0
- data/lib/ibex/frontend/parser/rules.rb +43 -6
- data/lib/ibex/frontend/parser.rb +182 -4
- data/lib/ibex/frontend/regenerator.rb +26 -1
- data/lib/ibex/frontend/resolution.rb +69 -0
- data/lib/ibex/frontend/resolver.rb +217 -0
- data/lib/ibex/frontend/rule_documentation.rb +103 -0
- data/lib/ibex/frontend/source_cursor.rb +132 -8
- data/lib/ibex/frontend/source_document.rb +229 -0
- data/lib/ibex/frontend/source_loader.rb +150 -0
- data/lib/ibex/frontend/source_span.rb +81 -0
- data/lib/ibex/frontend/token_adapter/declaration_document_state.rb +47 -0
- data/lib/ibex/frontend/token_adapter/declaration_lexer_state.rb +83 -0
- data/lib/ibex/frontend/token_adapter/declaration_state.rb +216 -26
- data/lib/ibex/frontend/token_adapter/delimiter_tracker.rb +8 -2
- data/lib/ibex/frontend/token_adapter/rule_state.rb +60 -2
- data/lib/ibex/frontend/token_adapter.rb +8 -3
- data/lib/ibex/frontend.rb +13 -2
- data/lib/ibex/generation_input.rb +57 -0
- data/lib/ibex/generation_manifest.rb +200 -0
- data/lib/ibex/generation_transaction.rb +261 -0
- data/lib/ibex/generation_transaction_recovery.rb +109 -0
- data/lib/ibex/generation_transaction_validation.rb +196 -0
- data/lib/ibex/grammar_tests.rb +206 -0
- data/lib/ibex/ir/automaton_ir.rb +38 -5
- data/lib/ibex/ir/grammar_ir.rb +137 -24
- data/lib/ibex/ir/lexer_ir.rb +76 -0
- data/lib/ibex/ir/migration.rb +120 -0
- data/lib/ibex/ir/serialize.rb +110 -19
- data/lib/ibex/ir/validator/automaton.rb +345 -0
- data/lib/ibex/ir/validator/base.rb +129 -0
- data/lib/ibex/ir/validator/grammar.rb +604 -0
- data/lib/ibex/ir/validator/lexer.rb +113 -0
- data/lib/ibex/ir/validator.rb +62 -0
- data/lib/ibex/ir.rb +57 -4
- data/lib/ibex/lalr/build_metrics.rb +23 -0
- data/lib/ibex/lalr/builder.rb +379 -52
- data/lib/ibex/lalr/conflict.rb +1 -0
- data/lib/ibex/lalr/conflict_search.rb +11 -5
- data/lib/ibex/lalr/counterexample.rb +20 -5
- data/lib/ibex/lalr/direct_lookaheads.rb +236 -0
- data/lib/ibex/lalr/ielr_partition.rb +152 -0
- data/lib/ibex/lalr/on_error_reductions.rb +74 -0
- data/lib/ibex/lalr.rb +7 -0
- data/lib/ibex/location.rb +129 -0
- data/lib/ibex/lsp/document_handlers.rb +66 -0
- data/lib/ibex/lsp/document_store.rb +264 -0
- data/lib/ibex/lsp/document_store_diagnostics.rb +44 -0
- data/lib/ibex/lsp/document_store_validation.rb +61 -0
- data/lib/ibex/lsp/initialization_handlers.rb +78 -0
- data/lib/ibex/lsp/navigation_handlers.rb +56 -0
- data/lib/ibex/lsp/position_codec.rb +109 -0
- data/lib/ibex/lsp/protocol_error.rb +33 -0
- data/lib/ibex/lsp/request_handlers.rb +45 -0
- data/lib/ibex/lsp/request_support.rb +87 -0
- data/lib/ibex/lsp/server.rb +146 -0
- data/lib/ibex/lsp/symbol_index.rb +241 -0
- data/lib/ibex/lsp/symbol_index_builder.rb +267 -0
- data/lib/ibex/lsp/symbol_index_precedence_references.rb +44 -0
- data/lib/ibex/lsp/symbol_index_source_queries.rb +61 -0
- data/lib/ibex/lsp/symbol_occurrence.rb +17 -0
- data/lib/ibex/lsp/transport.rb +118 -0
- data/lib/ibex/lsp/workspace.rb +127 -0
- data/lib/ibex/lsp/workspace_analyzer.rb +199 -0
- data/lib/ibex/lsp.rb +32 -0
- data/lib/ibex/normalize/declarations.rb +140 -7
- data/lib/ibex/normalize/diagnostics.rb +50 -5
- data/lib/ibex/normalize/expander.rb +59 -55
- data/lib/ibex/normalize/expression.rb +60 -39
- data/lib/ibex/normalize/inline_expansion.rb +414 -0
- data/lib/ibex/normalize/inline_validation.rb +174 -0
- data/lib/ibex/normalize/lexer.rb +131 -0
- data/lib/ibex/normalize/named_references.rb +60 -0
- data/lib/ibex/normalize/nodes.rb +46 -0
- data/lib/ibex/normalize/parameter_ebnf_lowering.rb +69 -0
- data/lib/ibex/normalize/parameter_lowering.rb +126 -0
- data/lib/ibex/normalize/parameter_substitution.rb +125 -0
- data/lib/ibex/normalize/parameter_validation.rb +140 -0
- data/lib/ibex/normalize/parameters.rb +199 -0
- data/lib/ibex/normalize/recovery_declarations.rb +84 -0
- data/lib/ibex/normalize.rb +179 -14
- data/lib/ibex/racc_migration/checker.rb +122 -0
- data/lib/ibex/racc_migration/harness.rb +177 -0
- data/lib/ibex/racc_migration/report.rb +94 -0
- data/lib/ibex/racc_migration.rb +12 -0
- data/lib/ibex/rake_task.rb +116 -0
- data/lib/ibex/samples.rb +186 -0
- data/lib/ibex/table_simulation/result.rb +51 -0
- data/lib/ibex/table_simulation/simulator.rb +253 -0
- data/lib/ibex/table_simulation/step.rb +60 -0
- data/lib/ibex/table_simulation/text.rb +31 -0
- data/lib/ibex/table_simulation.rb +13 -0
- data/lib/ibex/tables.rb +9 -70
- data/lib/ibex/version.rb +1 -1
- data/lib/ibex/watch/runner.rb +172 -0
- data/lib/ibex/watch/source_snapshot.rb +93 -0
- data/lib/ibex/watch.rb +11 -0
- data/lib/ibex.rb +25 -1
- data/schema/automaton-ir-v1.schema.json +401 -0
- data/schema/automaton-ir-v2.schema.json +58 -0
- data/schema/benchmark-v1.schema.json +212 -0
- data/schema/benchmark-v2.schema.json +61 -0
- data/schema/cst-v1.json +170 -0
- data/schema/error-ux-v1.schema.json +258 -0
- data/schema/explain-v1.schema.json +433 -0
- data/schema/frontend-diagnostics-v1.schema.json +154 -0
- data/schema/generation-manifest-v1.schema.json +115 -0
- data/schema/grammar-ir-v1.schema.json +426 -0
- data/schema/grammar-ir-v2.schema.json +779 -0
- data/schema/lexer-ir-v1.schema.json +215 -0
- data/schema/migration-check-v1.schema.json +60 -0
- data/schema/performance-comparison-v1.schema.json +395 -0
- data/schema/public-performance-comparison-v1.schema.json +506 -0
- data/schema/public-performance-profile-v1.schema.json +360 -0
- data/schema/runtime-coverage-v1.schema.json +86 -0
- data/schema/runtime-event-v1.schema.json +308 -0
- data/schema/table-simulation-v1.schema.json +70 -0
- data/sig/ibex/artifact_set.rbs +37 -0
- data/sig/ibex/cli/ambiguity.rbs +22 -0
- data/sig/ibex/cli/counterexample_options.rbs +2 -0
- data/sig/ibex/cli/coverage.rbs +53 -0
- data/sig/ibex/cli/debug.rbs +28 -0
- data/sig/ibex/cli/diagnostics.rbs +38 -0
- data/sig/ibex/cli/documentation.rbs +25 -0
- data/sig/ibex/cli/error_messages.rbs +57 -0
- data/sig/ibex/cli/explain.rbs +25 -0
- data/sig/ibex/cli/formatting.rbs +103 -0
- data/sig/ibex/cli/generation_artifacts.rbs +50 -0
- data/sig/ibex/cli/generation_error_messages.rbs +19 -0
- data/sig/ibex/cli/grammar_tests.rbs +36 -0
- data/sig/ibex/cli/ir_tools.rbs +51 -0
- data/sig/ibex/cli/lsp.rbs +14 -0
- data/sig/ibex/cli/outputs.rbs +17 -0
- data/sig/ibex/cli/racc_migration.rbs +30 -0
- data/sig/ibex/cli/samples.rbs +30 -0
- data/sig/ibex/cli/watch.rbs +43 -0
- data/sig/ibex/cli.rbs +104 -5
- data/sig/ibex/codegen/action_locations.rbs +45 -0
- data/sig/ibex/codegen/action_method_source.rbs +65 -0
- data/sig/ibex/codegen/action_source.rbs +50 -0
- data/sig/ibex/codegen/ambiguity.rbs +60 -0
- data/sig/ibex/codegen/cst_metadata.rbs +59 -0
- data/sig/ibex/codegen/documentation.rbs +50 -0
- data/sig/ibex/codegen/explain.rbs +85 -0
- data/sig/ibex/codegen/generated_action_abi.rbs +101 -0
- data/sig/ibex/codegen/html.rbs +18 -2
- data/sig/ibex/codegen/mermaid.rbs +16 -0
- data/sig/ibex/codegen/railroad.rbs +82 -0
- data/sig/ibex/codegen/railroad_documentation.rbs +31 -0
- data/sig/ibex/codegen/rbs.rbs +84 -4
- data/sig/ibex/codegen/report.rbs +8 -0
- data/sig/ibex/codegen/ruby.rbs +97 -23
- data/sig/ibex/codegen/ruby_actions.rbs +54 -0
- data/sig/ibex/codegen/ruby_ast.rbs +34 -0
- data/sig/ibex/codegen/ruby_error_messages.rbs +16 -0
- data/sig/ibex/codegen/ruby_lexer.rbs +25 -0
- data/sig/ibex/codegen/ruby_syntax.rbs +25 -0
- data/sig/ibex/codegen/ruby_table_metadata.rbs +26 -0
- data/sig/ibex/codegen/ruby_value_printers.rbs +28 -0
- data/sig/ibex/coverage/collector.rbs +76 -0
- data/sig/ibex/coverage/event_stream.rbs +42 -0
- data/sig/ibex/coverage/report.rbs +100 -0
- data/sig/ibex/coverage/runtime_event_validator.rbs +68 -0
- data/sig/ibex/coverage.rbs +7 -0
- data/sig/ibex/error_messages/parser.rbs +58 -0
- data/sig/ibex/error_messages/parser_v2.rbs +67 -0
- data/sig/ibex/error_messages/renderer.rbs +23 -0
- data/sig/ibex/error_messages/sentence_search.rbs +80 -0
- data/sig/ibex/error_messages/update.rbs +43 -0
- data/sig/ibex/error_messages.rbs +85 -0
- data/sig/ibex/frontend/ast.rbs +208 -19
- data/sig/ibex/frontend/bootstrap_parser.rbs +11 -0
- data/sig/ibex/frontend/diagnostic.rbs +53 -0
- data/sig/ibex/frontend/diagnostic_recovery.rbs +98 -0
- data/sig/ibex/frontend/dsl.rbs +33 -4
- data/sig/ibex/frontend/formatter.rbs +135 -0
- data/sig/ibex/frontend/generated_parser.rbs +218 -68
- data/sig/ibex/frontend/generated_parser_base.rbs +61 -10
- data/sig/ibex/frontend/generated_parser_includes.rbs +23 -0
- data/sig/ibex/frontend/generated_parser_metadata.rbs +23 -0
- data/sig/ibex/frontend/generated_parser_parameters.rbs +24 -0
- data/sig/ibex/frontend/generation.rbs +6 -0
- data/sig/ibex/frontend/lexer.rbs +49 -2
- data/sig/ibex/frontend/lexer_recovery.rbs +25 -0
- data/sig/ibex/frontend/parser/declarations.rbs +54 -0
- data/sig/ibex/frontend/parser/parameters.rbs +28 -0
- data/sig/ibex/frontend/parser/rules.rbs +3 -0
- data/sig/ibex/frontend/parser.rbs +66 -0
- data/sig/ibex/frontend/regenerator.rbs +11 -0
- data/sig/ibex/frontend/resolution.rbs +33 -0
- data/sig/ibex/frontend/resolver.rbs +91 -0
- data/sig/ibex/frontend/rule_documentation.rbs +42 -0
- data/sig/ibex/frontend/source_cursor.rbs +36 -3
- data/sig/ibex/frontend/source_document.rbs +119 -0
- data/sig/ibex/frontend/source_loader.rbs +66 -0
- data/sig/ibex/frontend/source_span.rbs +53 -0
- data/sig/ibex/frontend/token_adapter/declaration_document_state.rbs +21 -0
- data/sig/ibex/frontend/token_adapter/declaration_lexer_state.rbs +27 -0
- data/sig/ibex/frontend/token_adapter/declaration_state.rbs +73 -5
- data/sig/ibex/frontend/token_adapter/rule_state.rbs +20 -0
- data/sig/ibex/frontend/token_adapter.rbs +5 -2
- data/sig/ibex/frontend.rbs +1 -1
- data/sig/ibex/generation_input.rbs +37 -0
- data/sig/ibex/generation_manifest.rbs +67 -0
- data/sig/ibex/generation_transaction.rbs +82 -0
- data/sig/ibex/generation_transaction_recovery.rbs +36 -0
- data/sig/ibex/generation_transaction_validation.rbs +65 -0
- data/sig/ibex/grammar_tests.rbs +93 -0
- data/sig/ibex/ir/automaton_ir.rbs +8 -2
- data/sig/ibex/ir/grammar_ir.rbs +75 -15
- data/sig/ibex/ir/lexer_ir.rbs +57 -0
- data/sig/ibex/ir/migration.rbs +34 -0
- data/sig/ibex/ir/serialize.rbs +23 -6
- data/sig/ibex/ir/validator/automaton.rbs +109 -0
- data/sig/ibex/ir/validator/base.rbs +65 -0
- data/sig/ibex/ir/validator/grammar.rbs +184 -0
- data/sig/ibex/ir/validator/lexer.rbs +37 -0
- data/sig/ibex/ir/validator.rbs +16 -0
- data/sig/ibex/ir.rbs +38 -4
- data/sig/ibex/lalr/build_metrics.rbs +20 -0
- data/sig/ibex/lalr/builder.rbs +95 -15
- data/sig/ibex/lalr/conflict_search.rbs +7 -3
- data/sig/ibex/lalr/counterexample.rbs +5 -2
- data/sig/ibex/lalr/direct_lookaheads.rbs +86 -0
- data/sig/ibex/lalr/ielr_partition.rbs +59 -0
- data/sig/ibex/lalr/on_error_reductions.rbs +22 -0
- data/sig/ibex/lalr.rbs +6 -0
- data/sig/ibex/location.rbs +67 -0
- data/sig/ibex/lsp/document_handlers.rbs +24 -0
- data/sig/ibex/lsp/document_store.rbs +94 -0
- data/sig/ibex/lsp/document_store_diagnostics.rbs +20 -0
- data/sig/ibex/lsp/document_store_validation.rbs +26 -0
- data/sig/ibex/lsp/initialization_handlers.rbs +30 -0
- data/sig/ibex/lsp/navigation_handlers.rbs +30 -0
- data/sig/ibex/lsp/position_codec.rbs +40 -0
- data/sig/ibex/lsp/protocol_error.rbs +32 -0
- data/sig/ibex/lsp/request_handlers.rbs +26 -0
- data/sig/ibex/lsp/request_support.rbs +40 -0
- data/sig/ibex/lsp/server.rbs +55 -0
- data/sig/ibex/lsp/symbol_index.rbs +78 -0
- data/sig/ibex/lsp/symbol_index_builder.rbs +87 -0
- data/sig/ibex/lsp/symbol_index_precedence_references.rbs +18 -0
- data/sig/ibex/lsp/symbol_index_source_queries.rbs +26 -0
- data/sig/ibex/lsp/symbol_occurrence.rbs +25 -0
- data/sig/ibex/lsp/transport.rbs +35 -0
- data/sig/ibex/lsp/workspace.rbs +41 -0
- data/sig/ibex/lsp/workspace_analyzer.rbs +69 -0
- data/sig/ibex/lsp.rbs +7 -0
- data/sig/ibex/normalize/declarations.rbs +31 -0
- data/sig/ibex/normalize/diagnostics.rbs +9 -0
- data/sig/ibex/normalize/expander.rbs +20 -14
- data/sig/ibex/normalize/expression.rbs +10 -10
- data/sig/ibex/normalize/inline_expansion.rbs +120 -0
- data/sig/ibex/normalize/inline_validation.rbs +40 -0
- data/sig/ibex/normalize/lexer.rbs +37 -0
- data/sig/ibex/normalize/named_references.rbs +20 -0
- data/sig/ibex/normalize/nodes.rbs +14 -0
- data/sig/ibex/normalize/parameter_ebnf_lowering.rbs +32 -0
- data/sig/ibex/normalize/parameter_lowering.rbs +35 -0
- data/sig/ibex/normalize/parameter_substitution.rbs +42 -0
- data/sig/ibex/normalize/parameter_validation.rbs +44 -0
- data/sig/ibex/normalize/parameters.rbs +46 -0
- data/sig/ibex/normalize/recovery_declarations.rbs +24 -0
- data/sig/ibex/normalize.rbs +123 -18
- data/sig/ibex/racc_migration/checker.rbs +36 -0
- data/sig/ibex/racc_migration/harness.rbs +16 -0
- data/sig/ibex/racc_migration/report.rbs +53 -0
- data/sig/ibex/racc_migration.rbs +8 -0
- data/sig/ibex/rake_task.rbs +51 -0
- data/sig/ibex/samples.rbs +51 -0
- data/sig/ibex/table_simulation/result.rbs +32 -0
- data/sig/ibex/table_simulation/simulator.rbs +98 -0
- data/sig/ibex/table_simulation/step.rbs +40 -0
- data/sig/ibex/table_simulation/text.rbs +14 -0
- data/sig/ibex/table_simulation.rbs +7 -0
- data/sig/ibex/tables.rbs +0 -26
- data/sig/ibex/watch/runner.rbs +48 -0
- data/sig/ibex/watch/source_snapshot.rbs +42 -0
- data/sig/ibex/watch.rbs +7 -0
- data/sig/ibex.rbs +2 -0
- metadata +301 -16
- data/.rubocop.yml +0 -43
- data/CHANGELOG.md +0 -30
- data/Rakefile +0 -25
- data/Steepfile +0 -10
- data/docs/compat-notes.md +0 -37
- data/docs/lexer-coverage.md +0 -14
- data/docs/phase10-extensions.md +0 -27
- data/gemfiles/Gemfile +0 -7
- data/gemfiles/Gemfile.lock +0 -98
- data/lib/ibex/frontend/grammar.y +0 -156
- data/lib/ibex/runtime/parser.rb +0 -360
- data/lib/ibex/runtime.rb +0 -8
- data/sig/ibex/runtime/parser.rbs +0 -167
- data/sig/ibex/runtime.rbs +0 -6
data/gemfiles/Gemfile.lock
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: https://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
ast (2.4.3)
|
|
5
|
-
concurrent-ruby (1.3.8)
|
|
6
|
-
csv (3.3.5)
|
|
7
|
-
ffi (1.17.4)
|
|
8
|
-
ffi (1.17.4-arm64-darwin)
|
|
9
|
-
fileutils (1.8.0)
|
|
10
|
-
json (2.21.1)
|
|
11
|
-
language_server-protocol (3.17.0.6)
|
|
12
|
-
listen (3.10.0)
|
|
13
|
-
logger
|
|
14
|
-
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
15
|
-
rb-inotify (~> 0.9, >= 0.9.10)
|
|
16
|
-
logger (1.7.0)
|
|
17
|
-
parser (3.3.12.0)
|
|
18
|
-
ast (~> 2.4.1)
|
|
19
|
-
racc
|
|
20
|
-
prism (1.9.0)
|
|
21
|
-
racc (1.8.1)
|
|
22
|
-
rainbow (3.1.1)
|
|
23
|
-
rb-fsevent (0.11.2)
|
|
24
|
-
rb-inotify (0.11.1)
|
|
25
|
-
ffi (~> 1.0)
|
|
26
|
-
rbs (4.0.3)
|
|
27
|
-
logger
|
|
28
|
-
prism (>= 1.6.0)
|
|
29
|
-
tsort
|
|
30
|
-
rbs-inline (0.14.0)
|
|
31
|
-
prism (>= 0.29)
|
|
32
|
-
rbs (~> 4.0)
|
|
33
|
-
securerandom (0.4.1)
|
|
34
|
-
steep (2.0.0)
|
|
35
|
-
concurrent-ruby (>= 1.1.10)
|
|
36
|
-
csv (>= 3.0.9)
|
|
37
|
-
fileutils (>= 1.1.0)
|
|
38
|
-
json (>= 2.1.0)
|
|
39
|
-
language_server-protocol (>= 3.17.0.4, < 4.0)
|
|
40
|
-
listen (~> 3.0)
|
|
41
|
-
logger (>= 1.3.0)
|
|
42
|
-
parser (>= 3.2)
|
|
43
|
-
prism (>= 0.25.0)
|
|
44
|
-
rainbow (>= 2.2.2, < 4.0)
|
|
45
|
-
rbs (~> 4.0)
|
|
46
|
-
securerandom (>= 0.1)
|
|
47
|
-
strscan (>= 1.0.0)
|
|
48
|
-
terminal-table (>= 2, < 5)
|
|
49
|
-
uri (>= 0.12.0)
|
|
50
|
-
strscan (3.1.8)
|
|
51
|
-
terminal-table (4.0.0)
|
|
52
|
-
unicode-display_width (>= 1.1.1, < 4)
|
|
53
|
-
tsort (0.2.0)
|
|
54
|
-
unicode-display_width (3.2.0)
|
|
55
|
-
unicode-emoji (~> 4.1)
|
|
56
|
-
unicode-emoji (4.2.0)
|
|
57
|
-
uri (1.1.1)
|
|
58
|
-
|
|
59
|
-
PLATFORMS
|
|
60
|
-
arm64-darwin-24
|
|
61
|
-
ruby
|
|
62
|
-
|
|
63
|
-
DEPENDENCIES
|
|
64
|
-
rbs (= 4.0.3)
|
|
65
|
-
rbs-inline (= 0.14.0)
|
|
66
|
-
steep (= 2.0.0)
|
|
67
|
-
|
|
68
|
-
CHECKSUMS
|
|
69
|
-
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
70
|
-
bundler (4.0.13) sha256=19f08be7f27022cf0b89f27da0b044ae075e8270a9ef44ad248a932614e1ca3b
|
|
71
|
-
concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1
|
|
72
|
-
csv (3.3.5) sha256=6e5134ac3383ef728b7f02725d9872934f523cb40b961479f69cf3afa6c8e73f
|
|
73
|
-
ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf
|
|
74
|
-
ffi (1.17.4-arm64-darwin) sha256=19071aaf1419251b0a46852abf960e77330a3b334d13a4ab51d58b31a937001b
|
|
75
|
-
fileutils (1.8.0) sha256=8c6b1df54e2540bdb2f39258f08af78853aa70bad52b4d394bbc6424593c6e02
|
|
76
|
-
json (2.21.1) sha256=13a43df75d95641443f5702dff350f237164a9d811ff0f2c2800d4d980220583
|
|
77
|
-
language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
|
|
78
|
-
listen (3.10.0) sha256=c6e182db62143aeccc2e1960033bebe7445309c7272061979bb098d03760c9d2
|
|
79
|
-
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
80
|
-
parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828
|
|
81
|
-
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
|
82
|
-
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
|
|
83
|
-
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
|
84
|
-
rb-fsevent (0.11.2) sha256=43900b972e7301d6570f64b850a5aa67833ee7d87b458ee92805d56b7318aefe
|
|
85
|
-
rb-inotify (0.11.1) sha256=a0a700441239b0ff18eb65e3866236cd78613d6b9f78fea1f9ac47a85e47be6e
|
|
86
|
-
rbs (4.0.3) sha256=5a7bf70e2628549d9a1f44eae447b2cfe55968a9c60cfff52693a4bdcc020e14
|
|
87
|
-
rbs-inline (0.14.0) sha256=eaf47b46690d63acddab1f6804c9cc205a4bc78e637cfc421a0b1239874ef51c
|
|
88
|
-
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
|
|
89
|
-
steep (2.0.0) sha256=6eb0ecc09637bbb54f0a5f2cf63daea6d3208ccace64b4f1107d976333605c30
|
|
90
|
-
strscan (3.1.8) sha256=aae2db611a225559f21ffbb71765c9a4e60fd262534a9ea84f4f11c7f32f679e
|
|
91
|
-
terminal-table (4.0.0) sha256=f504793203f8251b2ea7c7068333053f0beeea26093ec9962e62ea79f94301d2
|
|
92
|
-
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
|
|
93
|
-
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
94
|
-
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
|
|
95
|
-
uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
|
|
96
|
-
|
|
97
|
-
BUNDLED WITH
|
|
98
|
-
4.0.13
|
data/lib/ibex/frontend/grammar.y
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
class Ibex::Frontend::GeneratedParser < Ibex::Frontend::GeneratedParserBase
|
|
2
|
-
token CLASS TOKEN PRECHIGH PRECLOW OPTIONS EXPECT START CONVERT PRAGMA RULE END
|
|
3
|
-
token LEFT RIGHT NONASSOC IDENTIFIER LITERAL INTEGER ACTION USER_CODE LHS
|
|
4
|
-
token SEPARATED_LIST SEPARATED_NONEMPTY_LIST
|
|
5
|
-
rule
|
|
6
|
-
grammar
|
|
7
|
-
: CLASS constant_path superclass pragmas declarations RULE rules END user_code
|
|
8
|
-
{ result = build_root(val[0], val[1], val[2], val[4], val[6], val[8]) }
|
|
9
|
-
|
|
10
|
-
constant_path
|
|
11
|
-
: IDENTIFIER { result = [val[0].value] }
|
|
12
|
-
| constant_path '::' IDENTIFIER { result = val[0] + [val[2].value] }
|
|
13
|
-
|
|
14
|
-
superclass
|
|
15
|
-
: { result = nil }
|
|
16
|
-
| '<' constant_path { result = val[1] }
|
|
17
|
-
|
|
18
|
-
pragmas
|
|
19
|
-
:
|
|
20
|
-
| pragmas PRAGMA IDENTIFIER
|
|
21
|
-
|
|
22
|
-
declarations
|
|
23
|
-
: { result = Array.new(0) }
|
|
24
|
-
| declarations declaration { result = val[0] + [val[1]] }
|
|
25
|
-
|
|
26
|
-
declaration
|
|
27
|
-
: token_declaration { result = val[0] }
|
|
28
|
-
| precedence_declaration { result = val[0] }
|
|
29
|
-
| options_declaration { result = val[0] }
|
|
30
|
-
| expect_declaration { result = val[0] }
|
|
31
|
-
| start_declaration { result = val[0] }
|
|
32
|
-
| convert_declaration { result = val[0] }
|
|
33
|
-
|
|
34
|
-
token_declaration
|
|
35
|
-
: TOKEN symbols { result = build_tokens(val[0], val[1]) }
|
|
36
|
-
|
|
37
|
-
precedence_declaration
|
|
38
|
-
: PRECHIGH precedence_levels PRECLOW { result = build_precedence(val[0], :high_to_low, val[1]) }
|
|
39
|
-
| PRECLOW precedence_levels PRECHIGH { result = build_precedence(val[0], :low_to_high, val[1]) }
|
|
40
|
-
|
|
41
|
-
precedence_levels
|
|
42
|
-
: { result = Array.new(0) }
|
|
43
|
-
| precedence_levels precedence_level { result = val[0] + [val[1]] }
|
|
44
|
-
|
|
45
|
-
precedence_level
|
|
46
|
-
: association symbols { result = build_precedence_level(val[0], val[1]) }
|
|
47
|
-
|
|
48
|
-
association
|
|
49
|
-
: LEFT { result = val[0] }
|
|
50
|
-
| RIGHT { result = val[0] }
|
|
51
|
-
| NONASSOC { result = val[0] }
|
|
52
|
-
|
|
53
|
-
options_declaration
|
|
54
|
-
: OPTIONS identifiers { result = build_options(val[0], val[1]) }
|
|
55
|
-
|
|
56
|
-
expect_declaration
|
|
57
|
-
: EXPECT INTEGER { result = build_expect(val[0], val[1]) }
|
|
58
|
-
|
|
59
|
-
start_declaration
|
|
60
|
-
: START grammar_symbol { result = build_start(val[0], val[1].value) }
|
|
61
|
-
|
|
62
|
-
convert_declaration
|
|
63
|
-
: CONVERT conversions END { result = build_convert(val[0], val[1]) }
|
|
64
|
-
|
|
65
|
-
conversions
|
|
66
|
-
: { result = Array.new(0) }
|
|
67
|
-
| conversions conversion { result = val[0] + [val[1]] }
|
|
68
|
-
|
|
69
|
-
conversion
|
|
70
|
-
: grammar_symbol LITERAL { result = build_conversion(val[0], val[1]) }
|
|
71
|
-
|
|
72
|
-
identifiers
|
|
73
|
-
: { result = Array.new(0) }
|
|
74
|
-
| identifiers IDENTIFIER { result = val[0] + [val[1].value] }
|
|
75
|
-
|
|
76
|
-
symbols
|
|
77
|
-
: { result = Array.new(0) }
|
|
78
|
-
| symbols grammar_symbol { result = val[0] + [val[1].value] }
|
|
79
|
-
|
|
80
|
-
grammar_symbol
|
|
81
|
-
: IDENTIFIER { result = val[0] }
|
|
82
|
-
| LITERAL { result = val[0] }
|
|
83
|
-
|
|
84
|
-
rules
|
|
85
|
-
: rule_definition { result = [val[0]] }
|
|
86
|
-
| rules rule_definition { result = val[0] + [val[1]] }
|
|
87
|
-
|
|
88
|
-
rule_definition
|
|
89
|
-
: LHS ':' alternatives semicolon { result = build_rule(val[0], val[2]) }
|
|
90
|
-
|
|
91
|
-
semicolon
|
|
92
|
-
:
|
|
93
|
-
| ';'
|
|
94
|
-
|
|
95
|
-
alternatives
|
|
96
|
-
: alternative { result = [val[0]] }
|
|
97
|
-
| alternatives '|' alternative { result = val[0] + [val[2]] }
|
|
98
|
-
|
|
99
|
-
alternative
|
|
100
|
-
: items precedence_override { result = build_alternative(val[0], val[1]) }
|
|
101
|
-
|
|
102
|
-
precedence_override
|
|
103
|
-
: { result = nil }
|
|
104
|
-
| '=' grammar_symbol { result = val[1] }
|
|
105
|
-
|
|
106
|
-
items
|
|
107
|
-
: { result = Array.new(0) }
|
|
108
|
-
| items item { result = val[0] + [val[1]] }
|
|
109
|
-
|
|
110
|
-
item
|
|
111
|
-
: symbol_item { result = val[0] }
|
|
112
|
-
| ACTION { result = build_action(val[0]) }
|
|
113
|
-
| group_item { result = val[0] }
|
|
114
|
-
| separated_item { result = val[0] }
|
|
115
|
-
|
|
116
|
-
symbol_item
|
|
117
|
-
: grammar_symbol named_reference suffixes
|
|
118
|
-
{ result = build_symbol_reference(val[0], val[1], val[2]) }
|
|
119
|
-
|
|
120
|
-
named_reference
|
|
121
|
-
: { result = nil }
|
|
122
|
-
| ':' IDENTIFIER { result = [val[0], val[1]] }
|
|
123
|
-
|
|
124
|
-
suffixes
|
|
125
|
-
: { result = Array.new(0) }
|
|
126
|
-
| suffixes '?' { result = val[0] + [val[1]] }
|
|
127
|
-
| suffixes '*' { result = val[0] + [val[1]] }
|
|
128
|
-
| suffixes '+' { result = val[0] + [val[1]] }
|
|
129
|
-
|
|
130
|
-
group_item
|
|
131
|
-
: '(' group_alternatives ')' suffixes
|
|
132
|
-
{ result = build_group(val[0], val[1], val[3]) }
|
|
133
|
-
|
|
134
|
-
group_alternatives
|
|
135
|
-
: group_items { result = [val[0]] }
|
|
136
|
-
| group_alternatives '|' group_items { result = val[0] + [val[2]] }
|
|
137
|
-
|
|
138
|
-
group_items
|
|
139
|
-
: { result = Array.new(0) }
|
|
140
|
-
| group_items group_item_element { result = val[0] + [val[1]] }
|
|
141
|
-
|
|
142
|
-
group_item_element
|
|
143
|
-
: symbol_item { result = val[0] }
|
|
144
|
-
| group_item { result = val[0] }
|
|
145
|
-
| separated_item { result = val[0] }
|
|
146
|
-
|
|
147
|
-
separated_item
|
|
148
|
-
: SEPARATED_LIST '(' item ',' item ')'
|
|
149
|
-
{ result = build_separated_list(val[0], val[2], val[4]) }
|
|
150
|
-
| SEPARATED_NONEMPTY_LIST '(' item ',' item ')'
|
|
151
|
-
{ result = build_separated_list(val[0], val[2], val[4]) }
|
|
152
|
-
|
|
153
|
-
user_code
|
|
154
|
-
: { result = empty_user_code }
|
|
155
|
-
| user_code USER_CODE { result = append_user_code(val[0], val[1]) }
|
|
156
|
-
end
|
data/lib/ibex/runtime/parser.rb
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
# rbs_inline: enabled
|
|
3
|
-
|
|
4
|
-
module Ibex
|
|
5
|
-
module Runtime
|
|
6
|
-
# Parser-table shape understood by this runtime.
|
|
7
|
-
PARSER_TABLE_FORMAT_VERSION = 1 #: Integer
|
|
8
|
-
|
|
9
|
-
# Raised by the default parser error handler.
|
|
10
|
-
class ParseError < StandardError; end
|
|
11
|
-
|
|
12
|
-
# rubocop:disable Metrics/ClassLength
|
|
13
|
-
|
|
14
|
-
# Drives a table-defined LR parser without native extensions.
|
|
15
|
-
#
|
|
16
|
-
# Subclasses provide `.parser_tables`, returning `:tokens`, `:token_names`,
|
|
17
|
-
# `:actions`, `:gotos`, and `:productions`. Actions are represented by
|
|
18
|
-
# `[:shift, state]`, `[:reduce, production]`, `[:accept]`, or `[:error]`.
|
|
19
|
-
class Parser
|
|
20
|
-
EOF_TOKEN = 0 #: Integer
|
|
21
|
-
ERROR_TOKEN = 1 #: Integer
|
|
22
|
-
NO_LOOKAHEAD = Object.new.freeze #: Object
|
|
23
|
-
RECOVERY_SHIFTS = 3 #: Integer
|
|
24
|
-
empty_row = {} # @type var empty_row: Hash[Integer, untyped]
|
|
25
|
-
|
|
26
|
-
EMPTY_ROW = empty_row.freeze #: Hash[Integer, untyped]
|
|
27
|
-
|
|
28
|
-
# @rbs @yydebug: bool
|
|
29
|
-
# @rbs @yydebug_output: IO
|
|
30
|
-
# @rbs @source: (^() -> untyped)?
|
|
31
|
-
# @rbs @state_stack: Array[Integer]
|
|
32
|
-
# @rbs @value_stack: Array[untyped]
|
|
33
|
-
# @rbs @lookahead: untyped
|
|
34
|
-
# @rbs @lookahead_value: untyped
|
|
35
|
-
# @rbs @recovery_shifts: Integer
|
|
36
|
-
# @rbs @semantic_error: bool
|
|
37
|
-
# @rbs @accept_requested: bool
|
|
38
|
-
# @rbs @unknown_token_id: Integer?
|
|
39
|
-
# @rbs @unknown_token_name: String?
|
|
40
|
-
|
|
41
|
-
attr_accessor :yydebug #: bool
|
|
42
|
-
attr_writer :yydebug_output #: IO
|
|
43
|
-
|
|
44
|
-
# @rbs () -> void
|
|
45
|
-
def initialize
|
|
46
|
-
@yydebug = false
|
|
47
|
-
@yydebug_output = $stderr
|
|
48
|
-
@source = nil
|
|
49
|
-
@state_stack = []
|
|
50
|
-
@value_stack = []
|
|
51
|
-
@lookahead = NO_LOOKAHEAD
|
|
52
|
-
@lookahead_value = nil
|
|
53
|
-
@recovery_shifts = 0
|
|
54
|
-
@semantic_error = false
|
|
55
|
-
@accept_requested = false
|
|
56
|
-
@unknown_token_id = nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Pull tokens from `next_token` and parse them.
|
|
60
|
-
# @rbs () -> untyped
|
|
61
|
-
def do_parse
|
|
62
|
-
drive_parser(-> { next_token })
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Parse tokens yielded by `receiver.method_id`.
|
|
66
|
-
# @rbs (untyped receiver, Symbol method_id) -> untyped
|
|
67
|
-
def yyparse(receiver, method_id)
|
|
68
|
-
stream = Enumerator.new do |tokens|
|
|
69
|
-
receiver.__send__(method_id) { |token| tokens << token }
|
|
70
|
-
end
|
|
71
|
-
drive_parser(-> { stream.next })
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Override in pull parsers. Return `[token, value]`, `false`, or `nil`.
|
|
75
|
-
# @rbs () -> ([untyped, untyped] | false | nil)
|
|
76
|
-
def next_token
|
|
77
|
-
raise NotImplementedError, "(input):1:1: next_token must be implemented"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Override to recover from syntax errors. The default always raises.
|
|
81
|
-
# @rbs (Integer token_id, untyped value, Array[untyped] value_stack) -> untyped
|
|
82
|
-
def on_error(token_id, value, _value_stack)
|
|
83
|
-
expected = expected_tokens
|
|
84
|
-
suffix = expected.empty? ? "" : "; expected #{expected.join(', ')}"
|
|
85
|
-
raise ParseError, "(input):1:1: unexpected #{token_to_str(token_id)}#{suffix} (#{value.inspect})"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Called after an ordinary input token is shifted. Override to observe
|
|
89
|
-
# the internal token id, semantic value, and destination state.
|
|
90
|
-
# @rbs (Integer token_id, untyped value, Integer state) -> void
|
|
91
|
-
def on_shift(_token_id, _value, _state); end
|
|
92
|
-
|
|
93
|
-
# Called after a production's semantic action and goto are committed.
|
|
94
|
-
# Override to observe its id, RHS values, and semantic result.
|
|
95
|
-
# @rbs (Integer production_id, Array[untyped] values, untyped result) -> void
|
|
96
|
-
def on_reduce(_production_id, _values, _result); end
|
|
97
|
-
|
|
98
|
-
# Called after the synthetic error token enters a recovery state.
|
|
99
|
-
# The payload describes the original error before recovery popped stacks.
|
|
100
|
-
# @rbs (Integer token_id, untyped value, Array[untyped] value_stack) -> void
|
|
101
|
-
def on_error_recover(_token_id, _value, _value_stack); end
|
|
102
|
-
|
|
103
|
-
# Return a human-readable name for an internal token id.
|
|
104
|
-
# @rbs (Integer token_id) -> String
|
|
105
|
-
def token_to_str(token_id)
|
|
106
|
-
return @unknown_token_name || token_id.to_s if token_id == @unknown_token_id
|
|
107
|
-
|
|
108
|
-
parser_tables.fetch(:token_names).fetch(token_id, token_id.to_s)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# Enter error recovery from a semantic action without calling `on_error`.
|
|
112
|
-
# @rbs () -> nil
|
|
113
|
-
def yyerror
|
|
114
|
-
@semantic_error = true
|
|
115
|
-
nil
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Leave error recovery immediately.
|
|
119
|
-
# @rbs () -> nil
|
|
120
|
-
def yyerrok
|
|
121
|
-
@recovery_shifts = 0
|
|
122
|
-
nil
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# Accept immediately after the current semantic action completes.
|
|
126
|
-
# @rbs () -> nil
|
|
127
|
-
def yyaccept
|
|
128
|
-
@accept_requested = true
|
|
129
|
-
nil
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Return token names accepted in the current parser state.
|
|
133
|
-
# @rbs () -> Array[String]
|
|
134
|
-
def expected_tokens
|
|
135
|
-
return [] if @state_stack.empty?
|
|
136
|
-
|
|
137
|
-
state = @state_stack.last
|
|
138
|
-
parser_tables.fetch(:token_names).keys.filter_map do |token_id|
|
|
139
|
-
action = table_lookup(parser_tables.fetch(:actions), state, token_id) || default_action(state) || [:error]
|
|
140
|
-
token_to_str(token_id) unless error_action?(action) || token_id == ERROR_TOKEN
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
# @rbs (^() -> untyped source) -> untyped
|
|
147
|
-
def drive_parser(source)
|
|
148
|
-
prepare_parse(source)
|
|
149
|
-
loop do
|
|
150
|
-
action = action_for_current_state
|
|
151
|
-
outcome = perform(action)
|
|
152
|
-
return outcome[1] if outcome[0] == :done
|
|
153
|
-
end
|
|
154
|
-
ensure
|
|
155
|
-
@source = nil
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
# @rbs (^() -> untyped source) -> void
|
|
159
|
-
def prepare_parse(source)
|
|
160
|
-
validate_parser_table_format!
|
|
161
|
-
@source = source
|
|
162
|
-
@state_stack = [0]
|
|
163
|
-
@value_stack = []
|
|
164
|
-
@lookahead = NO_LOOKAHEAD
|
|
165
|
-
@lookahead_value = nil
|
|
166
|
-
@recovery_shifts = 0
|
|
167
|
-
@semantic_error = false
|
|
168
|
-
@accept_requested = false
|
|
169
|
-
@unknown_token_id = nil
|
|
170
|
-
trace("start state 0")
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# @rbs () -> void
|
|
174
|
-
def validate_parser_table_format!
|
|
175
|
-
tables = parser_tables
|
|
176
|
-
unless tables.key?(:format_version)
|
|
177
|
-
raise ParseError,
|
|
178
|
-
"(tables):1:1: parser tables for #{self.class} are missing :format_version; " \
|
|
179
|
-
"regenerate the parser with the installed Ibex version"
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
actual = tables.fetch(:format_version)
|
|
183
|
-
return if actual == PARSER_TABLE_FORMAT_VERSION
|
|
184
|
-
|
|
185
|
-
raise ParseError,
|
|
186
|
-
"(tables):1:1: unsupported parser table format version #{actual.inspect} for #{self.class}; " \
|
|
187
|
-
"runtime supports #{PARSER_TABLE_FORMAT_VERSION}; regenerate the parser with the installed Ibex version"
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# @rbs () -> untyped
|
|
191
|
-
def action_for_current_state
|
|
192
|
-
read_lookahead if @lookahead.equal?(NO_LOOKAHEAD)
|
|
193
|
-
state = @state_stack.last
|
|
194
|
-
return [:error] unless parser_tables.fetch(:token_names).key?(@lookahead)
|
|
195
|
-
|
|
196
|
-
explicit = table_lookup(parser_tables.fetch(:actions), state, @lookahead)
|
|
197
|
-
return explicit if explicit
|
|
198
|
-
|
|
199
|
-
default_action(state) || [:error]
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
# @rbs (untyped action) -> untyped
|
|
203
|
-
def perform(action)
|
|
204
|
-
case action.first
|
|
205
|
-
when :shift then shift(action.fetch(1))
|
|
206
|
-
when :reduce then reduce(action.fetch(1))
|
|
207
|
-
when :accept then [:done, @value_stack.last]
|
|
208
|
-
when :error then recover
|
|
209
|
-
else raise ParseError, "(tables):1:1: unknown parser action #{action.inspect}"
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
# @rbs (Integer next_state) -> untyped
|
|
214
|
-
def shift(next_state)
|
|
215
|
-
token_id = @lookahead
|
|
216
|
-
value = @lookahead_value
|
|
217
|
-
trace("shift #{token_to_str(token_id)} -> state #{next_state}")
|
|
218
|
-
@state_stack << next_state
|
|
219
|
-
@value_stack << value
|
|
220
|
-
@lookahead = NO_LOOKAHEAD
|
|
221
|
-
@recovery_shifts -= 1 if @recovery_shifts.positive?
|
|
222
|
-
on_shift(token_id, value, next_state)
|
|
223
|
-
[:continue]
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
# @rbs (Integer production_id) -> untyped
|
|
227
|
-
def reduce(production_id)
|
|
228
|
-
production = parser_tables.fetch(:productions).fetch(production_id)
|
|
229
|
-
length = production.fetch(:length)
|
|
230
|
-
values = @value_stack.last(length)
|
|
231
|
-
hook_values = values.dup
|
|
232
|
-
@state_stack.pop(length)
|
|
233
|
-
@value_stack.pop(length)
|
|
234
|
-
result = reduction_value(production, values)
|
|
235
|
-
next_state = table_lookup(parser_tables.fetch(:gotos), @state_stack.last, production.fetch(:lhs))
|
|
236
|
-
raise ParseError, "(tables):1:1: missing goto for production #{production_id}" if next_state.nil?
|
|
237
|
-
|
|
238
|
-
@state_stack << next_state
|
|
239
|
-
@value_stack << result
|
|
240
|
-
trace("reduce #{production_id} (#{length}) -> state #{next_state}")
|
|
241
|
-
on_reduce(production_id, hook_values, result)
|
|
242
|
-
return [:done, result] if @accept_requested
|
|
243
|
-
return recover(report: false) if @semantic_error
|
|
244
|
-
|
|
245
|
-
[:continue]
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
# @rbs (Hash[Symbol, untyped] production, Array[untyped] values) -> untyped
|
|
249
|
-
def reduction_value(production, values)
|
|
250
|
-
action = production[:action]
|
|
251
|
-
return values.first unless action
|
|
252
|
-
return instance_exec(values, @value_stack.dup, &action) if action.respond_to?(:call)
|
|
253
|
-
|
|
254
|
-
__send__(action, values, @value_stack.dup)
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
# @rbs (?report: bool) -> untyped
|
|
258
|
-
def recover(report: true)
|
|
259
|
-
@semantic_error = false
|
|
260
|
-
if @recovery_shifts.positive?
|
|
261
|
-
return [:done, nil] if @lookahead == EOF_TOKEN
|
|
262
|
-
|
|
263
|
-
trace("discard #{token_to_str(@lookahead)} during recovery")
|
|
264
|
-
@lookahead = NO_LOOKAHEAD
|
|
265
|
-
return [:continue]
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
token_id = @lookahead
|
|
269
|
-
value = @lookahead_value
|
|
270
|
-
value_stack = @value_stack.dup
|
|
271
|
-
on_error(token_id, value, value_stack.dup) if report
|
|
272
|
-
return [:done, nil] unless shift_error_token
|
|
273
|
-
|
|
274
|
-
@recovery_shifts = RECOVERY_SHIFTS
|
|
275
|
-
on_error_recover(token_id, value, value_stack)
|
|
276
|
-
[:continue]
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
# @rbs () -> bool
|
|
280
|
-
def shift_error_token
|
|
281
|
-
loop do
|
|
282
|
-
action = table_lookup(parser_tables.fetch(:actions), @state_stack.last, ERROR_TOKEN)
|
|
283
|
-
if action&.first == :shift
|
|
284
|
-
trace("recover: shift error -> state #{action.fetch(1)}")
|
|
285
|
-
@state_stack << action.fetch(1)
|
|
286
|
-
@value_stack << nil
|
|
287
|
-
return true
|
|
288
|
-
end
|
|
289
|
-
return false if @state_stack.length == 1
|
|
290
|
-
|
|
291
|
-
trace("recover: pop state #{@state_stack.last}")
|
|
292
|
-
@state_stack.pop
|
|
293
|
-
@value_stack.pop
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
# @rbs () -> void
|
|
298
|
-
def read_lookahead
|
|
299
|
-
pair = read_external_token
|
|
300
|
-
if pair.nil? || pair == false
|
|
301
|
-
@lookahead = EOF_TOKEN
|
|
302
|
-
@lookahead_value = nil
|
|
303
|
-
else
|
|
304
|
-
external_token, @lookahead_value = pair
|
|
305
|
-
@lookahead = internal_token_id(external_token)
|
|
306
|
-
end
|
|
307
|
-
trace("read #{token_to_str(@lookahead)}")
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
# @rbs () -> untyped
|
|
311
|
-
def read_external_token
|
|
312
|
-
source = @source
|
|
313
|
-
raise ParseError, "(input):1:1: token source is not available" unless source
|
|
314
|
-
|
|
315
|
-
source.call
|
|
316
|
-
rescue StopIteration
|
|
317
|
-
false
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
# @rbs (untyped external_token) -> Integer
|
|
321
|
-
def internal_token_id(external_token)
|
|
322
|
-
token_id = parser_tables.fetch(:tokens)[external_token]
|
|
323
|
-
return token_id if token_id
|
|
324
|
-
|
|
325
|
-
@unknown_token_name = external_token.inspect
|
|
326
|
-
@unknown_token_id = -external_token.object_id.abs
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
# @rbs () -> Hash[Symbol, untyped]
|
|
330
|
-
def parser_tables
|
|
331
|
-
self.class.__send__(:parser_tables)
|
|
332
|
-
rescue NoMethodError
|
|
333
|
-
raise ParseError, "(tables):1:1: #{self.class} must define .parser_tables"
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
# @rbs (untyped action) -> bool
|
|
337
|
-
def error_action?(action)
|
|
338
|
-
action.nil? || action.first == :error
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
# @rbs (Integer state) -> untyped
|
|
342
|
-
def default_action(state)
|
|
343
|
-
parser_tables.fetch(:default_actions, EMPTY_ROW)[state]
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
# @rbs (untyped table, Integer row, Integer column) -> untyped
|
|
347
|
-
def table_lookup(table, row, column)
|
|
348
|
-
return table.lookup(row, column) if table.respond_to?(:lookup)
|
|
349
|
-
|
|
350
|
-
table.fetch(row, EMPTY_ROW)[column]
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
# @rbs (String message) -> void
|
|
354
|
-
def trace(message)
|
|
355
|
-
@yydebug_output.puts("ibex: #{message}") if @yydebug
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
# rubocop:enable Metrics/ClassLength
|
|
359
|
-
end
|
|
360
|
-
end
|