@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,117 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { AbstractStatement } from "../../node/abstract-statement.ts";
|
|
4
|
+
import type { AbstractExpression } from "../../node/abstract-expression.ts";
|
|
5
|
+
import { ForStatement } from "../../node/for-statement.ts";
|
|
6
|
+
import { ComputedElementaryTypeDefinition } from "../../node/computed-elementary-type-definition.ts";
|
|
7
|
+
import { StatementKind } from "../../node/enum/statement-kind.ts";
|
|
8
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
9
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
10
|
+
import type { Token } from "../../node/token.ts";
|
|
11
|
+
import { fetchOptionalNode, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
12
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
13
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
14
|
+
|
|
15
|
+
export function buildForStatement(
|
|
16
|
+
buildContext: BuildContext,
|
|
17
|
+
): ForStatement {
|
|
18
|
+
const children: Array<AbstractNode> = [];
|
|
19
|
+
|
|
20
|
+
const forKeyword = fetchRequiredNode<Token>(
|
|
21
|
+
buildContext,
|
|
22
|
+
NodeKind.TOKEN,
|
|
23
|
+
TokenKind.FOR,
|
|
24
|
+
);
|
|
25
|
+
children.push(forKeyword);
|
|
26
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
27
|
+
buildContext,
|
|
28
|
+
NodeKind.TOKEN,
|
|
29
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
30
|
+
);
|
|
31
|
+
children.push(openParenthesisPunctuator);
|
|
32
|
+
const expression1 = fetchOptionalNode<AbstractExpression>(
|
|
33
|
+
buildContext,
|
|
34
|
+
NodeKind.EXPRESSION,
|
|
35
|
+
);
|
|
36
|
+
const semicolon1Punctuator = fetchOptionalNode<Token>(
|
|
37
|
+
buildContext,
|
|
38
|
+
NodeKind.TOKEN,
|
|
39
|
+
TokenKind.SEMICOLON,
|
|
40
|
+
);
|
|
41
|
+
let computedElementaryTypeDefinition: OptionalNode<
|
|
42
|
+
ComputedElementaryTypeDefinition
|
|
43
|
+
>;
|
|
44
|
+
if (expression1) {
|
|
45
|
+
children.push(expression1);
|
|
46
|
+
if (semicolon1Punctuator) {
|
|
47
|
+
children.push(semicolon1Punctuator);
|
|
48
|
+
} else {
|
|
49
|
+
throw new InternalScannerError(
|
|
50
|
+
"Expected semicolon after first expression in for statement",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
} else if (semicolon1Punctuator) {
|
|
54
|
+
children.push(semicolon1Punctuator);
|
|
55
|
+
} else {
|
|
56
|
+
computedElementaryTypeDefinition = fetchOptionalNode<
|
|
57
|
+
ComputedElementaryTypeDefinition
|
|
58
|
+
>(
|
|
59
|
+
buildContext,
|
|
60
|
+
NodeKind.STATEMENT,
|
|
61
|
+
StatementKind.COMPUTED_ELEMENTARY_TYPE_DEFINITION,
|
|
62
|
+
);
|
|
63
|
+
if (computedElementaryTypeDefinition) {
|
|
64
|
+
children.push(computedElementaryTypeDefinition);
|
|
65
|
+
} else {
|
|
66
|
+
throw new InternalScannerError(
|
|
67
|
+
"Expected either an expression or a computed elementary type definition in for statement",
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const expression2 = fetchOptionalNode<AbstractExpression>(
|
|
73
|
+
buildContext,
|
|
74
|
+
NodeKind.EXPRESSION,
|
|
75
|
+
);
|
|
76
|
+
if (expression2) {
|
|
77
|
+
children.push(expression2);
|
|
78
|
+
}
|
|
79
|
+
const semicolon2Punctuator = fetchRequiredNode<Token>(
|
|
80
|
+
buildContext,
|
|
81
|
+
NodeKind.TOKEN,
|
|
82
|
+
TokenKind.SEMICOLON,
|
|
83
|
+
);
|
|
84
|
+
children.push(semicolon2Punctuator);
|
|
85
|
+
const expression3 = fetchOptionalNode<AbstractExpression>(
|
|
86
|
+
buildContext,
|
|
87
|
+
NodeKind.EXPRESSION,
|
|
88
|
+
);
|
|
89
|
+
if (expression3) {
|
|
90
|
+
children.push(expression3);
|
|
91
|
+
}
|
|
92
|
+
const closeParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
93
|
+
buildContext,
|
|
94
|
+
NodeKind.TOKEN,
|
|
95
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
96
|
+
);
|
|
97
|
+
children.push(closeParenthesisPunctuator);
|
|
98
|
+
const statement = fetchRequiredNode<AbstractStatement>(
|
|
99
|
+
buildContext,
|
|
100
|
+
NodeKind.STATEMENT,
|
|
101
|
+
);
|
|
102
|
+
children.push(statement);
|
|
103
|
+
|
|
104
|
+
return new ForStatement(
|
|
105
|
+
forKeyword,
|
|
106
|
+
openParenthesisPunctuator,
|
|
107
|
+
expression1,
|
|
108
|
+
computedElementaryTypeDefinition,
|
|
109
|
+
semicolon1Punctuator,
|
|
110
|
+
expression2,
|
|
111
|
+
semicolon2Punctuator,
|
|
112
|
+
expression3,
|
|
113
|
+
closeParenthesisPunctuator,
|
|
114
|
+
statement,
|
|
115
|
+
children,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NumberLiteral } from "../../node/number-literal.ts";
|
|
2
|
+
import { NumberLiteralKind } from "../../node/enum/number-literal-kind.ts";
|
|
3
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
4
|
+
import type { Token } from "../../node/token.ts";
|
|
5
|
+
|
|
6
|
+
const DOT_SEPARATOR_REGEX = /\./g;
|
|
7
|
+
|
|
8
|
+
export function buildHexadecimalLiteral(
|
|
9
|
+
token: Token,
|
|
10
|
+
): NumberLiteral {
|
|
11
|
+
const literalText = token.text;
|
|
12
|
+
|
|
13
|
+
if (!literalText.startsWith("0x")) {
|
|
14
|
+
throw new InternalScannerError(
|
|
15
|
+
`Missing hexadecimal literal prefix '0x': ${literalText}`,
|
|
16
|
+
token.getLocation(),
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (literalText.length === 2) {
|
|
21
|
+
throw new InternalScannerError(
|
|
22
|
+
`Missing hexadecimal literal value after prefix '0x'`,
|
|
23
|
+
token.getLocation(),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const stringValue = literalText.substring(2).trim().replaceAll(
|
|
28
|
+
DOT_SEPARATOR_REGEX,
|
|
29
|
+
"",
|
|
30
|
+
);
|
|
31
|
+
const value = parseInt(stringValue, 16);
|
|
32
|
+
|
|
33
|
+
return new NumberLiteral(
|
|
34
|
+
NumberLiteralKind.HEXADECIMAL,
|
|
35
|
+
value,
|
|
36
|
+
[token],
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import { IfStatement } from "../../node/if-statement.ts";
|
|
4
|
+
import type { AbstractStatement } from "../../node/abstract-statement.ts";
|
|
5
|
+
import type { AbstractExpression } from "../../node/abstract-expression.ts";
|
|
6
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
7
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
8
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
9
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
10
|
+
import { fetchOptionalNode, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
11
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
12
|
+
import type { Token } from "../../node/token.ts";
|
|
13
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
14
|
+
|
|
15
|
+
export function buildIfStatement(
|
|
16
|
+
buildContext: BuildContext,
|
|
17
|
+
): IfStatement {
|
|
18
|
+
const children: Array<AbstractNode> = [];
|
|
19
|
+
|
|
20
|
+
const ifKeyword = fetchRequiredNode<Token>(
|
|
21
|
+
buildContext,
|
|
22
|
+
NodeKind.TOKEN,
|
|
23
|
+
TokenKind.IF,
|
|
24
|
+
);
|
|
25
|
+
children.push(ifKeyword);
|
|
26
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
27
|
+
buildContext,
|
|
28
|
+
NodeKind.TOKEN,
|
|
29
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
30
|
+
);
|
|
31
|
+
children.push(openParenthesisPunctuator);
|
|
32
|
+
const condition = fetchRequiredNode<
|
|
33
|
+
AbstractExpression | NumberLiteral | Identifier
|
|
34
|
+
>(
|
|
35
|
+
buildContext,
|
|
36
|
+
[NodeKind.EXPRESSION, NodeKind.IDENTIFIER, NodeKind.NUMBER_LITERAL],
|
|
37
|
+
);
|
|
38
|
+
children.push(condition);
|
|
39
|
+
const closeParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
40
|
+
buildContext,
|
|
41
|
+
NodeKind.TOKEN,
|
|
42
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
43
|
+
);
|
|
44
|
+
children.push(closeParenthesisPunctuator);
|
|
45
|
+
const ifStatement = fetchRequiredNode<AbstractStatement>(
|
|
46
|
+
buildContext,
|
|
47
|
+
NodeKind.STATEMENT,
|
|
48
|
+
);
|
|
49
|
+
children.push(ifStatement);
|
|
50
|
+
const elseKeyword = fetchOptionalNode<Token>(
|
|
51
|
+
buildContext,
|
|
52
|
+
NodeKind.TOKEN,
|
|
53
|
+
TokenKind.ELSE,
|
|
54
|
+
);
|
|
55
|
+
let elseStatement: OptionalNode<AbstractStatement> = undefined;
|
|
56
|
+
if (elseKeyword) {
|
|
57
|
+
children.push(elseKeyword);
|
|
58
|
+
elseStatement = fetchOptionalNode<AbstractStatement>(
|
|
59
|
+
buildContext,
|
|
60
|
+
NodeKind.STATEMENT,
|
|
61
|
+
);
|
|
62
|
+
if (elseStatement) {
|
|
63
|
+
children.push(elseStatement);
|
|
64
|
+
} else {
|
|
65
|
+
throw new InternalScannerError(
|
|
66
|
+
"Expected else statement after else keyword",
|
|
67
|
+
(elseKeyword as Token).getLocation(),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return new IfStatement(
|
|
73
|
+
ifKeyword,
|
|
74
|
+
openParenthesisPunctuator,
|
|
75
|
+
condition,
|
|
76
|
+
closeParenthesisPunctuator,
|
|
77
|
+
ifStatement,
|
|
78
|
+
elseKeyword,
|
|
79
|
+
elseStatement,
|
|
80
|
+
children,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
4
|
+
import { ImplicitArrayDimension } from "../../node/implicit-array-dimension.ts";
|
|
5
|
+
import type { AbstractExpression } from "../../node/abstract-expression.ts";
|
|
6
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
7
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
8
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
9
|
+
import type { Token } from "../../node/token.ts";
|
|
10
|
+
import { fetchOptionalNode, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
11
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
12
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
13
|
+
|
|
14
|
+
export function buildImplicitArrayDimension(
|
|
15
|
+
buildContext: BuildContext,
|
|
16
|
+
): ImplicitArrayDimension {
|
|
17
|
+
const children: Array<AbstractNode> = [];
|
|
18
|
+
|
|
19
|
+
const openBracketPunctuator = fetchRequiredNode<Token>(
|
|
20
|
+
buildContext,
|
|
21
|
+
NodeKind.TOKEN,
|
|
22
|
+
TokenKind.OPEN_BRACKET,
|
|
23
|
+
);
|
|
24
|
+
children.push(openBracketPunctuator);
|
|
25
|
+
const rangeStart = fetchOptionalNode<
|
|
26
|
+
AbstractExpression | NumberLiteral | Identifier
|
|
27
|
+
>(
|
|
28
|
+
buildContext,
|
|
29
|
+
[NodeKind.EXPRESSION, NodeKind.IDENTIFIER, NodeKind.NUMBER_LITERAL],
|
|
30
|
+
);
|
|
31
|
+
let rangeOperator: OptionalNode<Token> = undefined;
|
|
32
|
+
let rangeEnd: OptionalNode<
|
|
33
|
+
AbstractExpression | NumberLiteral | Identifier
|
|
34
|
+
> = undefined;
|
|
35
|
+
if (rangeStart) {
|
|
36
|
+
children.push(rangeStart);
|
|
37
|
+
rangeOperator = fetchOptionalNode<Token>(
|
|
38
|
+
buildContext,
|
|
39
|
+
NodeKind.TOKEN,
|
|
40
|
+
TokenKind.RANGE_OPERATOR,
|
|
41
|
+
);
|
|
42
|
+
if (rangeOperator) {
|
|
43
|
+
children.push(rangeOperator);
|
|
44
|
+
} else {
|
|
45
|
+
throw new InternalScannerError(
|
|
46
|
+
"Expected range operator after range start in implicit array dimension",
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
rangeEnd = fetchOptionalNode<
|
|
50
|
+
AbstractExpression | NumberLiteral | Identifier
|
|
51
|
+
>(
|
|
52
|
+
buildContext,
|
|
53
|
+
[NodeKind.EXPRESSION, NodeKind.IDENTIFIER, NodeKind.NUMBER_LITERAL],
|
|
54
|
+
);
|
|
55
|
+
if (rangeEnd) {
|
|
56
|
+
children.push(rangeEnd);
|
|
57
|
+
} else {
|
|
58
|
+
throw new InternalScannerError(
|
|
59
|
+
"Expected range end after range operator in implicit array dimension",
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const closeBracketPunctuator = fetchRequiredNode<Token>(
|
|
64
|
+
buildContext,
|
|
65
|
+
NodeKind.TOKEN,
|
|
66
|
+
TokenKind.CLOSE_BRACKET,
|
|
67
|
+
);
|
|
68
|
+
children.push(closeBracketPunctuator);
|
|
69
|
+
|
|
70
|
+
return new ImplicitArrayDimension(
|
|
71
|
+
openBracketPunctuator,
|
|
72
|
+
rangeStart,
|
|
73
|
+
rangeOperator,
|
|
74
|
+
rangeEnd,
|
|
75
|
+
closeBracketPunctuator,
|
|
76
|
+
children,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NumberLiteral } from "../../node/number-literal.ts";
|
|
2
|
+
import { NumberLiteralKind } from "../../node/enum/number-literal-kind.ts";
|
|
3
|
+
import type { Token } from "../../node/token.ts";
|
|
4
|
+
|
|
5
|
+
export function buildIntegerLiteral(
|
|
6
|
+
token: Token,
|
|
7
|
+
): NumberLiteral {
|
|
8
|
+
const value = parseInt(token.text, 10);
|
|
9
|
+
|
|
10
|
+
return new NumberLiteral(
|
|
11
|
+
NumberLiteralKind.INTEGER,
|
|
12
|
+
value,
|
|
13
|
+
[token],
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AbstractExpression } from "../../../../index.ts";
|
|
2
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
3
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
4
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
5
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
6
|
+
import { LengthAttribute } from "../../node/length-attribute.ts";
|
|
7
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
8
|
+
import type { Token } from "../../node/token.ts";
|
|
9
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
10
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
11
|
+
|
|
12
|
+
export function buildLengthAttribute(
|
|
13
|
+
buildContext: BuildContext,
|
|
14
|
+
): LengthAttribute {
|
|
15
|
+
const children: Array<AbstractNode> = [];
|
|
16
|
+
|
|
17
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
18
|
+
buildContext,
|
|
19
|
+
NodeKind.TOKEN,
|
|
20
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
children.push(openParenthesisPunctuator);
|
|
24
|
+
|
|
25
|
+
const length = fetchRequiredNode<
|
|
26
|
+
NumberLiteral | Identifier | AbstractExpression
|
|
27
|
+
>(
|
|
28
|
+
buildContext,
|
|
29
|
+
[NodeKind.EXPRESSION, NodeKind.IDENTIFIER, NodeKind.NUMBER_LITERAL],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
children.push(length);
|
|
33
|
+
|
|
34
|
+
const closeParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
35
|
+
buildContext,
|
|
36
|
+
NodeKind.TOKEN,
|
|
37
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
children.push(closeParenthesisPunctuator);
|
|
41
|
+
|
|
42
|
+
return new LengthAttribute(
|
|
43
|
+
openParenthesisPunctuator,
|
|
44
|
+
length,
|
|
45
|
+
closeParenthesisPunctuator,
|
|
46
|
+
children,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AbstractExpression } from "../../node/abstract-expression.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
4
|
+
import { LengthofExpression } from "../../node/length-of-expression.ts";
|
|
5
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
6
|
+
import type { Token } from "../../node/token.ts";
|
|
7
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
8
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
9
|
+
|
|
10
|
+
export function buildLengthofExpression(
|
|
11
|
+
buildContext: BuildContext,
|
|
12
|
+
): LengthofExpression {
|
|
13
|
+
const lengthOfKeyword = fetchRequiredNode<Token>(
|
|
14
|
+
buildContext,
|
|
15
|
+
NodeKind.TOKEN,
|
|
16
|
+
TokenKind.LENGTHOF,
|
|
17
|
+
);
|
|
18
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
19
|
+
buildContext,
|
|
20
|
+
NodeKind.TOKEN,
|
|
21
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
22
|
+
);
|
|
23
|
+
const operand = fetchRequiredNode<AbstractExpression | Identifier>(
|
|
24
|
+
buildContext,
|
|
25
|
+
[NodeKind.EXPRESSION, NodeKind.IDENTIFIER],
|
|
26
|
+
);
|
|
27
|
+
const closedParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
28
|
+
buildContext,
|
|
29
|
+
NodeKind.TOKEN,
|
|
30
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return new LengthofExpression(
|
|
34
|
+
lengthOfKeyword,
|
|
35
|
+
openParenthesisPunctuator,
|
|
36
|
+
operand,
|
|
37
|
+
closedParenthesisPunctuator,
|
|
38
|
+
[
|
|
39
|
+
lengthOfKeyword,
|
|
40
|
+
openParenthesisPunctuator,
|
|
41
|
+
operand,
|
|
42
|
+
closedParenthesisPunctuator,
|
|
43
|
+
],
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
4
|
+
import { MapDeclaration } from "../../node/map-declaration.ts";
|
|
5
|
+
import type { ElementaryType } from "../../node/elementary-type.ts";
|
|
6
|
+
import type { MapEntry } from "../../node/map-entry.ts";
|
|
7
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
8
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
9
|
+
import type { Token } from "../../node/token.ts";
|
|
10
|
+
import {
|
|
11
|
+
fetchOneToManyCommaSeparatedList,
|
|
12
|
+
fetchOptionalNode,
|
|
13
|
+
fetchRequiredNode,
|
|
14
|
+
} from "../util/fetch-node.ts";
|
|
15
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
16
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
17
|
+
|
|
18
|
+
export function buildMapDeclaration(
|
|
19
|
+
buildContext: BuildContext,
|
|
20
|
+
): MapDeclaration {
|
|
21
|
+
const children: Array<AbstractNode> = [];
|
|
22
|
+
|
|
23
|
+
const mapKeyword = fetchRequiredNode<Token>(
|
|
24
|
+
buildContext,
|
|
25
|
+
NodeKind.TOKEN,
|
|
26
|
+
TokenKind.MAP,
|
|
27
|
+
);
|
|
28
|
+
children.push(mapKeyword);
|
|
29
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
30
|
+
buildContext,
|
|
31
|
+
NodeKind.IDENTIFIER,
|
|
32
|
+
);
|
|
33
|
+
children.push(identifier);
|
|
34
|
+
|
|
35
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
36
|
+
buildContext,
|
|
37
|
+
NodeKind.TOKEN,
|
|
38
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
39
|
+
);
|
|
40
|
+
children.push(openParenthesisPunctuator);
|
|
41
|
+
|
|
42
|
+
const outputElementaryType = fetchOptionalNode<ElementaryType>(
|
|
43
|
+
buildContext,
|
|
44
|
+
NodeKind.ELEMENTARY_TYPE,
|
|
45
|
+
);
|
|
46
|
+
let outputClassIdentifier: OptionalNode<Identifier> = undefined;
|
|
47
|
+
if (outputElementaryType) {
|
|
48
|
+
children.push(outputElementaryType);
|
|
49
|
+
} else {
|
|
50
|
+
outputClassIdentifier = fetchOptionalNode<Identifier>(
|
|
51
|
+
buildContext,
|
|
52
|
+
NodeKind.IDENTIFIER,
|
|
53
|
+
);
|
|
54
|
+
if (outputClassIdentifier) {
|
|
55
|
+
children.push(outputClassIdentifier);
|
|
56
|
+
} else {
|
|
57
|
+
throw new InternalScannerError(
|
|
58
|
+
"MapDeclaration must have either an output elementary type or an output class identifier.",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const closeParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
64
|
+
buildContext,
|
|
65
|
+
NodeKind.TOKEN,
|
|
66
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
67
|
+
);
|
|
68
|
+
children.push(closeParenthesisPunctuator);
|
|
69
|
+
|
|
70
|
+
const openBracePunctuator = fetchRequiredNode<Token>(
|
|
71
|
+
buildContext,
|
|
72
|
+
NodeKind.TOKEN,
|
|
73
|
+
TokenKind.OPEN_BRACE,
|
|
74
|
+
);
|
|
75
|
+
children.push(openBracePunctuator);
|
|
76
|
+
const { nodes: mapEntries, commaPunctuators } =
|
|
77
|
+
fetchOneToManyCommaSeparatedList<MapEntry>(
|
|
78
|
+
buildContext,
|
|
79
|
+
NodeKind.MAP_ENTRY,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// now push each output value and comma punctuator to children
|
|
83
|
+
for (let i = 0; i < mapEntries.length; i++) {
|
|
84
|
+
children.push(mapEntries[i]);
|
|
85
|
+
if (i < commaPunctuators.length) {
|
|
86
|
+
children.push(commaPunctuators[i]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const closeBracePunctuator = fetchRequiredNode<Token>(
|
|
91
|
+
buildContext,
|
|
92
|
+
NodeKind.TOKEN,
|
|
93
|
+
TokenKind.CLOSE_BRACE,
|
|
94
|
+
);
|
|
95
|
+
children.push(closeBracePunctuator);
|
|
96
|
+
|
|
97
|
+
return new MapDeclaration(
|
|
98
|
+
mapKeyword,
|
|
99
|
+
identifier,
|
|
100
|
+
openParenthesisPunctuator,
|
|
101
|
+
outputElementaryType,
|
|
102
|
+
outputClassIdentifier,
|
|
103
|
+
closeParenthesisPunctuator,
|
|
104
|
+
openBracePunctuator,
|
|
105
|
+
mapEntries,
|
|
106
|
+
commaPunctuators,
|
|
107
|
+
closeBracePunctuator,
|
|
108
|
+
children,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Identifier } from "../../node/identifier.ts";
|
|
2
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
3
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
4
|
+
import { MapDefinition } from "../../node/map-definition.ts";
|
|
5
|
+
import { fetchOptionalNode, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
6
|
+
import type { Token } from "../../node/token.ts";
|
|
7
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
8
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
9
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
10
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
11
|
+
import type { ElementaryType } from "../../node/elementary-type.ts";
|
|
12
|
+
|
|
13
|
+
export function buildMapDefinition(
|
|
14
|
+
buildContext: BuildContext,
|
|
15
|
+
): MapDefinition {
|
|
16
|
+
const children: Array<AbstractNode> = [];
|
|
17
|
+
|
|
18
|
+
const reservedKeyword = fetchOptionalNode<Token>(
|
|
19
|
+
buildContext,
|
|
20
|
+
NodeKind.TOKEN,
|
|
21
|
+
TokenKind.RESERVED,
|
|
22
|
+
);
|
|
23
|
+
if (reservedKeyword) {
|
|
24
|
+
children.push(reservedKeyword);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const legacyKeyword = fetchOptionalNode<Token>(
|
|
28
|
+
buildContext,
|
|
29
|
+
NodeKind.TOKEN,
|
|
30
|
+
TokenKind.LEGACY,
|
|
31
|
+
);
|
|
32
|
+
if (legacyKeyword) {
|
|
33
|
+
children.push(legacyKeyword);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const elementaryType = fetchOptionalNode<ElementaryType>(
|
|
37
|
+
buildContext,
|
|
38
|
+
NodeKind.ELEMENTARY_TYPE,
|
|
39
|
+
);
|
|
40
|
+
let classIdentifier: OptionalNode<Identifier> | undefined;
|
|
41
|
+
|
|
42
|
+
if (elementaryType) {
|
|
43
|
+
children.push(elementaryType);
|
|
44
|
+
} else {
|
|
45
|
+
classIdentifier = fetchOptionalNode<Identifier>(
|
|
46
|
+
buildContext,
|
|
47
|
+
NodeKind.IDENTIFIER,
|
|
48
|
+
);
|
|
49
|
+
if (classIdentifier) {
|
|
50
|
+
children.push(classIdentifier);
|
|
51
|
+
} else {
|
|
52
|
+
throw new InternalScannerError(
|
|
53
|
+
"Expected either an elementary type or a class identifier in map definition",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const relationalLessThanPunctuator = fetchRequiredNode<Token>(
|
|
59
|
+
buildContext,
|
|
60
|
+
NodeKind.TOKEN,
|
|
61
|
+
TokenKind.RELATIONAL_LESS_THAN,
|
|
62
|
+
);
|
|
63
|
+
children.push(relationalLessThanPunctuator);
|
|
64
|
+
|
|
65
|
+
const mapIdentifier = fetchRequiredNode<Identifier>(
|
|
66
|
+
buildContext,
|
|
67
|
+
NodeKind.IDENTIFIER,
|
|
68
|
+
);
|
|
69
|
+
children.push(mapIdentifier);
|
|
70
|
+
|
|
71
|
+
const relationalGreaterThanPunctuator = fetchRequiredNode<Token>(
|
|
72
|
+
buildContext,
|
|
73
|
+
NodeKind.TOKEN,
|
|
74
|
+
TokenKind.RELATIONAL_GREATER_THAN,
|
|
75
|
+
);
|
|
76
|
+
children.push(relationalGreaterThanPunctuator);
|
|
77
|
+
|
|
78
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
79
|
+
buildContext,
|
|
80
|
+
NodeKind.IDENTIFIER,
|
|
81
|
+
);
|
|
82
|
+
children.push(identifier);
|
|
83
|
+
|
|
84
|
+
const semicolonPunctuator = fetchRequiredNode<Token>(
|
|
85
|
+
buildContext,
|
|
86
|
+
NodeKind.TOKEN,
|
|
87
|
+
TokenKind.SEMICOLON,
|
|
88
|
+
);
|
|
89
|
+
children.push(semicolonPunctuator);
|
|
90
|
+
|
|
91
|
+
return new MapDefinition(
|
|
92
|
+
reservedKeyword,
|
|
93
|
+
legacyKeyword,
|
|
94
|
+
elementaryType,
|
|
95
|
+
classIdentifier,
|
|
96
|
+
relationalLessThanPunctuator,
|
|
97
|
+
mapIdentifier,
|
|
98
|
+
relationalGreaterThanPunctuator,
|
|
99
|
+
identifier,
|
|
100
|
+
semicolonPunctuator,
|
|
101
|
+
children,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import { MapEntry } from "../../node/map-entry.ts";
|
|
3
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
4
|
+
import type { AggregateOutputValue } from "../../node/aggregate-output-value.ts";
|
|
5
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
6
|
+
import type { Token } from "../../node/token.ts";
|
|
7
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
8
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
9
|
+
|
|
10
|
+
export function buildMapEntry(
|
|
11
|
+
buildContext: BuildContext,
|
|
12
|
+
): MapEntry {
|
|
13
|
+
const inputValue = fetchRequiredNode<NumberLiteral>(
|
|
14
|
+
buildContext,
|
|
15
|
+
NodeKind.NUMBER_LITERAL,
|
|
16
|
+
);
|
|
17
|
+
const commaPunctuator = fetchRequiredNode<Token>(
|
|
18
|
+
buildContext,
|
|
19
|
+
NodeKind.TOKEN,
|
|
20
|
+
TokenKind.COMMA,
|
|
21
|
+
);
|
|
22
|
+
const outputValue = fetchRequiredNode<AggregateOutputValue>(
|
|
23
|
+
buildContext,
|
|
24
|
+
NodeKind.AGGREGATE_OUTPUT_VALUE,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return new MapEntry(
|
|
28
|
+
inputValue,
|
|
29
|
+
commaPunctuator,
|
|
30
|
+
outputValue,
|
|
31
|
+
[inputValue, commaPunctuator, outputValue],
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getLocationFromTextPosition } from "../../../util/location-utils.ts";
|
|
2
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
3
|
+
import { MissingError } from "../../node/missing-error.ts";
|
|
4
|
+
|
|
5
|
+
export function buildMissingError(buildContext: BuildContext): MissingError {
|
|
6
|
+
const { cursor, text } = buildContext;
|
|
7
|
+
const location = getLocationFromTextPosition(text, cursor.from);
|
|
8
|
+
|
|
9
|
+
return new MissingError(location);
|
|
10
|
+
}
|