@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,199 @@
|
|
|
1
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
2
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
3
|
+
import { createSyntaxErrorFromTextAndCursor } from "../../../lezer/create-syntax-error-from-text-and-cursor.ts";
|
|
4
|
+
import { primitiveNodeProp } from "../../../lezer/props/primitive-node-prop-source.ts";
|
|
5
|
+
import { buildToken } from "../node/build-token.ts";
|
|
6
|
+
import { consumeTrivia } from "./consume-trivia.ts";
|
|
7
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
8
|
+
import getLogger from "../../../util/logger.ts";
|
|
9
|
+
import { buildMissingError } from "../node/build-missing-error.ts";
|
|
10
|
+
import { consumePrimitive } from "./consume-primitive.ts";
|
|
11
|
+
import { consumeAstNode } from "./consume-ast-node.ts";
|
|
12
|
+
import { Specification } from "../../node/specification.ts";
|
|
13
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
14
|
+
import { tokenKindByTokenTypeId } from "../util/token-kind-by-token-type-id-map.ts";
|
|
15
|
+
import { nodeKindByTokenTypeId } from "../util/node-kind-by-token-type-id-map.ts";
|
|
16
|
+
import { UnexpectedError } from "../../node/unexpected-error.ts";
|
|
17
|
+
|
|
18
|
+
const logger = getLogger("consumeAbstractNode");
|
|
19
|
+
|
|
20
|
+
export enum NodeScenario {
|
|
21
|
+
/** Missing Error Node */
|
|
22
|
+
MISSING_NODE,
|
|
23
|
+
/** Unexpected Error Node containing a child which is the unexpected token */
|
|
24
|
+
UNEXPECTED_NODE,
|
|
25
|
+
/** Unknown Error Node which has text of an unknown token */
|
|
26
|
+
UNKNOWN_TOKEN,
|
|
27
|
+
/** Primitive Node e.g. Identifier, IntegerLiteral... */
|
|
28
|
+
PRIMITIVE,
|
|
29
|
+
/** Terminal Token Node e.g. class, int... */
|
|
30
|
+
TOKEN,
|
|
31
|
+
/** Non-Terminal AST Node e.g. ClassDeclaration, ExpressionStatement... */
|
|
32
|
+
AST_NODE,
|
|
33
|
+
/** Terminal AST Node with missing children e.g. ClassDeclaration, ExpressionStatement... */
|
|
34
|
+
EMPTY_AST_NODE,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function determineNodeScenario(
|
|
38
|
+
buildContext: BuildContext,
|
|
39
|
+
): NodeScenario {
|
|
40
|
+
const { cursor, text, lenient } = buildContext;
|
|
41
|
+
const isError = cursor.type.isError;
|
|
42
|
+
|
|
43
|
+
if (isError && !lenient) {
|
|
44
|
+
throw createSyntaxErrorFromTextAndCursor(text, cursor);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Check if current sytax node is a terminal token by attempting to move to first child
|
|
48
|
+
const childExists = cursor.firstChild();
|
|
49
|
+
|
|
50
|
+
if (isError) {
|
|
51
|
+
// If the cursor was an error and it has a child, it is an unexpected token error
|
|
52
|
+
// In this case the child is the unexpected token, we can treat it like an AST node
|
|
53
|
+
// so move back to parent
|
|
54
|
+
if (childExists) {
|
|
55
|
+
cursor.parent();
|
|
56
|
+
return NodeScenario.UNEXPECTED_NODE;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If it is an error and no child exists, check if there is text, if so treat this as an
|
|
60
|
+
// unknown token error.
|
|
61
|
+
if (cursor.to > cursor.from) {
|
|
62
|
+
return NodeScenario.UNKNOWN_TOKEN;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Otherwise it is a missing node error.
|
|
66
|
+
return NodeScenario.MISSING_NODE;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// If we have a child, we should not use it yet, so move back to parent
|
|
70
|
+
if (childExists) {
|
|
71
|
+
cursor.parent();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Primitive is a terminal custom text rather than a syntax token, this will be treated slightly differently
|
|
75
|
+
if (cursor.type.prop(primitiveNodeProp)) {
|
|
76
|
+
return NodeScenario.PRIMITIVE;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Check if it is a token type
|
|
80
|
+
if (tokenKindByTokenTypeId.get(cursor.type.id) !== undefined) {
|
|
81
|
+
return NodeScenario.TOKEN;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// If it has no children, it is an empty AST node
|
|
85
|
+
if (!childExists) {
|
|
86
|
+
return NodeScenario.EMPTY_AST_NODE;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Otherwise it is a non-terminal AST node
|
|
90
|
+
return NodeScenario.AST_NODE;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* Iterate through the syntax tree and consume parse tree tokens to create an AST node.
|
|
95
|
+
*/
|
|
96
|
+
export function consumeAbstractNode(
|
|
97
|
+
buildContext: BuildContext,
|
|
98
|
+
): AbstractNode | undefined {
|
|
99
|
+
const { cursor } = buildContext;
|
|
100
|
+
const currentState =
|
|
101
|
+
buildContext.stateStack[buildContext.stateStack.length - 1];
|
|
102
|
+
|
|
103
|
+
// Get any leading trivia for the node
|
|
104
|
+
const leadingTrivia = consumeTrivia(buildContext, false);
|
|
105
|
+
|
|
106
|
+
// If no siblings remain to be consumed, return undefined
|
|
107
|
+
if (currentState.isEndOfSiblings) {
|
|
108
|
+
if (leadingTrivia.length > 0) {
|
|
109
|
+
if (buildContext.unconsumedTrivia) {
|
|
110
|
+
throw new InternalScannerError(
|
|
111
|
+
`Expected no unconsumed trivia, but found some.`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
buildContext.unconsumedTrivia = leadingTrivia;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Determine what kind of node we are about to consume
|
|
120
|
+
const nodeScenario = determineNodeScenario(buildContext);
|
|
121
|
+
|
|
122
|
+
logger.debug(
|
|
123
|
+
currentState.indent + "consuming node: " + cursor.name +
|
|
124
|
+
` (scenario: ${NodeScenario[nodeScenario]})`,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
let node;
|
|
128
|
+
|
|
129
|
+
switch (nodeScenario) {
|
|
130
|
+
case NodeScenario.MISSING_NODE:
|
|
131
|
+
node = buildMissingError(buildContext);
|
|
132
|
+
break;
|
|
133
|
+
case NodeScenario.PRIMITIVE:
|
|
134
|
+
node = consumePrimitive(buildContext);
|
|
135
|
+
break;
|
|
136
|
+
case NodeScenario.UNKNOWN_TOKEN: {
|
|
137
|
+
const unknownToken = buildToken(buildContext);
|
|
138
|
+
// wrap unknown token in unexpected node
|
|
139
|
+
node = new UnexpectedError(unknownToken);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case NodeScenario.TOKEN:
|
|
143
|
+
node = buildToken(buildContext);
|
|
144
|
+
break;
|
|
145
|
+
case NodeScenario.UNEXPECTED_NODE:
|
|
146
|
+
case NodeScenario.AST_NODE:
|
|
147
|
+
node = consumeAstNode(buildContext);
|
|
148
|
+
break;
|
|
149
|
+
case NodeScenario.EMPTY_AST_NODE: {
|
|
150
|
+
const nodeKind = nodeKindByTokenTypeId.get(cursor.type.id);
|
|
151
|
+
|
|
152
|
+
if (nodeKind === undefined) {
|
|
153
|
+
throw new InternalScannerError(
|
|
154
|
+
`No nodeKind mapping found for token type id: ${cursor.type.id} (${cursor.type.name})`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Allow specification to have no children
|
|
159
|
+
if (nodeKind == NodeKind.SPECIFICATION) {
|
|
160
|
+
return new Specification([]);
|
|
161
|
+
} else {
|
|
162
|
+
throw new InternalScannerError(
|
|
163
|
+
`Expected node to have at least one child: ${NodeKind[nodeKind]}`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
default: {
|
|
168
|
+
const exhaustiveCheck: never = nodeScenario;
|
|
169
|
+
throw new InternalScannerError(
|
|
170
|
+
"Unreachable code reached, nodeScenario == " + exhaustiveCheck,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Set any leading trivia now we have the node
|
|
176
|
+
if (leadingTrivia.length > 0) {
|
|
177
|
+
node.leadingTrivia = leadingTrivia;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Now that we have consumed a node, move to next sibling
|
|
181
|
+
if (cursor.nextSibling()) {
|
|
182
|
+
currentState.isEndOfSiblings = false;
|
|
183
|
+
} else {
|
|
184
|
+
currentState.isEndOfSiblings = true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Get any trailing trivia for the node
|
|
188
|
+
const trailingTrivia = consumeTrivia(buildContext, true);
|
|
189
|
+
if (trailingTrivia.length > 0) {
|
|
190
|
+
node.trailingTrivia = trailingTrivia;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
logger.debug(
|
|
194
|
+
currentState.indent + "current node: " + cursor.name +
|
|
195
|
+
(currentState.isEndOfSiblings ? ": end of siblings" : ""),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
return node;
|
|
199
|
+
}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import getLogger from "../../../util/logger.ts";
|
|
2
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
3
|
+
import { buildAggregateOutputValue } from "../node/build-aggregate-output-value.ts";
|
|
4
|
+
import { buildAlignedModifier } from "../node/build-aligned-modifier.ts";
|
|
5
|
+
import { buildArrayDefinition } from "../node/build-array-definition.ts";
|
|
6
|
+
import { buildArrayElementAccess } from "../node/build-array-element-access.ts";
|
|
7
|
+
import { buildBase64StringLiteral } from "../node/build-base64-string-literal.ts";
|
|
8
|
+
import { buildBinaryExpression } from "../node/build-binary-expression.ts";
|
|
9
|
+
import { buildBitModifier } from "../node/build-bit-modifier.ts";
|
|
10
|
+
import { buildCaseClause } from "../node/build-case-clause.ts";
|
|
11
|
+
import { buildClassDeclaration } from "../node/build-class-declaration.ts";
|
|
12
|
+
import { buildClassDefinition } from "../node/build-class-definition.ts";
|
|
13
|
+
import { buildClassIdRange } from "../node/build-class-id-range.ts";
|
|
14
|
+
import { buildClassId } from "../node/build-class-id.ts";
|
|
15
|
+
import { buildClassMemberAccess } from "../node/build-class-member-access.ts";
|
|
16
|
+
import { buildCompoundStatement } from "../node/build-compound-statement.ts";
|
|
17
|
+
import { buildComputedArrayDefinition } from "../node/build-computed-array-definition.ts";
|
|
18
|
+
import { buildComputedElementaryTypeDefinition } from "../node/build-computed-elementary-type-definition.ts";
|
|
19
|
+
import { buildDefaultClause } from "../node/build-default-clause.ts";
|
|
20
|
+
import { buildDoStatement } from "../node/build-do-statement.ts";
|
|
21
|
+
import { buildElementaryTypeDefinition } from "../node/build-elementary-type-definition.ts";
|
|
22
|
+
import { buildElementaryTypeOutputValue } from "../node/build-elementary-type-output-value.ts";
|
|
23
|
+
import { buildElementaryType } from "../node/build-elementary-type.ts";
|
|
24
|
+
import { buildExpandableModifier } from "../node/build-expandable-modifier.ts";
|
|
25
|
+
import { buildExplicitArrayDimension } from "../node/build-explicit-array-dimension.ts";
|
|
26
|
+
import { buildExpressionStatement } from "../node/build-expression-statement.ts";
|
|
27
|
+
import { buildExtendedClassIdRange } from "../node/build-extended-class-id-range.ts";
|
|
28
|
+
import { buildExtendsModifier } from "../node/build-extends-modifier.ts";
|
|
29
|
+
import { buildForStatement } from "../node/build-for-statement.ts";
|
|
30
|
+
import { buildIfStatement } from "../node/build-if-statement.ts";
|
|
31
|
+
import { buildImplicitArrayDimension } from "../node/build-implicit-array-dimension.ts";
|
|
32
|
+
import { buildLengthAttribute } from "../node/build-length-attribute.ts";
|
|
33
|
+
import { buildLengthofExpression } from "../node/build-lengthof-expression.ts";
|
|
34
|
+
import { buildMapDeclaration } from "../node/build-map-declaration.ts";
|
|
35
|
+
import { buildMapEntry } from "../node/build-map-entry.ts";
|
|
36
|
+
import { buildMultipleCharacterLiteral } from "../node/build-multiple-character-literal.ts";
|
|
37
|
+
import { buildParameterList } from "../node/build-parameter-list.ts";
|
|
38
|
+
import { buildParameterValueList } from "../node/build-parameter-value-list.ts";
|
|
39
|
+
import { buildParameter } from "../node/build-parameter.ts";
|
|
40
|
+
import { buildPartialArrayDimension } from "../node/build-partial-array-dimension.ts";
|
|
41
|
+
import { buildSpecification } from "../node/build-specification.ts";
|
|
42
|
+
import { buildStringDefinition } from "../node/build-string-definition.ts";
|
|
43
|
+
import { buildSwitchStatement } from "../node/build-switch-statement.ts";
|
|
44
|
+
import { buildUnaryExpression } from "../node/build-unary-expression.ts";
|
|
45
|
+
import { buildUtfStringLiteral } from "../node/build-utf-string-literal.ts";
|
|
46
|
+
import { buildWhileStatement } from "../node/build-while-statement.ts";
|
|
47
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
48
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
49
|
+
import { buildUnexpectedError } from "../node/build-unexpected-error.ts";
|
|
50
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
51
|
+
import { nodeKindByTokenTypeId } from "../util/node-kind-by-token-type-id-map.ts";
|
|
52
|
+
import { ArrayDimensionKind } from "../../node/enum/array-dimension-kind.ts";
|
|
53
|
+
import { arrayDimensionKindByTokenTypeId } from "../util/array-dimension-kind-by-token-type-id-map.ts";
|
|
54
|
+
import { stringLiteralKindByTokenTypeId } from "../util/string-literal-kind-by-token-type-id-map.ts";
|
|
55
|
+
import { statementKindByTokenTypeId } from "../util/statement-kind-by-token-type-id-map.ts";
|
|
56
|
+
import { expressionKindByTokenTypeId } from "../util/expression-kind-by-token-type-id-map.ts";
|
|
57
|
+
import { classIdKindByTokenTypeId } from "../util/class-id-kind-by-token-type-id-map.ts";
|
|
58
|
+
import { ClassIdKind } from "../../node/enum/class-id-kind.ts";
|
|
59
|
+
import { ExpressionKind } from "../../node/enum/expression-kind.ts";
|
|
60
|
+
import { StatementKind } from "../../node/enum/statement-kind.ts";
|
|
61
|
+
import { buildMapDefinition } from "../node/build-map-definition.ts";
|
|
62
|
+
import { StringLiteralKind } from "../../node/enum/string-literal-kind.ts";
|
|
63
|
+
import { consumeWhiteSpaceAndMissingErrors } from "./consume-white-space-and-missing-errors.ts";
|
|
64
|
+
|
|
65
|
+
const logger = getLogger("consumeAstNode");
|
|
66
|
+
|
|
67
|
+
function consumeArrayDimension(
|
|
68
|
+
buildContext: BuildContext,
|
|
69
|
+
parentTypeId: number,
|
|
70
|
+
parentTypeName: string,
|
|
71
|
+
): AbstractNode {
|
|
72
|
+
const arrayDimensionKind = arrayDimensionKindByTokenTypeId.get(
|
|
73
|
+
parentTypeId,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (arrayDimensionKind === undefined) {
|
|
77
|
+
throw new InternalScannerError(
|
|
78
|
+
`No arrayDimensionKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
switch (arrayDimensionKind) {
|
|
83
|
+
case ArrayDimensionKind.EXPLICIT:
|
|
84
|
+
return buildExplicitArrayDimension(buildContext);
|
|
85
|
+
case ArrayDimensionKind.IMPLICIT:
|
|
86
|
+
return buildImplicitArrayDimension(buildContext);
|
|
87
|
+
case ArrayDimensionKind.PARTIAL:
|
|
88
|
+
return buildPartialArrayDimension(buildContext);
|
|
89
|
+
default: {
|
|
90
|
+
const exhaustiveCheck: never = arrayDimensionKind;
|
|
91
|
+
throw new InternalScannerError(
|
|
92
|
+
"Unreachable code reached, arrayDimensionKind == " +
|
|
93
|
+
exhaustiveCheck,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function consumeClassId(
|
|
100
|
+
buildContext: BuildContext,
|
|
101
|
+
parentTypeId: number,
|
|
102
|
+
parentTypeName: string,
|
|
103
|
+
): AbstractNode {
|
|
104
|
+
const classIdKind = classIdKindByTokenTypeId.get(
|
|
105
|
+
parentTypeId,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (classIdKind === undefined) {
|
|
109
|
+
throw new InternalScannerError(
|
|
110
|
+
`No classIdKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
switch (classIdKind) {
|
|
114
|
+
case ClassIdKind.SINGLE:
|
|
115
|
+
return buildClassId(buildContext);
|
|
116
|
+
case ClassIdKind.RANGE:
|
|
117
|
+
return buildClassIdRange(buildContext);
|
|
118
|
+
case ClassIdKind.EXTENDED_RANGE:
|
|
119
|
+
return buildExtendedClassIdRange(buildContext);
|
|
120
|
+
default: {
|
|
121
|
+
const exhaustiveCheck: never = classIdKind;
|
|
122
|
+
throw new InternalScannerError(
|
|
123
|
+
"Unreachable code reached, classIdKind == " +
|
|
124
|
+
exhaustiveCheck,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function consumeExpression(
|
|
131
|
+
buildContext: BuildContext,
|
|
132
|
+
parentTypeId: number,
|
|
133
|
+
parentTypeName: string,
|
|
134
|
+
): AbstractNode {
|
|
135
|
+
const expressionKind = expressionKindByTokenTypeId.get(
|
|
136
|
+
parentTypeId,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (expressionKind === undefined) {
|
|
140
|
+
throw new InternalScannerError(
|
|
141
|
+
`No expressionKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
switch (expressionKind) {
|
|
145
|
+
case ExpressionKind.BINARY:
|
|
146
|
+
return buildBinaryExpression(buildContext);
|
|
147
|
+
case ExpressionKind.UNARY:
|
|
148
|
+
return buildUnaryExpression(buildContext);
|
|
149
|
+
case ExpressionKind.LENGTHOF:
|
|
150
|
+
return buildLengthofExpression(buildContext);
|
|
151
|
+
default: {
|
|
152
|
+
const exhaustiveCheck: never = expressionKind;
|
|
153
|
+
throw new InternalScannerError(
|
|
154
|
+
"Unreachable code reached, expressionKind == " +
|
|
155
|
+
exhaustiveCheck,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function consumeStatement(
|
|
162
|
+
buildContext: BuildContext,
|
|
163
|
+
parentTypeId: number,
|
|
164
|
+
parentTypeName: string,
|
|
165
|
+
): AbstractNode {
|
|
166
|
+
const statementKind = statementKindByTokenTypeId.get(
|
|
167
|
+
parentTypeId,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (statementKind === undefined) {
|
|
171
|
+
throw new InternalScannerError(
|
|
172
|
+
`No statementKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
switch (statementKind) {
|
|
176
|
+
case StatementKind.ARRAY_DEFINITION:
|
|
177
|
+
return buildArrayDefinition(buildContext);
|
|
178
|
+
case StatementKind.CLASS_DECLARATION:
|
|
179
|
+
return buildClassDeclaration(buildContext);
|
|
180
|
+
case StatementKind.CLASS_DEFINITION:
|
|
181
|
+
return buildClassDefinition(buildContext);
|
|
182
|
+
case StatementKind.COMPOUND:
|
|
183
|
+
return buildCompoundStatement(buildContext);
|
|
184
|
+
case StatementKind.COMPUTED_ARRAY_DEFINITION:
|
|
185
|
+
return buildComputedArrayDefinition(buildContext);
|
|
186
|
+
case StatementKind.COMPUTED_ELEMENTARY_TYPE_DEFINITION:
|
|
187
|
+
return buildComputedElementaryTypeDefinition(buildContext);
|
|
188
|
+
case StatementKind.DO:
|
|
189
|
+
return buildDoStatement(buildContext);
|
|
190
|
+
case StatementKind.ELEMENTARY_TYPE_DEFINITION:
|
|
191
|
+
return buildElementaryTypeDefinition(buildContext);
|
|
192
|
+
case StatementKind.EXPRESSION:
|
|
193
|
+
return buildExpressionStatement(buildContext);
|
|
194
|
+
case StatementKind.FOR:
|
|
195
|
+
return buildForStatement(buildContext);
|
|
196
|
+
case StatementKind.IF:
|
|
197
|
+
return buildIfStatement(buildContext);
|
|
198
|
+
case StatementKind.MAP_DECLARATION:
|
|
199
|
+
return buildMapDeclaration(buildContext);
|
|
200
|
+
case StatementKind.MAP_DEFINITION:
|
|
201
|
+
return buildMapDefinition(buildContext);
|
|
202
|
+
case StatementKind.STRING_DEFINITION:
|
|
203
|
+
return buildStringDefinition(buildContext);
|
|
204
|
+
case StatementKind.SWITCH:
|
|
205
|
+
return buildSwitchStatement(buildContext);
|
|
206
|
+
case StatementKind.WHILE:
|
|
207
|
+
return buildWhileStatement(buildContext);
|
|
208
|
+
default: {
|
|
209
|
+
const exhaustiveCheck: never = statementKind;
|
|
210
|
+
throw new InternalScannerError(
|
|
211
|
+
"Unreachable code reached, statementKind == " +
|
|
212
|
+
exhaustiveCheck,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function consumeStringLiteral(
|
|
219
|
+
buildContext: BuildContext,
|
|
220
|
+
parentTypeId: number,
|
|
221
|
+
parentTypeName: string,
|
|
222
|
+
): AbstractNode {
|
|
223
|
+
const stringLiteralKind = stringLiteralKindByTokenTypeId.get(
|
|
224
|
+
parentTypeId,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
if (stringLiteralKind === undefined) {
|
|
228
|
+
throw new InternalScannerError(
|
|
229
|
+
`No stringLiteralKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
switch (stringLiteralKind) {
|
|
233
|
+
case StringLiteralKind.BASIC:
|
|
234
|
+
return buildBase64StringLiteral(buildContext);
|
|
235
|
+
case StringLiteralKind.UTF:
|
|
236
|
+
return buildUtfStringLiteral(buildContext);
|
|
237
|
+
default: {
|
|
238
|
+
const exhaustiveCheck: never = stringLiteralKind;
|
|
239
|
+
throw new InternalScannerError(
|
|
240
|
+
"Unreachable code reached, stringLiteralKind == " +
|
|
241
|
+
exhaustiveCheck,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function consumeAstNode(buildContext: BuildContext): AbstractNode {
|
|
248
|
+
const { cursor } = buildContext;
|
|
249
|
+
const currentState =
|
|
250
|
+
buildContext.stateStack[buildContext.stateStack.length - 1];
|
|
251
|
+
const parentTypeId = cursor.type.id;
|
|
252
|
+
const parentTypeName = cursor.type.name;
|
|
253
|
+
|
|
254
|
+
let nodeKind: NodeKind | undefined;
|
|
255
|
+
|
|
256
|
+
if (cursor.type.isError) {
|
|
257
|
+
nodeKind = NodeKind.UNEXPECTED_ERROR;
|
|
258
|
+
} else {
|
|
259
|
+
nodeKind = nodeKindByTokenTypeId.get(parentTypeId);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (nodeKind === undefined) {
|
|
263
|
+
throw new InternalScannerError(
|
|
264
|
+
`No nodeKind mapping found for token type id: ${parentTypeId} (${parentTypeName})`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
logger.debug(
|
|
269
|
+
currentState.indent + "consuming AST node: " + NodeKind[nodeKind] + "...",
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const childStack = {
|
|
273
|
+
isEndOfSiblings: false,
|
|
274
|
+
indent: currentState.indent + " ",
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
buildContext.stateStack.push(childStack);
|
|
278
|
+
|
|
279
|
+
if (!cursor.firstChild()) {
|
|
280
|
+
throw new InternalScannerError(
|
|
281
|
+
`Expected AST node to have children: ${NodeKind[nodeKind]}`,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let node: AbstractNode;
|
|
286
|
+
|
|
287
|
+
switch (nodeKind) {
|
|
288
|
+
case NodeKind.ARRAY_DIMENSION:
|
|
289
|
+
node = consumeArrayDimension(buildContext, parentTypeId, parentTypeName);
|
|
290
|
+
break;
|
|
291
|
+
case NodeKind.CLASS_ID:
|
|
292
|
+
node = consumeClassId(buildContext, parentTypeId, parentTypeName);
|
|
293
|
+
break;
|
|
294
|
+
case NodeKind.EXPRESSION:
|
|
295
|
+
node = consumeExpression(buildContext, parentTypeId, parentTypeName);
|
|
296
|
+
break;
|
|
297
|
+
case NodeKind.STATEMENT:
|
|
298
|
+
node = consumeStatement(buildContext, parentTypeId, parentTypeName);
|
|
299
|
+
break;
|
|
300
|
+
case NodeKind.STRING_LITERAL:
|
|
301
|
+
node = consumeStringLiteral(buildContext, parentTypeId, parentTypeName);
|
|
302
|
+
break;
|
|
303
|
+
case NodeKind.AGGREGATE_OUTPUT_VALUE:
|
|
304
|
+
node = buildAggregateOutputValue(buildContext);
|
|
305
|
+
break;
|
|
306
|
+
case NodeKind.ALIGNED_MODIFIER:
|
|
307
|
+
node = buildAlignedModifier(buildContext);
|
|
308
|
+
break;
|
|
309
|
+
case NodeKind.ARRAY_ELEMENT_ACCESS:
|
|
310
|
+
node = buildArrayElementAccess(buildContext);
|
|
311
|
+
break;
|
|
312
|
+
case NodeKind.BIT_MODIFIER:
|
|
313
|
+
node = buildBitModifier(buildContext);
|
|
314
|
+
break;
|
|
315
|
+
case NodeKind.CASE_CLAUSE:
|
|
316
|
+
node = buildCaseClause(buildContext);
|
|
317
|
+
break;
|
|
318
|
+
case NodeKind.CLASS_MEMBER_ACCESS:
|
|
319
|
+
node = buildClassMemberAccess(buildContext);
|
|
320
|
+
break;
|
|
321
|
+
case NodeKind.DEFAULT_CLAUSE:
|
|
322
|
+
node = buildDefaultClause(buildContext);
|
|
323
|
+
break;
|
|
324
|
+
case NodeKind.ELEMENTARY_TYPE:
|
|
325
|
+
node = buildElementaryType(buildContext);
|
|
326
|
+
break;
|
|
327
|
+
case NodeKind.ELEMENTARY_TYPE_OUTPUT_VALUE:
|
|
328
|
+
node = buildElementaryTypeOutputValue(buildContext);
|
|
329
|
+
break;
|
|
330
|
+
case NodeKind.EXPANDABLE_MODIFIER:
|
|
331
|
+
node = buildExpandableModifier(buildContext);
|
|
332
|
+
break;
|
|
333
|
+
case NodeKind.EXTENDS_MODIFIER:
|
|
334
|
+
node = buildExtendsModifier(buildContext);
|
|
335
|
+
break;
|
|
336
|
+
case NodeKind.LENGTH_ATTRIBUTE:
|
|
337
|
+
node = buildLengthAttribute(buildContext);
|
|
338
|
+
break;
|
|
339
|
+
case NodeKind.MAP_ENTRY:
|
|
340
|
+
node = buildMapEntry(buildContext);
|
|
341
|
+
break;
|
|
342
|
+
case NodeKind.NUMBER_LITERAL:
|
|
343
|
+
node = buildMultipleCharacterLiteral(buildContext);
|
|
344
|
+
break;
|
|
345
|
+
case NodeKind.PARAMETER:
|
|
346
|
+
node = buildParameter(buildContext);
|
|
347
|
+
break;
|
|
348
|
+
case NodeKind.PARAMETER_LIST:
|
|
349
|
+
node = buildParameterList(buildContext);
|
|
350
|
+
break;
|
|
351
|
+
case NodeKind.PARAMETER_VALUE_LIST:
|
|
352
|
+
node = buildParameterValueList(buildContext);
|
|
353
|
+
break;
|
|
354
|
+
case NodeKind.SPECIFICATION:
|
|
355
|
+
node = buildSpecification(buildContext);
|
|
356
|
+
break;
|
|
357
|
+
case NodeKind.UNEXPECTED_ERROR:
|
|
358
|
+
node = buildUnexpectedError(buildContext);
|
|
359
|
+
break;
|
|
360
|
+
// These are node types that should be handled by other consumers
|
|
361
|
+
case NodeKind.IDENTIFIER:
|
|
362
|
+
case NodeKind.TOKEN:
|
|
363
|
+
throw new InternalScannerError(
|
|
364
|
+
`consumeAstNode cannot consume node of kind: ${NodeKind[nodeKind]}`,
|
|
365
|
+
);
|
|
366
|
+
default: {
|
|
367
|
+
const exhaustiveCheck: never = nodeKind;
|
|
368
|
+
throw new InternalScannerError(
|
|
369
|
+
"Unreachable code reached, nodeKind == " + exhaustiveCheck,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (!childStack.isEndOfSiblings) {
|
|
375
|
+
// skip any whitespace or missing error nodes as these are inserted by parser when recovering
|
|
376
|
+
consumeWhiteSpaceAndMissingErrors(buildContext);
|
|
377
|
+
|
|
378
|
+
if (!childStack.isEndOfSiblings) {
|
|
379
|
+
throw new InternalScannerError(
|
|
380
|
+
`Expected to have consumed all child nodes of ${
|
|
381
|
+
NodeKind[nodeKind]
|
|
382
|
+
}, but some remain.`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
buildContext.stateStack.pop();
|
|
388
|
+
|
|
389
|
+
if (!cursor.parent()) {
|
|
390
|
+
throw new InternalScannerError(
|
|
391
|
+
`Expected to move cursor back to parent of ${
|
|
392
|
+
NodeKind[nodeKind]
|
|
393
|
+
}, but failed.`,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
logger.debug(currentState.indent + "...consumed node: " + NodeKind[nodeKind]);
|
|
398
|
+
|
|
399
|
+
return node;
|
|
400
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
2
|
+
import getLogger from "../../../util/logger.ts";
|
|
3
|
+
import { buildToken } from "../node/build-token.ts";
|
|
4
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
5
|
+
import { buildBinaryLiteral } from "../node/build-binary-literal.ts";
|
|
6
|
+
import { buildDecimalLiteral } from "../node/build-decimal-literal.ts";
|
|
7
|
+
import { buildFloatingPointLiteral } from "../node/build-floating-point-literal.ts";
|
|
8
|
+
import { buildHexadecimalLiteral } from "../node/build-hexadecimal-literal.ts";
|
|
9
|
+
import { buildIdentifier } from "../node/build-identifier.ts";
|
|
10
|
+
import { buildIntegerLiteral } from "../node/build-integer-literal.ts";
|
|
11
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
12
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
13
|
+
|
|
14
|
+
// Generated by Lezer from the SDL grammar
|
|
15
|
+
import * as TokenTypeId from "../../../lezer/parser.terms.ts";
|
|
16
|
+
|
|
17
|
+
const logger = getLogger("consumePrimitive");
|
|
18
|
+
|
|
19
|
+
export function consumePrimitive(buildContext: BuildContext): AbstractNode {
|
|
20
|
+
const { cursor } = buildContext;
|
|
21
|
+
const currentState =
|
|
22
|
+
buildContext.stateStack[buildContext.stateStack.length - 1];
|
|
23
|
+
const token = buildToken(buildContext);
|
|
24
|
+
|
|
25
|
+
let node: AbstractNode;
|
|
26
|
+
|
|
27
|
+
switch (cursor.type.id) {
|
|
28
|
+
case TokenTypeId.Identifier:
|
|
29
|
+
node = buildIdentifier(token);
|
|
30
|
+
break;
|
|
31
|
+
case TokenTypeId.HexadecimalLiteral:
|
|
32
|
+
node = buildHexadecimalLiteral(token);
|
|
33
|
+
break;
|
|
34
|
+
case TokenTypeId.IntegerLiteral:
|
|
35
|
+
node = buildIntegerLiteral(token);
|
|
36
|
+
break;
|
|
37
|
+
case TokenTypeId.BinaryLiteral:
|
|
38
|
+
node = buildBinaryLiteral(token);
|
|
39
|
+
break;
|
|
40
|
+
case TokenTypeId.DecimalLiteral:
|
|
41
|
+
node = buildDecimalLiteral(token);
|
|
42
|
+
break;
|
|
43
|
+
case TokenTypeId.FloatingPointLiteral:
|
|
44
|
+
node = buildFloatingPointLiteral(token);
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
throw new InternalScannerError(
|
|
48
|
+
`Unsupported primitive type: ${cursor.type.name}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
logger.debug(
|
|
52
|
+
currentState.indent + "consumed primitive node: " +
|
|
53
|
+
NodeKind[node.nodeKind] +
|
|
54
|
+
" " +
|
|
55
|
+
token.text.replaceAll("\n", "\\n"),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return node;
|
|
59
|
+
}
|