@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,337 @@
|
|
|
1
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
2
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
3
|
+
|
|
4
|
+
// Generated by Lezer from the SDL grammar
|
|
5
|
+
import * as TokenTypeId from "../../../lezer/parser.terms.ts";
|
|
6
|
+
|
|
7
|
+
export const tokenKindByTokenTypeId: Map<number, TokenKind> = new Map();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Map parsed token type ID to AST token type enum.
|
|
11
|
+
* Exhaustive switch statement to ensure all token type IDs are handled.
|
|
12
|
+
*/
|
|
13
|
+
Object.values(TokenTypeId).forEach((tokenTypeId) => {
|
|
14
|
+
switch (tokenTypeId) {
|
|
15
|
+
case TokenTypeId._break:
|
|
16
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BREAK);
|
|
17
|
+
break;
|
|
18
|
+
case TokenTypeId._case:
|
|
19
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CASE);
|
|
20
|
+
break;
|
|
21
|
+
case TokenTypeId._class:
|
|
22
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CLASS);
|
|
23
|
+
break;
|
|
24
|
+
case TokenTypeId._const:
|
|
25
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CONST);
|
|
26
|
+
break;
|
|
27
|
+
case TokenTypeId._default:
|
|
28
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.DEFAULT);
|
|
29
|
+
break;
|
|
30
|
+
case TokenTypeId._do:
|
|
31
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.DO);
|
|
32
|
+
break;
|
|
33
|
+
case TokenTypeId._else:
|
|
34
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ELSE);
|
|
35
|
+
break;
|
|
36
|
+
case TokenTypeId._extends:
|
|
37
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.EXTENDS);
|
|
38
|
+
break;
|
|
39
|
+
case TokenTypeId._for:
|
|
40
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.FOR);
|
|
41
|
+
break;
|
|
42
|
+
case TokenTypeId._if:
|
|
43
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.IF);
|
|
44
|
+
break;
|
|
45
|
+
case TokenTypeId._switch:
|
|
46
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.SWITCH);
|
|
47
|
+
break;
|
|
48
|
+
case TokenTypeId._while:
|
|
49
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.WHILE);
|
|
50
|
+
break;
|
|
51
|
+
case TokenTypeId.abstract:
|
|
52
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ABSTRACT);
|
|
53
|
+
break;
|
|
54
|
+
case TokenTypeId.Addition:
|
|
55
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ADDITION);
|
|
56
|
+
break;
|
|
57
|
+
case TokenTypeId.AlignmentBitCount8:
|
|
58
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ALIGNMENT_BIT_COUNT_8);
|
|
59
|
+
break;
|
|
60
|
+
case TokenTypeId.AlignmentBitCount16:
|
|
61
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ALIGNMENT_BIT_COUNT_16);
|
|
62
|
+
break;
|
|
63
|
+
case TokenTypeId.AlignmentBitCount32:
|
|
64
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ALIGNMENT_BIT_COUNT_32);
|
|
65
|
+
break;
|
|
66
|
+
case TokenTypeId.AlignmentBitCount64:
|
|
67
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ALIGNMENT_BIT_COUNT_64);
|
|
68
|
+
break;
|
|
69
|
+
case TokenTypeId.AlignmentBitCount128:
|
|
70
|
+
tokenKindByTokenTypeId.set(
|
|
71
|
+
tokenTypeId,
|
|
72
|
+
TokenKind.ALIGNMENT_BIT_COUNT_128,
|
|
73
|
+
);
|
|
74
|
+
break;
|
|
75
|
+
case TokenTypeId.aligned:
|
|
76
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ALIGNED);
|
|
77
|
+
break;
|
|
78
|
+
case TokenTypeId.Assignment:
|
|
79
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.ASSIGNMENT);
|
|
80
|
+
break;
|
|
81
|
+
case TokenTypeId.base64string:
|
|
82
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BASE64_STRING);
|
|
83
|
+
break;
|
|
84
|
+
case TokenTypeId.Base64StringLiteralCharacters:
|
|
85
|
+
tokenKindByTokenTypeId.set(
|
|
86
|
+
tokenTypeId,
|
|
87
|
+
TokenKind.BASE64_STRING_LITERAL_CHARACTERS,
|
|
88
|
+
);
|
|
89
|
+
break;
|
|
90
|
+
case TokenTypeId.BinaryLiteral:
|
|
91
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BINARY_LITERAL);
|
|
92
|
+
break;
|
|
93
|
+
case TokenTypeId.bit:
|
|
94
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BIT);
|
|
95
|
+
break;
|
|
96
|
+
case TokenTypeId.BitwiseAnd:
|
|
97
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BITWISE_AND);
|
|
98
|
+
break;
|
|
99
|
+
case TokenTypeId.BitwiseOr:
|
|
100
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BITWISE_OR);
|
|
101
|
+
break;
|
|
102
|
+
case TokenTypeId.BitwiseShiftLeft:
|
|
103
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BITWISE_SHIFT_LEFT);
|
|
104
|
+
break;
|
|
105
|
+
case TokenTypeId.BitwiseShiftRight:
|
|
106
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.BITWISE_SHIFT_RIGHT);
|
|
107
|
+
break;
|
|
108
|
+
case TokenTypeId.CloseBrace:
|
|
109
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CLOSE_BRACE);
|
|
110
|
+
break;
|
|
111
|
+
case TokenTypeId.CloseBracket:
|
|
112
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CLOSE_BRACKET);
|
|
113
|
+
break;
|
|
114
|
+
case TokenTypeId.CloseParenthesis:
|
|
115
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.CLOSE_PARENTHESIS);
|
|
116
|
+
break;
|
|
117
|
+
case TokenTypeId.Colon:
|
|
118
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.COLON);
|
|
119
|
+
break;
|
|
120
|
+
case TokenTypeId.Comma:
|
|
121
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.COMMA);
|
|
122
|
+
break;
|
|
123
|
+
case TokenTypeId.computed:
|
|
124
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.COMPUTED);
|
|
125
|
+
break;
|
|
126
|
+
case TokenTypeId.DecimalLiteral:
|
|
127
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.DECIMAL_LITERAL);
|
|
128
|
+
break;
|
|
129
|
+
case TokenTypeId.Division:
|
|
130
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.DIVISION);
|
|
131
|
+
break;
|
|
132
|
+
case TokenTypeId.DoubleQuote:
|
|
133
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.DOUBLE_QUOTE);
|
|
134
|
+
break;
|
|
135
|
+
case TokenTypeId.expandable:
|
|
136
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.EXPANDABLE);
|
|
137
|
+
break;
|
|
138
|
+
case TokenTypeId.float:
|
|
139
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.FLOAT);
|
|
140
|
+
break;
|
|
141
|
+
case TokenTypeId.FloatingPointLiteral:
|
|
142
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.FLOATING_POINT_LITERAL);
|
|
143
|
+
break;
|
|
144
|
+
case TokenTypeId.HexadecimalLiteral:
|
|
145
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.HEXADECIMAL_LITERAL);
|
|
146
|
+
break;
|
|
147
|
+
case TokenTypeId.Identifier:
|
|
148
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.IDENTIFIER);
|
|
149
|
+
break;
|
|
150
|
+
case TokenTypeId.int:
|
|
151
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.INT);
|
|
152
|
+
break;
|
|
153
|
+
case TokenTypeId.IntegerLiteral:
|
|
154
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.INTEGER_LITERAL);
|
|
155
|
+
break;
|
|
156
|
+
case TokenTypeId.legacy:
|
|
157
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.LEGACY);
|
|
158
|
+
break;
|
|
159
|
+
case TokenTypeId.lengthof:
|
|
160
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.LENGTHOF);
|
|
161
|
+
break;
|
|
162
|
+
case TokenTypeId.LogicalAnd:
|
|
163
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.LOGICAL_AND);
|
|
164
|
+
break;
|
|
165
|
+
case TokenTypeId.LogicalOr:
|
|
166
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.LOGICAL_OR);
|
|
167
|
+
break;
|
|
168
|
+
case TokenTypeId.LookAhead:
|
|
169
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.LOOK_AHEAD);
|
|
170
|
+
break;
|
|
171
|
+
case TokenTypeId.map:
|
|
172
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.MAP);
|
|
173
|
+
break;
|
|
174
|
+
case TokenTypeId.Modulus:
|
|
175
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.MODULUS);
|
|
176
|
+
break;
|
|
177
|
+
case TokenTypeId.MultipleCharacterLiteralCharacters:
|
|
178
|
+
tokenKindByTokenTypeId.set(
|
|
179
|
+
tokenTypeId,
|
|
180
|
+
TokenKind.MULTIPLE_CHARACTER_LITERAL_CHARACTERS,
|
|
181
|
+
);
|
|
182
|
+
break;
|
|
183
|
+
case TokenTypeId.Multiplication:
|
|
184
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.MULTIPLICATION);
|
|
185
|
+
break;
|
|
186
|
+
case TokenTypeId.OpenBrace:
|
|
187
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.OPEN_BRACE);
|
|
188
|
+
break;
|
|
189
|
+
case TokenTypeId.OpenBracket:
|
|
190
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.OPEN_BRACKET);
|
|
191
|
+
break;
|
|
192
|
+
case TokenTypeId.OpenParenthesis:
|
|
193
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.OPEN_PARENTHESIS);
|
|
194
|
+
break;
|
|
195
|
+
case TokenTypeId.Period:
|
|
196
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.PERIOD);
|
|
197
|
+
break;
|
|
198
|
+
case TokenTypeId.PostfixDecrement:
|
|
199
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.POSTFIX_DECREMENT);
|
|
200
|
+
break;
|
|
201
|
+
case TokenTypeId.PostfixIncrement:
|
|
202
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.POSTFIX_INCREMENT);
|
|
203
|
+
break;
|
|
204
|
+
case TokenTypeId.RangeOperator:
|
|
205
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.RANGE_OPERATOR);
|
|
206
|
+
break;
|
|
207
|
+
case TokenTypeId.reserved:
|
|
208
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.RESERVED);
|
|
209
|
+
break;
|
|
210
|
+
case TokenTypeId.RelationalEqual:
|
|
211
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.RELATIONAL_EQUAL);
|
|
212
|
+
break;
|
|
213
|
+
case TokenTypeId.RelationalGreaterThan:
|
|
214
|
+
tokenKindByTokenTypeId.set(
|
|
215
|
+
tokenTypeId,
|
|
216
|
+
TokenKind.RELATIONAL_GREATER_THAN,
|
|
217
|
+
);
|
|
218
|
+
break;
|
|
219
|
+
case TokenTypeId.RelationalGreaterThanOrEqual:
|
|
220
|
+
tokenKindByTokenTypeId.set(
|
|
221
|
+
tokenTypeId,
|
|
222
|
+
TokenKind.RELATIONAL_GREATER_THAN_OR_EQUAL,
|
|
223
|
+
);
|
|
224
|
+
break;
|
|
225
|
+
case TokenTypeId.RelationalLessThan:
|
|
226
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.RELATIONAL_LESS_THAN);
|
|
227
|
+
break;
|
|
228
|
+
case TokenTypeId.RelationalLessThanOrEqual:
|
|
229
|
+
tokenKindByTokenTypeId.set(
|
|
230
|
+
tokenTypeId,
|
|
231
|
+
TokenKind.RELATIONAL_LESS_THAN_OR_EQUAL,
|
|
232
|
+
);
|
|
233
|
+
break;
|
|
234
|
+
case TokenTypeId.RelationalNotEqual:
|
|
235
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.RELATIONAL_NOT_EQUAL);
|
|
236
|
+
break;
|
|
237
|
+
case TokenTypeId.Semicolon:
|
|
238
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.SEMICOLON);
|
|
239
|
+
break;
|
|
240
|
+
case TokenTypeId.SingleQuote:
|
|
241
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.SINGLE_QUOTE);
|
|
242
|
+
break;
|
|
243
|
+
case TokenTypeId.Subtraction:
|
|
244
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.SUBTRACTION);
|
|
245
|
+
break;
|
|
246
|
+
case TokenTypeId.UnaryNegation:
|
|
247
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UNARY_NEGATION);
|
|
248
|
+
break;
|
|
249
|
+
case TokenTypeId.UnaryPlus:
|
|
250
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UNARY_PLUS);
|
|
251
|
+
break;
|
|
252
|
+
case TokenTypeId.unsigned:
|
|
253
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UNSIGNED);
|
|
254
|
+
break;
|
|
255
|
+
case TokenTypeId.utf16string:
|
|
256
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UTF16_STRING);
|
|
257
|
+
break;
|
|
258
|
+
case TokenTypeId.utf8list:
|
|
259
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UTF8_LIST);
|
|
260
|
+
break;
|
|
261
|
+
case TokenTypeId.utf8string:
|
|
262
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UTF8_STRING);
|
|
263
|
+
break;
|
|
264
|
+
case TokenTypeId.utfstring:
|
|
265
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UTF_STRING);
|
|
266
|
+
break;
|
|
267
|
+
case TokenTypeId.UtfPrefix:
|
|
268
|
+
tokenKindByTokenTypeId.set(tokenTypeId, TokenKind.UTF_PREFIX);
|
|
269
|
+
break;
|
|
270
|
+
case TokenTypeId.UtfStringLiteralCharacters:
|
|
271
|
+
tokenKindByTokenTypeId.set(
|
|
272
|
+
tokenTypeId,
|
|
273
|
+
TokenKind.UTF_STRING_LITERAL_CHARACTERS,
|
|
274
|
+
);
|
|
275
|
+
break;
|
|
276
|
+
|
|
277
|
+
// Parser tokens that do not map to AST TokenKinds
|
|
278
|
+
case TokenTypeId.AlignedModifier:
|
|
279
|
+
case TokenTypeId.AggregateOutputValue:
|
|
280
|
+
case TokenTypeId.ArrayDefinition:
|
|
281
|
+
case TokenTypeId.AssignmentExpression:
|
|
282
|
+
case TokenTypeId.ArrayElementAccess:
|
|
283
|
+
case TokenTypeId.Base64StringLiteral:
|
|
284
|
+
case TokenTypeId.BinaryExpression:
|
|
285
|
+
case TokenTypeId.BitModifier:
|
|
286
|
+
case TokenTypeId.CaseClause:
|
|
287
|
+
case TokenTypeId.ClassDefinition:
|
|
288
|
+
case TokenTypeId.ClassDeclaration:
|
|
289
|
+
case TokenTypeId.ClassId:
|
|
290
|
+
case TokenTypeId.ClassIdRange:
|
|
291
|
+
case TokenTypeId.ClassMemberAccess:
|
|
292
|
+
case TokenTypeId.Comment:
|
|
293
|
+
case TokenTypeId.CompoundStatement:
|
|
294
|
+
case TokenTypeId.ComputedArrayDefinition:
|
|
295
|
+
case TokenTypeId.ComputedElementaryTypeDefinition:
|
|
296
|
+
case TokenTypeId.DefaultClause:
|
|
297
|
+
case TokenTypeId.DoStatement:
|
|
298
|
+
case TokenTypeId.ElementaryType:
|
|
299
|
+
case TokenTypeId.ElementaryTypeDefinition:
|
|
300
|
+
case TokenTypeId.ElementaryTypeOutputValue:
|
|
301
|
+
case TokenTypeId.ExpandableModifier:
|
|
302
|
+
case TokenTypeId.ExplicitArrayDimension:
|
|
303
|
+
case TokenTypeId.ExpressionStatement:
|
|
304
|
+
case TokenTypeId.ExtendedClassIdRange:
|
|
305
|
+
case TokenTypeId.ExtendsModifier:
|
|
306
|
+
case TokenTypeId.ForStatement:
|
|
307
|
+
case TokenTypeId.IfStatement:
|
|
308
|
+
case TokenTypeId.ImplicitArrayDimension:
|
|
309
|
+
case TokenTypeId.LengthAttribute:
|
|
310
|
+
case TokenTypeId.LengthofExpression:
|
|
311
|
+
case TokenTypeId.MapDeclaration:
|
|
312
|
+
case TokenTypeId.MapDefinition:
|
|
313
|
+
case TokenTypeId.MapEntry:
|
|
314
|
+
case TokenTypeId.MultipleCharacterLiteral:
|
|
315
|
+
case TokenTypeId.Parameter:
|
|
316
|
+
case TokenTypeId.ParameterList:
|
|
317
|
+
case TokenTypeId.ParameterValueList:
|
|
318
|
+
case TokenTypeId.PartialArrayDimension:
|
|
319
|
+
case TokenTypeId.Specification:
|
|
320
|
+
case TokenTypeId.StringDefinition:
|
|
321
|
+
case TokenTypeId.SwitchStatement:
|
|
322
|
+
case TokenTypeId.UnaryExpression:
|
|
323
|
+
case TokenTypeId.UtfStringLiteral:
|
|
324
|
+
case TokenTypeId.WhileStatement:
|
|
325
|
+
case TokenTypeId.Whitespace:
|
|
326
|
+
break;
|
|
327
|
+
default: {
|
|
328
|
+
const exhaustiveCheck: never = tokenTypeId;
|
|
329
|
+
throw new InternalScannerError(
|
|
330
|
+
"Unreachable code reached, tokenTypeId == " + exhaustiveCheck,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Add mapping for unknown token
|
|
337
|
+
tokenKindByTokenTypeId.set(0, TokenKind.ERROR_UNKNOWN_TOKEN);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Tree } from "@lezer/common";
|
|
2
|
+
import { Text } from "@codemirror/state";
|
|
3
|
+
import type { SdlStringInput } from "../lezer/sdl-string-input.ts";
|
|
4
|
+
import type { Specification } from "./node/specification.ts";
|
|
5
|
+
import { debugEnabled } from "../util/logger.ts";
|
|
6
|
+
import type { NodeHandler } from "./visitor/node-handler.ts";
|
|
7
|
+
import { TraversingVisitor } from "./visitor/traversing-visitor.ts";
|
|
8
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
9
|
+
import type { BuildContext } from "./build/util/build-context.ts";
|
|
10
|
+
import type { RequiredNode } from "./util/types.ts";
|
|
11
|
+
import { fetchRequiredNode } from "./build/util/fetch-node.ts";
|
|
12
|
+
import { NodeKind } from "./node/enum/node-kind.ts";
|
|
13
|
+
import { nodeKindByTokenTypeId } from "./build/util/node-kind-by-token-type-id-map.ts";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Process the SDL parse tree and return an abstract syntax tree.
|
|
17
|
+
*
|
|
18
|
+
* @param parseTree The parse `Tree` generated from the SDL source.
|
|
19
|
+
* @param sdlStringInput The SDL source text as an `SdlStringInput`.
|
|
20
|
+
* @param lenient If true, the AST construction will be lenient and create error tokens and nodes for parse errors in the parse tree.
|
|
21
|
+
*/
|
|
22
|
+
export function buildAst(
|
|
23
|
+
parseTree: Tree,
|
|
24
|
+
sdlStringInput: SdlStringInput,
|
|
25
|
+
lenient = false,
|
|
26
|
+
): RequiredNode<Specification> {
|
|
27
|
+
const text = Text.of(
|
|
28
|
+
sdlStringInput.read(0, sdlStringInput.length).split("\n"),
|
|
29
|
+
);
|
|
30
|
+
const cursor = parseTree.cursor();
|
|
31
|
+
const buildContext: BuildContext = {
|
|
32
|
+
cursor,
|
|
33
|
+
text,
|
|
34
|
+
lenient,
|
|
35
|
+
stateStack: [{ indent: "", isEndOfSiblings: false }],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const nodeKind = nodeKindByTokenTypeId.get(cursor.type.id);
|
|
39
|
+
|
|
40
|
+
if (nodeKind === undefined) {
|
|
41
|
+
throw new InternalScannerError(
|
|
42
|
+
`No nodeKind mapping found for token type id: ${cursor.type.id} (${cursor.type.name})`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// check the root node is a Specification
|
|
47
|
+
if (nodeKind !== NodeKind.SPECIFICATION) {
|
|
48
|
+
throw new InternalScannerError(
|
|
49
|
+
`Expected start node to be a Specification, but found ${
|
|
50
|
+
NodeKind[nodeKind]
|
|
51
|
+
}.`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const specification = fetchRequiredNode<Specification>(
|
|
56
|
+
buildContext,
|
|
57
|
+
NodeKind.SPECIFICATION,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (buildContext.stateStack.length !== 1) {
|
|
61
|
+
throw new InternalScannerError(
|
|
62
|
+
`Expected final build context state stack length to be 1, but found ${buildContext.stateStack.length}.`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!specification) {
|
|
67
|
+
throw new InternalScannerError(
|
|
68
|
+
`Expected to parse a Specification node, but none was found.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ((nodeKind !== NodeKind.SPECIFICATION) && (!cursor.type.isError)) {
|
|
73
|
+
throw new InternalScannerError(
|
|
74
|
+
`Expected final node to be a Specification or an error, but found ${
|
|
75
|
+
NodeKind[nodeKind]
|
|
76
|
+
}.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// check if any unconsumed trivia remain which
|
|
81
|
+
if (buildContext.unconsumedTrivia) {
|
|
82
|
+
if (!specification.trailingTrivia) {
|
|
83
|
+
specification.trailingTrivia = [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// filter from the end any empty blank line trivia
|
|
87
|
+
while (
|
|
88
|
+
(buildContext.unconsumedTrivia.length > 0) &&
|
|
89
|
+
(buildContext.unconsumedTrivia[
|
|
90
|
+
buildContext.unconsumedTrivia.length - 1
|
|
91
|
+
].text.trim() === "")
|
|
92
|
+
) {
|
|
93
|
+
buildContext.unconsumedTrivia.pop();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
specification.trailingTrivia.push(
|
|
97
|
+
...buildContext.unconsumedTrivia,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
delete buildContext.unconsumedTrivia;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (debugEnabled) {
|
|
104
|
+
const dummyNodeHandler: NodeHandler = {
|
|
105
|
+
beforeVisit: () => {},
|
|
106
|
+
visit: () => {},
|
|
107
|
+
afterVisit: () => {},
|
|
108
|
+
};
|
|
109
|
+
const traversingVisitor = new TraversingVisitor(dummyNodeHandler);
|
|
110
|
+
traversingVisitor.visit(specification);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return specification;
|
|
114
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequiredNode } from "../util/types.ts";
|
|
2
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
3
|
+
import { AbstractStatement } from "./abstract-statement.ts";
|
|
4
|
+
import type { StatementKind } from "./enum/statement-kind.ts";
|
|
5
|
+
import type { Identifier } from "./identifier.ts";
|
|
6
|
+
import type { Token } from "./token.ts";
|
|
7
|
+
|
|
8
|
+
export abstract class AbstractArrayDefinition extends AbstractStatement {
|
|
9
|
+
constructor(
|
|
10
|
+
kind: StatementKind,
|
|
11
|
+
public readonly identifier: RequiredNode<Identifier>,
|
|
12
|
+
public readonly semicolonPunctuator: RequiredNode<Token>,
|
|
13
|
+
children: Array<AbstractNode>,
|
|
14
|
+
) {
|
|
15
|
+
super(kind, children);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequiredNode } from "../util/types.ts";
|
|
2
|
+
import { AbstractCompositeNode } from "./abstract-composite-node.ts";
|
|
3
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
4
|
+
import { ArrayDimensionKind } from "./enum/array-dimension-kind.ts";
|
|
5
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
6
|
+
import type { Token } from "./token.ts";
|
|
7
|
+
|
|
8
|
+
export abstract class AbstractArrayDimension extends AbstractCompositeNode {
|
|
9
|
+
constructor(
|
|
10
|
+
public readonly arrayDimensionKind: ArrayDimensionKind,
|
|
11
|
+
public readonly openBracketPunctuator: RequiredNode<Token>,
|
|
12
|
+
public readonly closeBracketPunctuator: RequiredNode<Token>,
|
|
13
|
+
children: Array<AbstractNode>,
|
|
14
|
+
) {
|
|
15
|
+
super(
|
|
16
|
+
NodeKind.ARRAY_DIMENSION,
|
|
17
|
+
children,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractCompositeNode } from "./abstract-composite-node.ts";
|
|
2
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
3
|
+
import { ClassIdKind } from "./enum/class-id-kind.ts";
|
|
4
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
5
|
+
|
|
6
|
+
export abstract class AbstractClassId extends AbstractCompositeNode {
|
|
7
|
+
constructor(
|
|
8
|
+
public readonly classIdKind: ClassIdKind,
|
|
9
|
+
children: Array<AbstractNode>,
|
|
10
|
+
) {
|
|
11
|
+
super(NodeKind.CLASS_ID, children);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Location } from "../../location.ts";
|
|
2
|
+
import { InternalScannerError } from "../../scanner-error.ts";
|
|
3
|
+
import { isCompositeNode, isToken } from "../util/types.ts";
|
|
4
|
+
import { AbstractNode } from "./abstract-node.ts";
|
|
5
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
6
|
+
import type { Token } from "./token.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents an abstract composite node in the abstract syntax tree.
|
|
10
|
+
* This class extends the `AbstractNode` class and provides a base for nodes
|
|
11
|
+
* that can have child nodes.
|
|
12
|
+
*/
|
|
13
|
+
export abstract class AbstractCompositeNode extends AbstractNode {
|
|
14
|
+
public startToken: Token | undefined;
|
|
15
|
+
public endToken: Token | undefined;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
nodeKind: NodeKind,
|
|
19
|
+
public readonly children: Array<AbstractNode>,
|
|
20
|
+
) {
|
|
21
|
+
super(nodeKind, true);
|
|
22
|
+
|
|
23
|
+
if (children.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const firstChild = children[0];
|
|
28
|
+
if (isCompositeNode(firstChild)) {
|
|
29
|
+
this.startToken = firstChild.startToken;
|
|
30
|
+
} else if (isToken(firstChild)) {
|
|
31
|
+
this.startToken = firstChild;
|
|
32
|
+
} else {
|
|
33
|
+
throw new InternalScannerError(
|
|
34
|
+
"Unsupported node type for start token assignment: " +
|
|
35
|
+
NodeKind[firstChild.nodeKind],
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const lastChild = children[children.length - 1];
|
|
39
|
+
if (isCompositeNode(lastChild)) {
|
|
40
|
+
this.endToken = lastChild.endToken;
|
|
41
|
+
} else if (isToken(lastChild)) {
|
|
42
|
+
this.endToken = lastChild;
|
|
43
|
+
} else {
|
|
44
|
+
throw new InternalScannerError(
|
|
45
|
+
"Unsupported node type for end token assignment: " +
|
|
46
|
+
NodeKind[lastChild.nodeKind],
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getLocation(): Location {
|
|
52
|
+
if (!this.startToken && !this.endToken) {
|
|
53
|
+
throw new InternalScannerError("Start and end token are undefined");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.startToken?.getLocation() ?? this.endToken!.getLocation();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OptionalNode, RequiredNode } from "../util/types.ts";
|
|
2
|
+
import type { AbstractExpression } from "./abstract-expression.ts";
|
|
3
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
4
|
+
import { AbstractStatement } from "./abstract-statement.ts";
|
|
5
|
+
import type { ElementaryType } from "./elementary-type.ts";
|
|
6
|
+
import type { StatementKind } from "./enum/statement-kind.ts";
|
|
7
|
+
import type { Identifier } from "./identifier.ts";
|
|
8
|
+
import type { NumberLiteral } from "./number-literal.ts";
|
|
9
|
+
import type { Token } from "./token.ts";
|
|
10
|
+
|
|
11
|
+
export abstract class AbstractElementaryTypeDefinition
|
|
12
|
+
extends AbstractStatement {
|
|
13
|
+
constructor(
|
|
14
|
+
kind: StatementKind,
|
|
15
|
+
public readonly constKeyword: OptionalNode<Token>,
|
|
16
|
+
public readonly elementaryType: RequiredNode<ElementaryType>,
|
|
17
|
+
public readonly identifier: RequiredNode<Identifier>,
|
|
18
|
+
public readonly assignmentOperator: OptionalNode<Token>,
|
|
19
|
+
public readonly value: OptionalNode<
|
|
20
|
+
| AbstractExpression
|
|
21
|
+
| NumberLiteral
|
|
22
|
+
| Identifier
|
|
23
|
+
>,
|
|
24
|
+
public readonly semicolonPunctuator: RequiredNode<Token>,
|
|
25
|
+
children: Array<AbstractNode>,
|
|
26
|
+
) {
|
|
27
|
+
super(kind, children);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractCompositeNode } from "./abstract-composite-node.ts";
|
|
2
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
3
|
+
import { ExpressionKind } from "./enum/expression-kind.ts";
|
|
4
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
5
|
+
|
|
6
|
+
export abstract class AbstractExpression extends AbstractCompositeNode {
|
|
7
|
+
constructor(
|
|
8
|
+
public readonly expressionKind: ExpressionKind,
|
|
9
|
+
children: AbstractNode[],
|
|
10
|
+
) {
|
|
11
|
+
super(NodeKind.EXPRESSION, children);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Location } from "../../location.ts";
|
|
2
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
3
|
+
import type { Trivia } from "./trivia.ts";
|
|
4
|
+
|
|
5
|
+
export abstract class AbstractNode {
|
|
6
|
+
public leadingTrivia: Trivia[] | undefined;
|
|
7
|
+
public trailingTrivia: Trivia[] | undefined;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
public readonly nodeKind: NodeKind,
|
|
11
|
+
public readonly isComposite: boolean,
|
|
12
|
+
) {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
abstract getLocation(): Location;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractCompositeNode } from "./abstract-composite-node.ts";
|
|
2
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
3
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
4
|
+
import { StatementKind } from "./enum/statement-kind.ts";
|
|
5
|
+
|
|
6
|
+
export abstract class AbstractStatement extends AbstractCompositeNode {
|
|
7
|
+
constructor(
|
|
8
|
+
public readonly statementKind: StatementKind,
|
|
9
|
+
public readonly children: Array<AbstractNode>,
|
|
10
|
+
) {
|
|
11
|
+
super(NodeKind.STATEMENT, children);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AbstractNode } from "./abstract-node.ts";
|
|
2
|
+
import { AbstractCompositeNode } from "./abstract-composite-node.ts";
|
|
3
|
+
import { NodeKind } from "./enum/node-kind.ts";
|
|
4
|
+
import type { NumberLiteral } from "./number-literal.ts";
|
|
5
|
+
import type { ElementaryTypeOutputValue } from "./elementary-type-output-value.ts";
|
|
6
|
+
import type { Token } from "./token.ts";
|
|
7
|
+
import type {
|
|
8
|
+
OneToManyList,
|
|
9
|
+
RequiredNode,
|
|
10
|
+
ZeroToManyList,
|
|
11
|
+
} from "../util/types.ts";
|
|
12
|
+
|
|
13
|
+
export class AggregateOutputValue extends AbstractCompositeNode {
|
|
14
|
+
constructor(
|
|
15
|
+
public readonly openBracePunctuator: RequiredNode<Token>,
|
|
16
|
+
public readonly outputValues: OneToManyList<
|
|
17
|
+
AggregateOutputValue | ElementaryTypeOutputValue | NumberLiteral
|
|
18
|
+
>,
|
|
19
|
+
public readonly commaPunctuators: ZeroToManyList<Token>,
|
|
20
|
+
public readonly closeBracePunctuator: RequiredNode<Token>,
|
|
21
|
+
children: Array<AbstractNode>,
|
|
22
|
+
) {
|
|
23
|
+
super(
|
|
24
|
+
NodeKind.AGGREGATE_OUTPUT_VALUE,
|
|
25
|
+
children,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|