@mpeggroup/mpeg-sdl-parser 4.0.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.
- package/LICENSE +21 -0
- package/README.md +337 -0
- package/bun.lock +65 -0
- package/dist/index.js +11829 -0
- package/grammar/sdl.ebnf.grammar +399 -0
- package/grammar/sdl.lezer.grammar +629 -0
- package/index.ts +83 -0
- package/package.json +61 -0
- package/src/analyser/checks/check-array-definition.ts +90 -0
- package/src/analyser/checks/check-array-element-access.ts +31 -0
- package/src/analyser/checks/check-class-declaration.ts +417 -0
- package/src/analyser/checks/check-computed-array-definition.ts +44 -0
- package/src/analyser/checks/check-computed-elementary-type-definition.ts +45 -0
- package/src/analyser/checks/check-elementary-type-definition.ts +167 -0
- package/src/analyser/checks/check-expression-binary.ts +242 -0
- package/src/analyser/checks/check-expression-lengthof.ts +34 -0
- package/src/analyser/checks/check-expression-unary.ts +166 -0
- package/src/analyser/checks/check-identifier.ts +71 -0
- package/src/analyser/checks/check-if-statement.ts +164 -0
- package/src/analyser/checks/check-map-declaration.ts +180 -0
- package/src/analyser/checks/check-map-definition.ts +118 -0
- package/src/analyser/checks/check-number-literal-float.ts +28 -0
- package/src/analyser/checks/check-parameter-list.ts +42 -0
- package/src/analyser/checks/check-specification.ts +53 -0
- package/src/analyser/checks/check-switch-statement.ts +206 -0
- package/src/analyser/checks/check.ts +20 -0
- package/src/analyser/create-sdl-analyser.ts +85 -0
- package/src/analyser/node-handler/abstract-analysis-node-handler.ts +626 -0
- package/src/analyser/node-handler/build-symbol-table-node-handler.ts +649 -0
- package/src/analyser/node-handler/specific-check-node-handler.ts +46 -0
- package/src/analyser/node-handler/validate-scope-node-handler.ts +290 -0
- package/src/analyser/node-handler/validate-type-node-handler.ts +497 -0
- package/src/analyser/sdl-analyser.ts +119 -0
- package/src/analyser/symbol-table.ts +388 -0
- package/src/analyser/util/symbol-table-utils.ts +458 -0
- package/src/analyser/util/type-utils.ts +238 -0
- package/src/ast/build/consume/consume-abstract-node.ts +199 -0
- package/src/ast/build/consume/consume-ast-node.ts +400 -0
- package/src/ast/build/consume/consume-primitive.ts +59 -0
- package/src/ast/build/consume/consume-trivia.ts +96 -0
- package/src/ast/build/consume/consume-white-space-and-missing-errors.ts +27 -0
- package/src/ast/build/node/build-aggregate-output-value.ts +57 -0
- package/src/ast/build/node/build-aligned-modifier.ts +99 -0
- package/src/ast/build/node/build-array-definition.ts +131 -0
- package/src/ast/build/node/build-array-element-access.ts +45 -0
- package/src/ast/build/node/build-base64-string-literal.ts +41 -0
- package/src/ast/build/node/build-binary-expression.ts +113 -0
- package/src/ast/build/node/build-binary-literal.ts +37 -0
- package/src/ast/build/node/build-bit-modifier.ts +86 -0
- package/src/ast/build/node/build-case-clause.ts +101 -0
- package/src/ast/build/node/build-class-declaration.ts +124 -0
- package/src/ast/build/node/build-class-definition.ts +56 -0
- package/src/ast/build/node/build-class-id-range.ts +32 -0
- package/src/ast/build/node/build-class-id.ts +19 -0
- package/src/ast/build/node/build-class-member-access.ts +27 -0
- package/src/ast/build/node/build-compound-statement.ts +33 -0
- package/src/ast/build/node/build-computed-array-definition.ts +53 -0
- package/src/ast/build/node/build-computed-elementary-type-definition.ts +100 -0
- package/src/ast/build/node/build-decimal-literal.ts +15 -0
- package/src/ast/build/node/build-default-clause.ts +76 -0
- package/src/ast/build/node/build-do-statement.ts +71 -0
- package/src/ast/build/node/build-elementary-type-definition.ts +164 -0
- package/src/ast/build/node/build-elementary-type-output-value.ts +25 -0
- package/src/ast/build/node/build-elementary-type.ts +36 -0
- package/src/ast/build/node/build-expandable-modifier.ts +68 -0
- package/src/ast/build/node/build-explicit-array-dimension.ts +37 -0
- package/src/ast/build/node/build-expression-statement.ts +31 -0
- package/src/ast/build/node/build-extended-class-id-range.ts +27 -0
- package/src/ast/build/node/build-extends-modifier.ts +41 -0
- package/src/ast/build/node/build-floating-point-literal.ts +15 -0
- package/src/ast/build/node/build-for-statement.ts +117 -0
- package/src/ast/build/node/build-hexadecimal-literal.ts +38 -0
- package/src/ast/build/node/build-identifier.ts +8 -0
- package/src/ast/build/node/build-if-statement.ts +82 -0
- package/src/ast/build/node/build-implicit-array-dimension.ts +78 -0
- package/src/ast/build/node/build-integer-literal.ts +15 -0
- package/src/ast/build/node/build-length-attribute.ts +48 -0
- package/src/ast/build/node/build-lengthof-expression.ts +45 -0
- package/src/ast/build/node/build-map-declaration.ts +110 -0
- package/src/ast/build/node/build-map-definition.ts +103 -0
- package/src/ast/build/node/build-map-entry.ts +33 -0
- package/src/ast/build/node/build-missing-error.ts +10 -0
- package/src/ast/build/node/build-multiple-character-literal.ts +65 -0
- package/src/ast/build/node/build-parameter-list.ts +50 -0
- package/src/ast/build/node/build-parameter-value-list.ts +54 -0
- package/src/ast/build/node/build-parameter.ts +47 -0
- package/src/ast/build/node/build-partial-array-dimension.ts +55 -0
- package/src/ast/build/node/build-specification.ts +24 -0
- package/src/ast/build/node/build-string-definition.ts +106 -0
- package/src/ast/build/node/build-switch-statement.ts +84 -0
- package/src/ast/build/node/build-token.ts +26 -0
- package/src/ast/build/node/build-unary-expression.ts +109 -0
- package/src/ast/build/node/build-unexpected-error.ts +14 -0
- package/src/ast/build/node/build-utf-string-literal.ts +110 -0
- package/src/ast/build/node/build-while-statement.ts +55 -0
- package/src/ast/build/util/array-dimension-kind-by-token-type-id-map.ts +167 -0
- package/src/ast/build/util/binary-operator-kind-by-token-type-id-map.ts +152 -0
- package/src/ast/build/util/build-context.ts +36 -0
- package/src/ast/build/util/class-id-kind-by-token-type-id-map.ts +160 -0
- package/src/ast/build/util/expression-kind-by-token-type-id-map.ts +168 -0
- package/src/ast/build/util/fetch-node.ts +433 -0
- package/src/ast/build/util/node-kind-by-token-type-id-map.ts +202 -0
- package/src/ast/build/util/statement-kind-by-token-type-id-map.ts +210 -0
- package/src/ast/build/util/string-literal-kind-by-token-type-id-map.ts +162 -0
- package/src/ast/build/util/token-kind-by-token-type-id-map.ts +337 -0
- package/src/ast/build-ast.ts +114 -0
- package/src/ast/node/abstract-array-definition.ts +17 -0
- package/src/ast/node/abstract-array-dimension.ts +20 -0
- package/src/ast/node/abstract-class-id.ts +13 -0
- package/src/ast/node/abstract-composite-node.ts +58 -0
- package/src/ast/node/abstract-elementary-type-definition.ts +29 -0
- package/src/ast/node/abstract-expression.ts +13 -0
- package/src/ast/node/abstract-leaf-node.ts +10 -0
- package/src/ast/node/abstract-node.ts +16 -0
- package/src/ast/node/abstract-statement.ts +13 -0
- package/src/ast/node/aggregate-output-value.ts +28 -0
- package/src/ast/node/aligned-modifier.ts +21 -0
- package/src/ast/node/array-definition.ts +44 -0
- package/src/ast/node/array-element-access.ts +24 -0
- package/src/ast/node/binary-expression.ts +28 -0
- package/src/ast/node/bit-modifier.ts +24 -0
- package/src/ast/node/case-clause.ts +30 -0
- package/src/ast/node/class-declaration.ts +39 -0
- package/src/ast/node/class-definition.ts +23 -0
- package/src/ast/node/class-id-range.ts +17 -0
- package/src/ast/node/class-id.ts +14 -0
- package/src/ast/node/class-member-access.ts +19 -0
- package/src/ast/node/compound-statement.ts +19 -0
- package/src/ast/node/computed-array-definition.ts +26 -0
- package/src/ast/node/computed-elementary-type-definition.ts +34 -0
- package/src/ast/node/default-clause.ts +26 -0
- package/src/ast/node/do-statement.ts +28 -0
- package/src/ast/node/elementary-type-definition.ts +49 -0
- package/src/ast/node/elementary-type-output-value.ts +19 -0
- package/src/ast/node/elementary-type.ts +18 -0
- package/src/ast/node/enum/array-dimension-kind.ts +11 -0
- package/src/ast/node/enum/binary-operator-kind.ts +41 -0
- package/src/ast/node/enum/class-id-kind.ts +12 -0
- package/src/ast/node/enum/elementary-type-kind.ts +13 -0
- package/src/ast/node/enum/expression-kind.ts +11 -0
- package/src/ast/node/enum/node-kind.ts +57 -0
- package/src/ast/node/enum/number-literal-kind.ts +17 -0
- package/src/ast/node/enum/statement-kind.ts +37 -0
- package/src/ast/node/enum/string-literal-kind.ts +13 -0
- package/src/ast/node/enum/string-variable-kind.ts +25 -0
- package/src/ast/node/enum/token-kind.ts +87 -0
- package/src/ast/node/expandable-modifier.ts +21 -0
- package/src/ast/node/explicit-array-dimension.ts +26 -0
- package/src/ast/node/expression-statement.ts +23 -0
- package/src/ast/node/extended-class-id-range.ts +20 -0
- package/src/ast/node/extends-modifier.ts +21 -0
- package/src/ast/node/for-statement.ts +29 -0
- package/src/ast/node/identifier.ts +12 -0
- package/src/ast/node/if-statement.ts +28 -0
- package/src/ast/node/implicit-array-dimension.ts +34 -0
- package/src/ast/node/length-attribute.ts +24 -0
- package/src/ast/node/length-of-expression.ts +21 -0
- package/src/ast/node/map-declaration.ts +34 -0
- package/src/ast/node/map-definition.ts +27 -0
- package/src/ast/node/map-entry.ts +18 -0
- package/src/ast/node/missing-error.ts +9 -0
- package/src/ast/node/number-literal.ts +18 -0
- package/src/ast/node/parameter-list.ts +25 -0
- package/src/ast/node/parameter-value-list.ts +29 -0
- package/src/ast/node/parameter.ts +20 -0
- package/src/ast/node/partial-array-dimension.ts +28 -0
- package/src/ast/node/specification.ts +21 -0
- package/src/ast/node/string-definition.ts +28 -0
- package/src/ast/node/string-literal.ts +21 -0
- package/src/ast/node/switch-statement.ts +32 -0
- package/src/ast/node/token.ts +20 -0
- package/src/ast/node/trivia.ts +13 -0
- package/src/ast/node/unary-expression.ts +31 -0
- package/src/ast/node/unexpected-error.ts +12 -0
- package/src/ast/node/while-statement.ts +26 -0
- package/src/ast/util/types.ts +138 -0
- package/src/ast/visitor/node-handler.ts +15 -0
- package/src/ast/visitor/node-visitor.ts +13 -0
- package/src/ast/visitor/traversing-visitor.ts +69 -0
- package/src/completion/completion-rules.ts +447 -0
- package/src/completion/get-potential-syntactic-tokens.ts +54 -0
- package/src/completion/get-potential-token-type-ids.ts +116 -0
- package/src/completion/hierarchical-map.ts +43 -0
- package/src/completion/rules/abstract-types.ts +174 -0
- package/src/completion/rules/aggregate-output-value-rules.ts +48 -0
- package/src/completion/rules/aligned-modifier-rules.ts +45 -0
- package/src/completion/rules/array-definition-rules.ts +87 -0
- package/src/completion/rules/array-element-access-rules.ts +22 -0
- package/src/completion/rules/assignment-expression-rules.ts +19 -0
- package/src/completion/rules/binary-expression-rules.ts +23 -0
- package/src/completion/rules/bit-modifier-rules.ts +25 -0
- package/src/completion/rules/case-clause-rules.ts +39 -0
- package/src/completion/rules/class-declaration-rules.ts +81 -0
- package/src/completion/rules/class-definition-rules.ts +28 -0
- package/src/completion/rules/class-id-range-rules.ts +17 -0
- package/src/completion/rules/class-id-rules.ts +9 -0
- package/src/completion/rules/class-member-access-rules.ts +7 -0
- package/src/completion/rules/compound-statement-rules.ts +25 -0
- package/src/completion/rules/computed-array-definition-rules.ts +25 -0
- package/src/completion/rules/computed-elementary-type-rules.ts +44 -0
- package/src/completion/rules/default-clause-rules.ts +23 -0
- package/src/completion/rules/do-statement-rules.ts +38 -0
- package/src/completion/rules/elementary-type-definition-rules.ts +62 -0
- package/src/completion/rules/elementary-type-output-value-rules.ts +13 -0
- package/src/completion/rules/elementary-type-rules.ts +18 -0
- package/src/completion/rules/expandable-modifier-rules.ts +21 -0
- package/src/completion/rules/explicit-array-dimension-rules.ts +22 -0
- package/src/completion/rules/expression-statement-rules.ts +22 -0
- package/src/completion/rules/extended-class-id-range-rules.ts +17 -0
- package/src/completion/rules/extends-modifier-rules.ts +17 -0
- package/src/completion/rules/for-statement-rules.ts +51 -0
- package/src/completion/rules/if-statement-rules.ts +42 -0
- package/src/completion/rules/implicit-array-dimension-rules.ts +21 -0
- package/src/completion/rules/length-attribute-rules.ts +19 -0
- package/src/completion/rules/lengthof-expression-rules.ts +23 -0
- package/src/completion/rules/map-declaration-rules.ts +45 -0
- package/src/completion/rules/map-definition-rules.ts +46 -0
- package/src/completion/rules/map-entry-rules.ts +17 -0
- package/src/completion/rules/parameter-list-rules.ts +21 -0
- package/src/completion/rules/parameter-rules.ts +17 -0
- package/src/completion/rules/parameter-value-list-rules.ts +27 -0
- package/src/completion/rules/partial-array-dimension-rules.ts +33 -0
- package/src/completion/rules/specification-rules.ts +37 -0
- package/src/completion/rules/string-definition-rules.ts +103 -0
- package/src/completion/rules/switch-statement-rules.ts +50 -0
- package/src/completion/rules/unary-expression-rules.ts +41 -0
- package/src/completion/rules/utf-string-literal-rules.ts +17 -0
- package/src/completion/rules/while-statement-rules.ts +38 -0
- package/src/lezer/context-tracker.ts +45 -0
- package/src/lezer/create-sdl-parser.ts +88 -0
- package/src/lezer/create-syntax-error-from-text-and-cursor.ts +110 -0
- package/src/lezer/create-syntax-error-from-text-and-position.ts +36 -0
- package/src/lezer/parser.terms.ts +129 -0
- package/src/lezer/parser.ts +63 -0
- package/src/lezer/props/fold-node-prop-source.ts +27 -0
- package/src/lezer/props/primitive-node-prop-source.ts +19 -0
- package/src/lezer/props/style-tags-node-prop-source.ts +188 -0
- package/src/lezer/props/syntactic-token-node-prop-source.ts +298 -0
- package/src/lezer/sdl-string-input.ts +46 -0
- package/src/location.ts +13 -0
- package/src/parse-helper.ts +93 -0
- package/src/prettier/prettier-plugin-sdl.ts +89 -0
- package/src/prettier/print-abstract-array-dimension.ts +84 -0
- package/src/prettier/print-abstract-class-id.ts +53 -0
- package/src/prettier/print-abstract-expression.ts +168 -0
- package/src/prettier/print-abstract-node.ts +224 -0
- package/src/prettier/print-abstract-statement.ts +124 -0
- package/src/prettier/print-aggregate-output-value.ts +35 -0
- package/src/prettier/print-aligned-modifier.ts +50 -0
- package/src/prettier/print-array-definition.ts +95 -0
- package/src/prettier/print-array-element-access.ts +14 -0
- package/src/prettier/print-bit-modifier.ts +48 -0
- package/src/prettier/print-case-clause.ts +58 -0
- package/src/prettier/print-class-declaration.ts +99 -0
- package/src/prettier/print-class-definition.ts +44 -0
- package/src/prettier/print-class-member-access.ts +13 -0
- package/src/prettier/print-computed-array-definition.ts +33 -0
- package/src/prettier/print-computed-elementary-type-definition.ts +60 -0
- package/src/prettier/print-default-clause.ts +39 -0
- package/src/prettier/print-do-statement.ts +31 -0
- package/src/prettier/print-elementary-type-definition.ts +108 -0
- package/src/prettier/print-elementary-type-output-value.ts +13 -0
- package/src/prettier/print-elementary-type.ts +28 -0
- package/src/prettier/print-expandable-modifier.ts +41 -0
- package/src/prettier/print-extends-modifier.ts +29 -0
- package/src/prettier/print-for-statement.ts +64 -0
- package/src/prettier/print-identifier.ts +10 -0
- package/src/prettier/print-if-statement.ts +76 -0
- package/src/prettier/print-length-attribute.ts +14 -0
- package/src/prettier/print-map-declaration.ts +75 -0
- package/src/prettier/print-map-definition.ts +67 -0
- package/src/prettier/print-map-entry.ts +22 -0
- package/src/prettier/print-number-literal.ts +84 -0
- package/src/prettier/print-parameter-list.ts +20 -0
- package/src/prettier/print-parameter-value-list.ts +20 -0
- package/src/prettier/print-parameter.ts +34 -0
- package/src/prettier/print-specification.ts +51 -0
- package/src/prettier/print-string-definition.ts +114 -0
- package/src/prettier/print-string-literal.ts +57 -0
- package/src/prettier/print-switch-statement.ts +46 -0
- package/src/prettier/print-token.ts +7 -0
- package/src/prettier/print-unexpected-error.ts +10 -0
- package/src/prettier/print-while-statement.ts +26 -0
- package/src/prettier/util/print-utils.ts +607 -0
- package/src/prettier/util/types.ts +40 -0
- package/src/scanner-error.ts +65 -0
- package/src/util/location-utils.ts +16 -0
- package/src/util/logger.ts +165 -0
- package/tests/analyser/create-sdl-analyser.test.ts +54 -0
- package/tests/analyser/get-sdl-analyser-test-scenarios.ts +80 -0
- package/tests/analyser/sdl-analyser-scenarios.test.ts +67 -0
- package/tests/analyser/semantic-error-scenarios.test.ts +40 -0
- package/tests/analyser/symbol-table.test.ts +188 -0
- package/tests/analyser/test-cases/array_definition.txt +50 -0
- package/tests/analyser/test-cases/class_declaration.txt +112 -0
- package/tests/analyser/test-cases/class_definition.txt +60 -0
- package/tests/analyser/test-cases/compound_statement.txt +63 -0
- package/tests/analyser/test-cases/computed_array_definition.txt +12 -0
- package/tests/analyser/test-cases/computed_elementary_type_definition.txt +39 -0
- package/tests/analyser/test-cases/do_statement.txt +16 -0
- package/tests/analyser/test-cases/elementary_type_definition.txt +58 -0
- package/tests/analyser/test-cases/expression.txt +159 -0
- package/tests/analyser/test-cases/for_statement.txt +55 -0
- package/tests/analyser/test-cases/if_statement.txt +57 -0
- package/tests/analyser/test-cases/map_declaration.txt +89 -0
- package/tests/analyser/test-cases/map_definition.txt +35 -0
- package/tests/analyser/test-cases/number_literal.txt +31 -0
- package/tests/analyser/test-cases/parameter_list.txt +16 -0
- package/tests/analyser/test-cases/scopes.txt +239 -0
- package/tests/analyser/test-cases/specification.txt +28 -0
- package/tests/analyser/test-cases/string_definition.txt +40 -0
- package/tests/analyser/test-cases/switch_statement.txt +96 -0
- package/tests/analyser/test-cases/while_statement.txt +16 -0
- package/tests/analyser/util/symbol-table-utils.test.ts +65 -0
- package/tests/ast/__snapshots__/build-ast.test.ts.snap +38897 -0
- package/tests/ast/build-ast.test.ts +463 -0
- package/tests/ast/visitor/traversing-visitor.test.ts +36 -0
- package/tests/completion/get-potential-syntactic-tokens.test.ts +89 -0
- package/tests/completion/get-potential-token-type-ids.test.ts +76 -0
- package/tests/completion/test-potential-syntactic-tokens-scenario.ts +24 -0
- package/tests/completion/test-potential-token-type-ids-scenario.ts +33 -0
- package/tests/fixtures/history-recording-node-handler.ts +232 -0
- package/tests/lezer/create-parse-error-from-text-and-position.test.ts +129 -0
- package/tests/lezer/create-sdl-parser.test.ts +15 -0
- package/tests/lezer/sdl-parser-scenarios.test.ts +24 -0
- package/tests/lezer/sdl-string-input.test.ts +12 -0
- package/tests/lezer/syntax-error-scenarios.test.ts +114 -0
- package/tests/lezer/test-cases/array_definition.txt +109 -0
- package/tests/lezer/test-cases/class_declaration.txt +141 -0
- package/tests/lezer/test-cases/class_definition.txt +89 -0
- package/tests/lezer/test-cases/comment.txt +335 -0
- package/tests/lezer/test-cases/compound_statement.txt +109 -0
- package/tests/lezer/test-cases/computed_array_definition.txt +33 -0
- package/tests/lezer/test-cases/computed_elementary_type_definition.txt +59 -0
- package/tests/lezer/test-cases/do_statement.txt +48 -0
- package/tests/lezer/test-cases/elementary_type_definition.txt +158 -0
- package/tests/lezer/test-cases/expression.txt +1203 -0
- package/tests/lezer/test-cases/for_statement.txt +183 -0
- package/tests/lezer/test-cases/if_statement.txt +183 -0
- package/tests/lezer/test-cases/invalid.txt +97 -0
- package/tests/lezer/test-cases/map_declaration.txt +152 -0
- package/tests/lezer/test-cases/map_definition.txt +59 -0
- package/tests/lezer/test-cases/number_literal.txt +273 -0
- package/tests/lezer/test-cases/specification.txt +38 -0
- package/tests/lezer/test-cases/string_definition.txt +263 -0
- package/tests/lezer/test-cases/string_literal.txt +303 -0
- package/tests/lezer/test-cases/switch_statement.txt +407 -0
- package/tests/lezer/test-cases/while_statement.txt +45 -0
- package/tests/parse-helper.test.ts +361 -0
- package/tests/prettier/__snapshots__/prettier-plugin-sdl.test.ts.snap +127 -0
- package/tests/prettier/prettier-plugin-sdl.test.ts +58 -0
- package/tests/prettier/print-array.test.ts +29 -0
- package/tests/prettier/print-class.test.ts +15 -0
- package/tests/prettier/print-do.test.ts +25 -0
- package/tests/prettier/print-elementary-type.test.ts +62 -0
- package/tests/prettier/print-error.test.ts +40 -0
- package/tests/prettier/print-expression.test.ts +17 -0
- package/tests/prettier/print-for.test.ts +23 -0
- package/tests/prettier/print-if.test.ts +71 -0
- package/tests/prettier/print-number-literal.test.ts +28 -0
- package/tests/prettier/print-specification.test.ts +54 -0
- package/tests/prettier/print-string.test.ts +36 -0
- package/tests/prettier/print-switch.test.ts +69 -0
- package/tests/prettier/print-while.test.ts +23 -0
- package/tests/prettier/test-prettier-scenario.ts +41 -0
- package/tests/prettier/util/print-utils.test.ts +665 -0
- package/tests/prettier/util/types.test.ts +38 -0
- package/tests/sample-specifications/invalid.sdl +24 -0
- package/tests/sample-specifications/prettified-invalid.sdl +28 -0
- package/tests/sample-specifications/prettified-various-elements-narrow.sdl +97 -0
- package/tests/sample-specifications/prettified-various-elements.sdl +90 -0
- package/tests/sample-specifications/sample.sdl +24 -0
- package/tests/sample-specifications/various-elements.sdl +88 -0
- package/tests/util/logger.test.ts +36 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { HierarchicalSearch } from "./hierarchical-map.ts";
|
|
2
|
+
import { alignedModifierRules } from "./rules/aligned-modifier-rules.ts";
|
|
3
|
+
import { parameterValueListRules } from "./rules/parameter-value-list-rules.ts";
|
|
4
|
+
import { stringDefinitionRules } from "./rules/string-definition-rules.ts";
|
|
5
|
+
import { utfStringLiteralRules } from "./rules/utf-string-literal-rules.ts";
|
|
6
|
+
import { whileStatementRules } from "./rules/while-statement-rules.ts";
|
|
7
|
+
import { computedElementaryTypeRules } from "./rules/computed-elementary-type-rules.ts";
|
|
8
|
+
import { elementaryTypeRules } from "./rules/elementary-type-rules.ts";
|
|
9
|
+
import { compoundStatementRules } from "./rules/compound-statement-rules.ts";
|
|
10
|
+
import { ifStatementRules } from "./rules/if-statement-rules.ts";
|
|
11
|
+
import { forStatementRules } from "./rules/for-statement-rules.ts";
|
|
12
|
+
import { switchStatementRules } from "./rules/switch-statement-rules.ts";
|
|
13
|
+
import { caseClauseRules } from "./rules/case-clause-rules.ts";
|
|
14
|
+
import { defaultClauseRules } from "./rules/default-clause-rules.ts";
|
|
15
|
+
import { classDeclarationRules } from "./rules/class-declaration-rules.ts";
|
|
16
|
+
import { expandableModifierRules } from "./rules/expandable-modifier-rules.ts";
|
|
17
|
+
import { classDefinitionRules } from "./rules/class-definition-rules.ts";
|
|
18
|
+
import { assignmentExpressionRules } from "./rules/assignment-expression-rules.ts";
|
|
19
|
+
import { doStatementRules } from "./rules/do-statement-rules.ts";
|
|
20
|
+
import { elementaryTypeDefinitionRules } from "./rules/elementary-type-definition-rules.ts";
|
|
21
|
+
import { lengthAttributeRules } from "./rules/length-attribute-rules.ts";
|
|
22
|
+
import { extendsModifierRules } from "./rules/extends-modifier-rules.ts";
|
|
23
|
+
import { parameterListRules } from "./rules/parameter-list-rules.ts";
|
|
24
|
+
import { parameterRules } from "./rules/parameter-rules.ts";
|
|
25
|
+
import { binaryExpressionRules } from "./rules/binary-expression-rules.ts";
|
|
26
|
+
import { unaryExpressionRules } from "./rules/unary-expression-rules.ts";
|
|
27
|
+
import { arrayElementAccessRules } from "./rules/array-element-access-rules.ts";
|
|
28
|
+
import { classMemberAccessRules } from "./rules/class-member-access-rules.ts";
|
|
29
|
+
import { lengthofExpressionRules } from "./rules/lengthof-expression-rules.ts";
|
|
30
|
+
import { bitModifierRules } from "./rules/bit-modifier-rules.ts";
|
|
31
|
+
import { extendedClassIdRangeRules } from "./rules/extended-class-id-range-rules.ts";
|
|
32
|
+
import { classIdRules } from "./rules/class-id-rules.ts";
|
|
33
|
+
import { classIdRangeRules } from "./rules/class-id-range-rules.ts";
|
|
34
|
+
import { expressionStatementRules } from "./rules/expression-statement-rules.ts";
|
|
35
|
+
import { mapDefinitionRules } from "./rules/map-definition-rules.ts";
|
|
36
|
+
import { arrayDefinitionRules } from "./rules/array-definition-rules.ts";
|
|
37
|
+
import { implicitArrayDimensionRules } from "./rules/implicit-array-dimension-rules.ts";
|
|
38
|
+
import { explicitArrayDimensionRules } from "./rules/explicit-array-dimension-rules.ts";
|
|
39
|
+
import { partialArrayDimensionRules } from "./rules/partial-array-dimension-rules.ts";
|
|
40
|
+
import { computedArrayDefinitionRules } from "./rules/computed-array-definition-rules.ts";
|
|
41
|
+
import { mapDeclarationRules } from "./rules/map-declaration-rules.ts";
|
|
42
|
+
import { mapEntryRules } from "./rules/map-entry-rules.ts";
|
|
43
|
+
import { aggregateOutputValueRules } from "./rules/aggregate-output-value-rules.ts";
|
|
44
|
+
import { elementaryTypeOutputValueRules } from "./rules/elementary-type-output-value-rules.ts";
|
|
45
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
46
|
+
import { specificationRules } from "./rules/specification-rules.ts";
|
|
47
|
+
import { tokenIdToSyntaxStringMapping } from "../lezer/props/syntactic-token-node-prop-source.ts";
|
|
48
|
+
|
|
49
|
+
import getLogger from "../util/logger.ts";
|
|
50
|
+
|
|
51
|
+
// Generated by Lezer from the SDL grammar
|
|
52
|
+
import * as TokenTypeId from "../lezer/parser.terms.ts";
|
|
53
|
+
import { parser } from "../lezer/parser.ts";
|
|
54
|
+
|
|
55
|
+
const nodeTypes = parser.nodeSet.types;
|
|
56
|
+
|
|
57
|
+
const logger = getLogger("completionRules");
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A map from parent token type ID to a HierarchicalSearch of previous sibling token type IDs to expected token type IDs.
|
|
61
|
+
*/
|
|
62
|
+
export const completionRulesByParentMap: Map<
|
|
63
|
+
number,
|
|
64
|
+
HierarchicalSearch<number[]>
|
|
65
|
+
> = new Map();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A map from token type ID to potential starting syntactic tokens.
|
|
69
|
+
*/
|
|
70
|
+
export const potentialSyntacticTokensByTokenTypeId: Map<number, string[]> =
|
|
71
|
+
new Map();
|
|
72
|
+
|
|
73
|
+
type CompletionRule = {
|
|
74
|
+
previous: number | number[];
|
|
75
|
+
expected: number | number[];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function addRulesForParent(
|
|
79
|
+
parentTokenId: number,
|
|
80
|
+
rules: CompletionRule | CompletionRule[],
|
|
81
|
+
) {
|
|
82
|
+
if (completionRulesByParentMap.has(parentTokenId)) {
|
|
83
|
+
throw new InternalScannerError(
|
|
84
|
+
`Completion rules for parent token ${
|
|
85
|
+
nodeTypes[parentTokenId].name
|
|
86
|
+
} already exist`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!Array.isArray(rules)) {
|
|
91
|
+
rules = [rules];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (rules.length === 0) {
|
|
95
|
+
logger.warn(
|
|
96
|
+
`No completion rules provided for parent token ${
|
|
97
|
+
nodeTypes[parentTokenId].name
|
|
98
|
+
}`,
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const hierarchicalSearch = new HierarchicalSearch<number[]>();
|
|
104
|
+
|
|
105
|
+
for (const rule of rules) {
|
|
106
|
+
const previousTokens = Array.isArray(rule.previous)
|
|
107
|
+
? rule.previous
|
|
108
|
+
: [rule.previous];
|
|
109
|
+
const expectedTokens = Array.isArray(rule.expected)
|
|
110
|
+
? rule.expected
|
|
111
|
+
: [rule.expected];
|
|
112
|
+
|
|
113
|
+
hierarchicalSearch.set(previousTokens, expectedTokens);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
completionRulesByParentMap.set(parentTokenId, hierarchicalSearch);
|
|
117
|
+
|
|
118
|
+
logger.debug(
|
|
119
|
+
`Added completion rules for parent token ${nodeTypes[parentTokenId].name}`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Validate that all TokenTypeIds have completion rules defined, except for those that are intentionally excluded.
|
|
125
|
+
*/
|
|
126
|
+
Object.values(TokenTypeId).forEach((tokenTypeId) => {
|
|
127
|
+
switch (tokenTypeId) {
|
|
128
|
+
case TokenTypeId.AlignedModifier:
|
|
129
|
+
addRulesForParent(TokenTypeId.AlignedModifier, alignedModifierRules);
|
|
130
|
+
break;
|
|
131
|
+
case TokenTypeId.AggregateOutputValue:
|
|
132
|
+
addRulesForParent(
|
|
133
|
+
TokenTypeId.AggregateOutputValue,
|
|
134
|
+
aggregateOutputValueRules,
|
|
135
|
+
);
|
|
136
|
+
break;
|
|
137
|
+
case TokenTypeId.ArrayDefinition:
|
|
138
|
+
addRulesForParent(TokenTypeId.ArrayDefinition, arrayDefinitionRules);
|
|
139
|
+
break;
|
|
140
|
+
case TokenTypeId.AssignmentExpression:
|
|
141
|
+
addRulesForParent(
|
|
142
|
+
TokenTypeId.AssignmentExpression,
|
|
143
|
+
assignmentExpressionRules,
|
|
144
|
+
);
|
|
145
|
+
break;
|
|
146
|
+
case TokenTypeId.ArrayElementAccess:
|
|
147
|
+
addRulesForParent(
|
|
148
|
+
TokenTypeId.ArrayElementAccess,
|
|
149
|
+
arrayElementAccessRules,
|
|
150
|
+
);
|
|
151
|
+
break;
|
|
152
|
+
case TokenTypeId.BinaryExpression:
|
|
153
|
+
addRulesForParent(TokenTypeId.BinaryExpression, binaryExpressionRules);
|
|
154
|
+
break;
|
|
155
|
+
case TokenTypeId.BitModifier:
|
|
156
|
+
addRulesForParent(TokenTypeId.BitModifier, bitModifierRules);
|
|
157
|
+
break;
|
|
158
|
+
case TokenTypeId.CaseClause:
|
|
159
|
+
addRulesForParent(TokenTypeId.CaseClause, caseClauseRules);
|
|
160
|
+
break;
|
|
161
|
+
case TokenTypeId.ClassDefinition:
|
|
162
|
+
addRulesForParent(TokenTypeId.ClassDefinition, classDefinitionRules);
|
|
163
|
+
break;
|
|
164
|
+
case TokenTypeId.ClassDeclaration:
|
|
165
|
+
addRulesForParent(TokenTypeId.ClassDeclaration, classDeclarationRules);
|
|
166
|
+
break;
|
|
167
|
+
case TokenTypeId.ClassId:
|
|
168
|
+
addRulesForParent(TokenTypeId.ClassId, classIdRules);
|
|
169
|
+
break;
|
|
170
|
+
case TokenTypeId.ClassIdRange:
|
|
171
|
+
addRulesForParent(TokenTypeId.ClassIdRange, classIdRangeRules);
|
|
172
|
+
break;
|
|
173
|
+
case TokenTypeId.ClassMemberAccess:
|
|
174
|
+
addRulesForParent(TokenTypeId.ClassMemberAccess, classMemberAccessRules);
|
|
175
|
+
break;
|
|
176
|
+
case TokenTypeId.CompoundStatement:
|
|
177
|
+
addRulesForParent(TokenTypeId.CompoundStatement, compoundStatementRules);
|
|
178
|
+
break;
|
|
179
|
+
case TokenTypeId.ComputedArrayDefinition:
|
|
180
|
+
addRulesForParent(
|
|
181
|
+
TokenTypeId.ComputedArrayDefinition,
|
|
182
|
+
computedArrayDefinitionRules,
|
|
183
|
+
);
|
|
184
|
+
break;
|
|
185
|
+
case TokenTypeId.ComputedElementaryTypeDefinition:
|
|
186
|
+
addRulesForParent(
|
|
187
|
+
TokenTypeId.ComputedElementaryTypeDefinition,
|
|
188
|
+
computedElementaryTypeRules,
|
|
189
|
+
);
|
|
190
|
+
break;
|
|
191
|
+
case TokenTypeId.DefaultClause:
|
|
192
|
+
addRulesForParent(TokenTypeId.DefaultClause, defaultClauseRules);
|
|
193
|
+
break;
|
|
194
|
+
case TokenTypeId.DoStatement:
|
|
195
|
+
addRulesForParent(TokenTypeId.DoStatement, doStatementRules);
|
|
196
|
+
break;
|
|
197
|
+
case TokenTypeId.ElementaryType:
|
|
198
|
+
addRulesForParent(TokenTypeId.ElementaryType, elementaryTypeRules);
|
|
199
|
+
break;
|
|
200
|
+
case TokenTypeId.ElementaryTypeDefinition:
|
|
201
|
+
addRulesForParent(
|
|
202
|
+
TokenTypeId.ElementaryTypeDefinition,
|
|
203
|
+
elementaryTypeDefinitionRules,
|
|
204
|
+
);
|
|
205
|
+
break;
|
|
206
|
+
case TokenTypeId.ElementaryTypeOutputValue:
|
|
207
|
+
addRulesForParent(
|
|
208
|
+
TokenTypeId.ElementaryTypeOutputValue,
|
|
209
|
+
elementaryTypeOutputValueRules,
|
|
210
|
+
);
|
|
211
|
+
break;
|
|
212
|
+
case TokenTypeId.ExpandableModifier:
|
|
213
|
+
addRulesForParent(
|
|
214
|
+
TokenTypeId.ExpandableModifier,
|
|
215
|
+
expandableModifierRules,
|
|
216
|
+
);
|
|
217
|
+
break;
|
|
218
|
+
case TokenTypeId.ExplicitArrayDimension:
|
|
219
|
+
addRulesForParent(
|
|
220
|
+
TokenTypeId.ExplicitArrayDimension,
|
|
221
|
+
explicitArrayDimensionRules,
|
|
222
|
+
);
|
|
223
|
+
break;
|
|
224
|
+
case TokenTypeId.ExpressionStatement:
|
|
225
|
+
addRulesForParent(
|
|
226
|
+
TokenTypeId.ExpressionStatement,
|
|
227
|
+
expressionStatementRules,
|
|
228
|
+
);
|
|
229
|
+
break;
|
|
230
|
+
case TokenTypeId.ExtendedClassIdRange:
|
|
231
|
+
addRulesForParent(
|
|
232
|
+
TokenTypeId.ExtendedClassIdRange,
|
|
233
|
+
extendedClassIdRangeRules,
|
|
234
|
+
);
|
|
235
|
+
break;
|
|
236
|
+
case TokenTypeId.ExtendsModifier:
|
|
237
|
+
addRulesForParent(TokenTypeId.ExtendsModifier, extendsModifierRules);
|
|
238
|
+
break;
|
|
239
|
+
case TokenTypeId.ForStatement:
|
|
240
|
+
addRulesForParent(TokenTypeId.ForStatement, forStatementRules);
|
|
241
|
+
break;
|
|
242
|
+
case TokenTypeId.IfStatement:
|
|
243
|
+
addRulesForParent(TokenTypeId.IfStatement, ifStatementRules);
|
|
244
|
+
break;
|
|
245
|
+
case TokenTypeId.ImplicitArrayDimension:
|
|
246
|
+
addRulesForParent(
|
|
247
|
+
TokenTypeId.ImplicitArrayDimension,
|
|
248
|
+
implicitArrayDimensionRules,
|
|
249
|
+
);
|
|
250
|
+
break;
|
|
251
|
+
case TokenTypeId.LengthAttribute:
|
|
252
|
+
addRulesForParent(TokenTypeId.LengthAttribute, lengthAttributeRules);
|
|
253
|
+
break;
|
|
254
|
+
case TokenTypeId.LengthofExpression:
|
|
255
|
+
addRulesForParent(
|
|
256
|
+
TokenTypeId.LengthofExpression,
|
|
257
|
+
lengthofExpressionRules,
|
|
258
|
+
);
|
|
259
|
+
break;
|
|
260
|
+
case TokenTypeId.MapDeclaration:
|
|
261
|
+
addRulesForParent(TokenTypeId.MapDeclaration, mapDeclarationRules);
|
|
262
|
+
break;
|
|
263
|
+
case TokenTypeId.MapDefinition:
|
|
264
|
+
addRulesForParent(TokenTypeId.MapDefinition, mapDefinitionRules);
|
|
265
|
+
break;
|
|
266
|
+
case TokenTypeId.MapEntry:
|
|
267
|
+
addRulesForParent(TokenTypeId.MapEntry, mapEntryRules);
|
|
268
|
+
break;
|
|
269
|
+
case TokenTypeId.Parameter:
|
|
270
|
+
addRulesForParent(TokenTypeId.Parameter, parameterRules);
|
|
271
|
+
break;
|
|
272
|
+
case TokenTypeId.ParameterList:
|
|
273
|
+
addRulesForParent(TokenTypeId.ParameterList, parameterListRules);
|
|
274
|
+
break;
|
|
275
|
+
case TokenTypeId.ParameterValueList:
|
|
276
|
+
addRulesForParent(
|
|
277
|
+
TokenTypeId.ParameterValueList,
|
|
278
|
+
parameterValueListRules,
|
|
279
|
+
);
|
|
280
|
+
break;
|
|
281
|
+
case TokenTypeId.PartialArrayDimension:
|
|
282
|
+
addRulesForParent(
|
|
283
|
+
TokenTypeId.PartialArrayDimension,
|
|
284
|
+
partialArrayDimensionRules,
|
|
285
|
+
);
|
|
286
|
+
break;
|
|
287
|
+
case TokenTypeId.StringDefinition:
|
|
288
|
+
addRulesForParent(TokenTypeId.StringDefinition, stringDefinitionRules);
|
|
289
|
+
break;
|
|
290
|
+
case TokenTypeId.Specification:
|
|
291
|
+
addRulesForParent(TokenTypeId.Specification, specificationRules);
|
|
292
|
+
break;
|
|
293
|
+
case TokenTypeId.SwitchStatement:
|
|
294
|
+
addRulesForParent(TokenTypeId.SwitchStatement, switchStatementRules);
|
|
295
|
+
break;
|
|
296
|
+
case TokenTypeId.UnaryExpression:
|
|
297
|
+
addRulesForParent(TokenTypeId.UnaryExpression, unaryExpressionRules);
|
|
298
|
+
break;
|
|
299
|
+
case TokenTypeId.UtfStringLiteral:
|
|
300
|
+
addRulesForParent(TokenTypeId.UtfStringLiteral, utfStringLiteralRules);
|
|
301
|
+
break;
|
|
302
|
+
case TokenTypeId.WhileStatement:
|
|
303
|
+
addRulesForParent(TokenTypeId.WhileStatement, whileStatementRules);
|
|
304
|
+
break;
|
|
305
|
+
// Tokens that do not require completion rules
|
|
306
|
+
case TokenTypeId._break:
|
|
307
|
+
case TokenTypeId._case:
|
|
308
|
+
case TokenTypeId._class:
|
|
309
|
+
case TokenTypeId._const:
|
|
310
|
+
case TokenTypeId._default:
|
|
311
|
+
case TokenTypeId._do:
|
|
312
|
+
case TokenTypeId._else:
|
|
313
|
+
case TokenTypeId._extends:
|
|
314
|
+
case TokenTypeId._for:
|
|
315
|
+
case TokenTypeId._if:
|
|
316
|
+
case TokenTypeId._switch:
|
|
317
|
+
case TokenTypeId._while:
|
|
318
|
+
case TokenTypeId.abstract:
|
|
319
|
+
case TokenTypeId.Addition:
|
|
320
|
+
case TokenTypeId.AlignmentBitCount8:
|
|
321
|
+
case TokenTypeId.AlignmentBitCount16:
|
|
322
|
+
case TokenTypeId.AlignmentBitCount32:
|
|
323
|
+
case TokenTypeId.AlignmentBitCount64:
|
|
324
|
+
case TokenTypeId.AlignmentBitCount128:
|
|
325
|
+
case TokenTypeId.aligned:
|
|
326
|
+
case TokenTypeId.Assignment:
|
|
327
|
+
case TokenTypeId.base64string:
|
|
328
|
+
case TokenTypeId.Base64StringLiteral:
|
|
329
|
+
case TokenTypeId.Base64StringLiteralCharacters:
|
|
330
|
+
case TokenTypeId.BinaryLiteral:
|
|
331
|
+
case TokenTypeId.bit:
|
|
332
|
+
case TokenTypeId.BitwiseAnd:
|
|
333
|
+
case TokenTypeId.BitwiseOr:
|
|
334
|
+
case TokenTypeId.BitwiseShiftLeft:
|
|
335
|
+
case TokenTypeId.BitwiseShiftRight:
|
|
336
|
+
case TokenTypeId.CloseBrace:
|
|
337
|
+
case TokenTypeId.CloseBracket:
|
|
338
|
+
case TokenTypeId.CloseParenthesis:
|
|
339
|
+
case TokenTypeId.Colon:
|
|
340
|
+
case TokenTypeId.Comma:
|
|
341
|
+
case TokenTypeId.Comment:
|
|
342
|
+
case TokenTypeId.computed:
|
|
343
|
+
case TokenTypeId.DecimalLiteral:
|
|
344
|
+
case TokenTypeId.Division:
|
|
345
|
+
case TokenTypeId.DoubleQuote:
|
|
346
|
+
case TokenTypeId.expandable:
|
|
347
|
+
case TokenTypeId.float:
|
|
348
|
+
case TokenTypeId.FloatingPointLiteral:
|
|
349
|
+
case TokenTypeId.HexadecimalLiteral:
|
|
350
|
+
case TokenTypeId.Identifier:
|
|
351
|
+
case TokenTypeId.int:
|
|
352
|
+
case TokenTypeId.IntegerLiteral:
|
|
353
|
+
case TokenTypeId.legacy:
|
|
354
|
+
case TokenTypeId.lengthof:
|
|
355
|
+
case TokenTypeId.LogicalAnd:
|
|
356
|
+
case TokenTypeId.LogicalOr:
|
|
357
|
+
case TokenTypeId.LookAhead:
|
|
358
|
+
case TokenTypeId.map:
|
|
359
|
+
case TokenTypeId.Modulus:
|
|
360
|
+
case TokenTypeId.MultipleCharacterLiteral:
|
|
361
|
+
case TokenTypeId.MultipleCharacterLiteralCharacters:
|
|
362
|
+
case TokenTypeId.Multiplication:
|
|
363
|
+
case TokenTypeId.OpenBrace:
|
|
364
|
+
case TokenTypeId.OpenBracket:
|
|
365
|
+
case TokenTypeId.OpenParenthesis:
|
|
366
|
+
case TokenTypeId.Period:
|
|
367
|
+
case TokenTypeId.PostfixDecrement:
|
|
368
|
+
case TokenTypeId.PostfixIncrement:
|
|
369
|
+
case TokenTypeId.RangeOperator:
|
|
370
|
+
case TokenTypeId.reserved:
|
|
371
|
+
case TokenTypeId.RelationalEqual:
|
|
372
|
+
case TokenTypeId.RelationalGreaterThan:
|
|
373
|
+
case TokenTypeId.RelationalGreaterThanOrEqual:
|
|
374
|
+
case TokenTypeId.RelationalLessThan:
|
|
375
|
+
case TokenTypeId.RelationalLessThanOrEqual:
|
|
376
|
+
case TokenTypeId.RelationalNotEqual:
|
|
377
|
+
case TokenTypeId.Semicolon:
|
|
378
|
+
case TokenTypeId.SingleQuote:
|
|
379
|
+
case TokenTypeId.Subtraction:
|
|
380
|
+
case TokenTypeId.UnaryNegation:
|
|
381
|
+
case TokenTypeId.UnaryPlus:
|
|
382
|
+
case TokenTypeId.unsigned:
|
|
383
|
+
case TokenTypeId.utf16string:
|
|
384
|
+
case TokenTypeId.utf8list:
|
|
385
|
+
case TokenTypeId.utf8string:
|
|
386
|
+
case TokenTypeId.utfstring:
|
|
387
|
+
case TokenTypeId.UtfPrefix:
|
|
388
|
+
case TokenTypeId.UtfStringLiteralCharacters:
|
|
389
|
+
case TokenTypeId.Whitespace:
|
|
390
|
+
break;
|
|
391
|
+
default: {
|
|
392
|
+
const exhaustiveCheck: never = tokenTypeId;
|
|
393
|
+
throw new InternalScannerError(
|
|
394
|
+
"Unreachable code reached, tokenTypeId == " + exhaustiveCheck,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// now build the potentialSyntacticTokensByTokenTypeId map
|
|
401
|
+
// get the potential starting syntactic tokens for each token type ID
|
|
402
|
+
Object.values(TokenTypeId).forEach((tokenTypeId) => {
|
|
403
|
+
const resolvedTokenTypeIds: Set<number> = new Set();
|
|
404
|
+
|
|
405
|
+
const resolveTokenTypeId = (tokenTypeId: number) => {
|
|
406
|
+
if (completionRulesByParentMap.has(tokenTypeId)) {
|
|
407
|
+
// recurse
|
|
408
|
+
const childHierarchicalSearch = completionRulesByParentMap.get(
|
|
409
|
+
tokenTypeId,
|
|
410
|
+
)!;
|
|
411
|
+
const childPotentialTokenTypeIds = childHierarchicalSearch.get([-1]);
|
|
412
|
+
|
|
413
|
+
if (childPotentialTokenTypeIds) {
|
|
414
|
+
for (const childTokenTypeId of childPotentialTokenTypeIds) {
|
|
415
|
+
resolveTokenTypeId(childTokenTypeId);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
// this should be a syntactic token type ID
|
|
420
|
+
resolvedTokenTypeIds.add(tokenTypeId);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
resolveTokenTypeId(tokenTypeId);
|
|
425
|
+
|
|
426
|
+
if (resolvedTokenTypeIds.size > 0) {
|
|
427
|
+
// now convert the resolvedTokenTypeIds to syntactic token strings and order them
|
|
428
|
+
const syntacticTokens: string[] = [];
|
|
429
|
+
|
|
430
|
+
for (const tokenTypeId of resolvedTokenTypeIds) {
|
|
431
|
+
const syntaxString = tokenIdToSyntaxStringMapping.get(tokenTypeId);
|
|
432
|
+
if (syntaxString) {
|
|
433
|
+
syntacticTokens.push(syntaxString);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
syntacticTokens.sort();
|
|
438
|
+
|
|
439
|
+
potentialSyntacticTokensByTokenTypeId.set(tokenTypeId, syntacticTokens);
|
|
440
|
+
|
|
441
|
+
logger.debug(
|
|
442
|
+
`Added potential syntactic tokens for parent token ${
|
|
443
|
+
nodeTypes[tokenTypeId].name
|
|
444
|
+
}: ${syntacticTokens.join(" ")}`,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { TreeCursor } from "@lezer/common";
|
|
2
|
+
import { getPotentialTokenTypeIds } from "./get-potential-token-type-ids.ts";
|
|
3
|
+
import { potentialSyntacticTokensByTokenTypeId } from "./completion-rules.ts";
|
|
4
|
+
import getLogger from "../util/logger.ts";
|
|
5
|
+
|
|
6
|
+
const logger = getLogger("getPotentialSyntacticTokens");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Given a TreeCursor positioned at a node, returns the potential syntactic tokens at that position.
|
|
10
|
+
*
|
|
11
|
+
* @param cursor A TreeCursor positioned at a node.
|
|
12
|
+
*
|
|
13
|
+
* @returns An array of potential syntactic tokens, or undefined if none found.
|
|
14
|
+
*/
|
|
15
|
+
export function getPotentialSyntacticTokens(
|
|
16
|
+
cursor: TreeCursor,
|
|
17
|
+
): string[] | undefined {
|
|
18
|
+
const potentialTokenTypeIds = getPotentialTokenTypeIds(cursor);
|
|
19
|
+
|
|
20
|
+
if (!potentialTokenTypeIds || (potentialTokenTypeIds.length === 0)) {
|
|
21
|
+
logger.debug(
|
|
22
|
+
"No potentialTokenTypeIds so no potential syntactic tokens",
|
|
23
|
+
);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const potentialSyntacticTokens: string[] = [];
|
|
28
|
+
|
|
29
|
+
potentialTokenTypeIds.forEach((potentialTokenTypeId) => {
|
|
30
|
+
const syntacticTokens = potentialSyntacticTokensByTokenTypeId.get(
|
|
31
|
+
potentialTokenTypeId,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (syntacticTokens) {
|
|
35
|
+
potentialSyntacticTokens.push(...syntacticTokens);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (potentialSyntacticTokens.length === 0) {
|
|
40
|
+
logger.debug(
|
|
41
|
+
"No potential syntactic tokens",
|
|
42
|
+
);
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// sort and remove duplicates
|
|
47
|
+
const uniqueSortedTokens = Array.from(new Set(potentialSyntacticTokens))
|
|
48
|
+
.sort();
|
|
49
|
+
|
|
50
|
+
logger.debug(
|
|
51
|
+
`Potential syntactic tokens: ${uniqueSortedTokens.join(" ")}`,
|
|
52
|
+
);
|
|
53
|
+
return uniqueSortedTokens;
|
|
54
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { NodeType, TreeCursor } from "@lezer/common";
|
|
2
|
+
import { completionRulesByParentMap } from "./completion-rules.ts";
|
|
3
|
+
import getLogger from "../util/logger.ts";
|
|
4
|
+
|
|
5
|
+
// Generated by Lezer from the SDL grammar
|
|
6
|
+
import * as TokenTypeId from "../lezer/parser.terms.ts";
|
|
7
|
+
import { parser } from "../lezer/parser.ts";
|
|
8
|
+
|
|
9
|
+
const nodeTypes = parser.nodeSet.types;
|
|
10
|
+
|
|
11
|
+
const logger = getLogger("getPotentialTokenTypeIds");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Given a TreeCursor positioned at a node, returns the potential token types at that position.
|
|
15
|
+
*
|
|
16
|
+
* @param cursor The TreeCursor positioned at a node.
|
|
17
|
+
*
|
|
18
|
+
* @returns An array of potential NodeType IDs, or undefined if none found.
|
|
19
|
+
*/
|
|
20
|
+
export function getPotentialTokenTypeIds(
|
|
21
|
+
cursor: TreeCursor,
|
|
22
|
+
): number[] | undefined {
|
|
23
|
+
// No potential tokens if currently on a comment
|
|
24
|
+
if (cursor.type.id === TokenTypeId.Comment) {
|
|
25
|
+
logger.debug("No potential tokens in comments");
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// firstly clone the cursor to avoid breaking the traversal of the original cursor
|
|
30
|
+
const parentCursorClone = cursor.node.cursor();
|
|
31
|
+
const siblingCursorClone = cursor.node.cursor();
|
|
32
|
+
|
|
33
|
+
// look for parent token type, ignoring whitespace and errors
|
|
34
|
+
const parentTokenTypesIds: number[] = [];
|
|
35
|
+
|
|
36
|
+
while (parentCursorClone.parent()) {
|
|
37
|
+
if (
|
|
38
|
+
(parentCursorClone.type.id !== TokenTypeId.Whitespace) &&
|
|
39
|
+
!parentCursorClone.type.isError
|
|
40
|
+
) {
|
|
41
|
+
parentTokenTypesIds.unshift(parentCursorClone.type.id);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (parentTokenTypesIds.length === 0) {
|
|
47
|
+
logger.debug("No parent token type found, assuming global scope");
|
|
48
|
+
parentTokenTypesIds.push(TokenTypeId.Specification);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// look for previous sibling token types, ignoring whitespace, errors and comments
|
|
52
|
+
const previousSiblingTokenTypes: NodeType[] = [];
|
|
53
|
+
|
|
54
|
+
while (siblingCursorClone.prevSibling()) {
|
|
55
|
+
if (
|
|
56
|
+
(siblingCursorClone.type.id !== TokenTypeId.Whitespace) &&
|
|
57
|
+
!siblingCursorClone.type.isError &&
|
|
58
|
+
(siblingCursorClone.type.id !== TokenTypeId.Comment)
|
|
59
|
+
) {
|
|
60
|
+
previousSiblingTokenTypes.unshift(siblingCursorClone.type);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
logger.debug(
|
|
65
|
+
"parentTokenTypes: " +
|
|
66
|
+
parentTokenTypesIds.map((id) => nodeTypes[id].name).join(", "),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (previousSiblingTokenTypes.length > 0) {
|
|
70
|
+
logger.debug(
|
|
71
|
+
"previousSiblingTokenTypes: " +
|
|
72
|
+
previousSiblingTokenTypes.map((type) => type.name).join(", "),
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
logger.debug("No previous sibling token type found");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const potentialCompletionRules = completionRulesByParentMap
|
|
79
|
+
.get(parentTokenTypesIds[parentTokenTypesIds.length - 1]);
|
|
80
|
+
|
|
81
|
+
if (!potentialCompletionRules) {
|
|
82
|
+
logger.debug(
|
|
83
|
+
"No expected tokens map found for parentTokenType: " +
|
|
84
|
+
nodeTypes[parentTokenTypesIds[parentTokenTypesIds.length - 1]].name,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const potentialTokenTypes = potentialCompletionRules.get(
|
|
91
|
+
previousSiblingTokenTypes.length > 0
|
|
92
|
+
? [-1, ...previousSiblingTokenTypes.map((type) => type.id)]
|
|
93
|
+
: [-1],
|
|
94
|
+
);
|
|
95
|
+
if (!potentialTokenTypes || potentialTokenTypes.length === 0) {
|
|
96
|
+
logger.debug(
|
|
97
|
+
"No expected tokens found for parentTokenTypes: " +
|
|
98
|
+
parentTokenTypesIds.map((id) => nodeTypes[id].name).join(", ") +
|
|
99
|
+
(previousSiblingTokenTypes.length > 0
|
|
100
|
+
? " and previousSiblingTokenTypes: " +
|
|
101
|
+
previousSiblingTokenTypes.map((type) => type.name).join(", ")
|
|
102
|
+
: ""),
|
|
103
|
+
);
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// sort and remove duplicates
|
|
108
|
+
const uniqueSortedTokenTypes = Array.from(new Set(potentialTokenTypes)).sort((
|
|
109
|
+
a,
|
|
110
|
+
b,
|
|
111
|
+
) => a - b);
|
|
112
|
+
logger.debug(
|
|
113
|
+
`Potential token types: ${uniqueSortedTokenTypes.join(" ")}`,
|
|
114
|
+
);
|
|
115
|
+
return uniqueSortedTokenTypes;
|
|
116
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hierarchical search structure that allows for searching with progressively shorter suffixes of ID arrays.
|
|
3
|
+
*/
|
|
4
|
+
export class HierarchicalSearch<T> {
|
|
5
|
+
private store = new Map<string, T>();
|
|
6
|
+
|
|
7
|
+
constructor(initialData?: [number[], T][]) {
|
|
8
|
+
if (initialData) {
|
|
9
|
+
for (const [ids, value] of initialData) {
|
|
10
|
+
this.set(ids, value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private serializeKey(ids: number[]): string {
|
|
16
|
+
return ids.join(",");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set(ids: number[], value: T): void {
|
|
20
|
+
this.store.set(this.serializeKey(ids), value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get(ids: number[]): T | undefined {
|
|
24
|
+
// Try exact match first
|
|
25
|
+
const exactKey = this.serializeKey(ids);
|
|
26
|
+
|
|
27
|
+
if (this.store.has(exactKey)) {
|
|
28
|
+
return this.store.get(exactKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Try progressively shorter suffixes
|
|
32
|
+
for (let i = 1; i < ids.length; i++) {
|
|
33
|
+
const suffix = ids.slice(i);
|
|
34
|
+
const key = this.serializeKey(suffix);
|
|
35
|
+
|
|
36
|
+
if (this.store.has(key)) {
|
|
37
|
+
return this.store.get(key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|