@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,86 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
4
|
+
import { BitModifier } from "../../node/bit-modifier.ts";
|
|
5
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
6
|
+
import type { AbstractClassId } from "../../node/abstract-class-id.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 buildBitModifier(
|
|
15
|
+
buildContext: BuildContext,
|
|
16
|
+
): BitModifier {
|
|
17
|
+
const children: Array<AbstractNode> = [];
|
|
18
|
+
|
|
19
|
+
const colonPunctuator = fetchRequiredNode<Token>(
|
|
20
|
+
buildContext,
|
|
21
|
+
NodeKind.TOKEN,
|
|
22
|
+
TokenKind.COLON,
|
|
23
|
+
);
|
|
24
|
+
children.push(colonPunctuator);
|
|
25
|
+
const bitKeyword = fetchRequiredNode<Token>(
|
|
26
|
+
buildContext,
|
|
27
|
+
NodeKind.TOKEN,
|
|
28
|
+
TokenKind.BIT,
|
|
29
|
+
);
|
|
30
|
+
children.push(bitKeyword);
|
|
31
|
+
const openParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
32
|
+
buildContext,
|
|
33
|
+
NodeKind.TOKEN,
|
|
34
|
+
TokenKind.OPEN_PARENTHESIS,
|
|
35
|
+
);
|
|
36
|
+
children.push(openParenthesisPunctuator);
|
|
37
|
+
const length = fetchRequiredNode<NumberLiteral>(
|
|
38
|
+
buildContext,
|
|
39
|
+
NodeKind.NUMBER_LITERAL,
|
|
40
|
+
);
|
|
41
|
+
children.push(length);
|
|
42
|
+
const closeParenthesisPunctuator = fetchRequiredNode<Token>(
|
|
43
|
+
buildContext,
|
|
44
|
+
NodeKind.TOKEN,
|
|
45
|
+
TokenKind.CLOSE_PARENTHESIS,
|
|
46
|
+
);
|
|
47
|
+
children.push(closeParenthesisPunctuator);
|
|
48
|
+
const identifier = fetchOptionalNode<Identifier>(
|
|
49
|
+
buildContext,
|
|
50
|
+
NodeKind.IDENTIFIER,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let assignmentOperator: OptionalNode<Token> = undefined;
|
|
54
|
+
if (identifier) {
|
|
55
|
+
children.push(identifier);
|
|
56
|
+
assignmentOperator = fetchOptionalNode<Token>(
|
|
57
|
+
buildContext,
|
|
58
|
+
NodeKind.TOKEN,
|
|
59
|
+
TokenKind.ASSIGNMENT,
|
|
60
|
+
);
|
|
61
|
+
if (assignmentOperator) {
|
|
62
|
+
children.push(assignmentOperator);
|
|
63
|
+
} else {
|
|
64
|
+
throw new InternalScannerError(
|
|
65
|
+
"Expected assignment operator '=' after bit modifier identifier.",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const classId = fetchRequiredNode<AbstractClassId>(
|
|
70
|
+
buildContext,
|
|
71
|
+
NodeKind.CLASS_ID,
|
|
72
|
+
);
|
|
73
|
+
children.push(classId);
|
|
74
|
+
|
|
75
|
+
return new BitModifier(
|
|
76
|
+
colonPunctuator,
|
|
77
|
+
bitKeyword,
|
|
78
|
+
openParenthesisPunctuator,
|
|
79
|
+
length,
|
|
80
|
+
closeParenthesisPunctuator,
|
|
81
|
+
identifier,
|
|
82
|
+
assignmentOperator,
|
|
83
|
+
classId,
|
|
84
|
+
children,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
4
|
+
import { CaseClause } from "../../node/case-clause.ts";
|
|
5
|
+
import type { AbstractStatement } from "../../node/abstract-statement.ts";
|
|
6
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
7
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
8
|
+
import type { Token } from "../../node/token.ts";
|
|
9
|
+
import {
|
|
10
|
+
fetchOptionalNode,
|
|
11
|
+
fetchRequiredNode,
|
|
12
|
+
fetchZeroToManyList,
|
|
13
|
+
} from "../util/fetch-node.ts";
|
|
14
|
+
import type { OptionalNode } from "../../util/types.ts";
|
|
15
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
16
|
+
|
|
17
|
+
export function buildCaseClause(
|
|
18
|
+
buildContext: BuildContext,
|
|
19
|
+
): CaseClause {
|
|
20
|
+
const children: Array<AbstractNode> = [];
|
|
21
|
+
|
|
22
|
+
const caseKeyword = fetchRequiredNode<Token>(
|
|
23
|
+
buildContext,
|
|
24
|
+
NodeKind.TOKEN,
|
|
25
|
+
TokenKind.CASE,
|
|
26
|
+
);
|
|
27
|
+
children.push(caseKeyword);
|
|
28
|
+
const value = fetchRequiredNode<NumberLiteral>(
|
|
29
|
+
buildContext,
|
|
30
|
+
NodeKind.NUMBER_LITERAL,
|
|
31
|
+
);
|
|
32
|
+
children.push(value);
|
|
33
|
+
const colonPunctuator = fetchRequiredNode<Token>(
|
|
34
|
+
buildContext,
|
|
35
|
+
NodeKind.TOKEN,
|
|
36
|
+
TokenKind.COLON,
|
|
37
|
+
);
|
|
38
|
+
children.push(colonPunctuator);
|
|
39
|
+
const openBracePunctuator = fetchOptionalNode<Token>(
|
|
40
|
+
buildContext,
|
|
41
|
+
NodeKind.TOKEN,
|
|
42
|
+
TokenKind.OPEN_BRACE,
|
|
43
|
+
);
|
|
44
|
+
if (openBracePunctuator) {
|
|
45
|
+
children.push(openBracePunctuator);
|
|
46
|
+
}
|
|
47
|
+
const statements = fetchZeroToManyList<AbstractStatement>(
|
|
48
|
+
buildContext,
|
|
49
|
+
NodeKind.STATEMENT,
|
|
50
|
+
);
|
|
51
|
+
children.push(...statements);
|
|
52
|
+
const breakKeyword = fetchOptionalNode<Token>(
|
|
53
|
+
buildContext,
|
|
54
|
+
NodeKind.TOKEN,
|
|
55
|
+
TokenKind.BREAK,
|
|
56
|
+
);
|
|
57
|
+
let semicolonPunctuator: OptionalNode<Token> = undefined;
|
|
58
|
+
if (breakKeyword) {
|
|
59
|
+
children.push(breakKeyword);
|
|
60
|
+
semicolonPunctuator = fetchOptionalNode<Token>(
|
|
61
|
+
buildContext,
|
|
62
|
+
NodeKind.TOKEN,
|
|
63
|
+
TokenKind.SEMICOLON,
|
|
64
|
+
);
|
|
65
|
+
if (semicolonPunctuator) {
|
|
66
|
+
children.push(semicolonPunctuator);
|
|
67
|
+
} else {
|
|
68
|
+
throw new InternalScannerError(
|
|
69
|
+
"Expected semicolon punctuator ';' after break keyword.",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let closeBracePunctuator: OptionalNode<Token> = undefined;
|
|
75
|
+
if (openBracePunctuator) {
|
|
76
|
+
closeBracePunctuator = fetchOptionalNode<Token>(
|
|
77
|
+
buildContext,
|
|
78
|
+
NodeKind.TOKEN,
|
|
79
|
+
TokenKind.CLOSE_BRACE,
|
|
80
|
+
);
|
|
81
|
+
if (closeBracePunctuator) {
|
|
82
|
+
children.push(closeBracePunctuator);
|
|
83
|
+
} else {
|
|
84
|
+
throw new InternalScannerError(
|
|
85
|
+
"Expected close brace punctuator '}' to match open brace punctuator.",
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return new CaseClause(
|
|
91
|
+
caseKeyword,
|
|
92
|
+
value,
|
|
93
|
+
colonPunctuator,
|
|
94
|
+
openBracePunctuator,
|
|
95
|
+
statements,
|
|
96
|
+
breakKeyword,
|
|
97
|
+
semicolonPunctuator,
|
|
98
|
+
closeBracePunctuator,
|
|
99
|
+
children,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
3
|
+
import { ClassDeclaration } from "../../node/class-declaration.ts";
|
|
4
|
+
import { AbstractStatement } from "../../node/abstract-statement.ts";
|
|
5
|
+
import { BitModifier } from "../../node/bit-modifier.ts";
|
|
6
|
+
import { ExtendsModifier } from "../../node/extends-modifier.ts";
|
|
7
|
+
import { ParameterList } from "../../node/parameter-list.ts";
|
|
8
|
+
import type { ExpandableModifier } from "../../node/expandable-modifier.ts";
|
|
9
|
+
import type { AlignedModifier } from "../../node/aligned-modifier.ts";
|
|
10
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
11
|
+
import type { Token } from "../../node/token.ts";
|
|
12
|
+
import {
|
|
13
|
+
fetchOptionalNode,
|
|
14
|
+
fetchRequiredNode,
|
|
15
|
+
fetchZeroToManyList,
|
|
16
|
+
} from "../util/fetch-node.ts";
|
|
17
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
18
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
19
|
+
|
|
20
|
+
export function buildClassDeclaration(
|
|
21
|
+
buildContext: BuildContext,
|
|
22
|
+
): ClassDeclaration {
|
|
23
|
+
const children: Array<AbstractNode> = [];
|
|
24
|
+
const alignedModifier = fetchOptionalNode<AlignedModifier>(
|
|
25
|
+
buildContext,
|
|
26
|
+
NodeKind.ALIGNED_MODIFIER,
|
|
27
|
+
);
|
|
28
|
+
if (alignedModifier) {
|
|
29
|
+
children.push(alignedModifier);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const expandableModifier = fetchOptionalNode<ExpandableModifier>(
|
|
33
|
+
buildContext,
|
|
34
|
+
NodeKind.EXPANDABLE_MODIFIER,
|
|
35
|
+
);
|
|
36
|
+
if (expandableModifier) {
|
|
37
|
+
children.push(expandableModifier);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const abstractKeyword = fetchOptionalNode<Token>(
|
|
41
|
+
buildContext,
|
|
42
|
+
NodeKind.TOKEN,
|
|
43
|
+
TokenKind.ABSTRACT,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (abstractKeyword) {
|
|
47
|
+
children.push(abstractKeyword);
|
|
48
|
+
}
|
|
49
|
+
const classKeyword = fetchRequiredNode<Token>(
|
|
50
|
+
buildContext,
|
|
51
|
+
NodeKind.TOKEN,
|
|
52
|
+
TokenKind.CLASS,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
children.push(classKeyword);
|
|
56
|
+
|
|
57
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
58
|
+
buildContext,
|
|
59
|
+
NodeKind.IDENTIFIER,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
children.push(identifier);
|
|
63
|
+
|
|
64
|
+
const parameterList = fetchOptionalNode<ParameterList>(
|
|
65
|
+
buildContext,
|
|
66
|
+
NodeKind.PARAMETER_LIST,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (parameterList) {
|
|
70
|
+
children.push(parameterList);
|
|
71
|
+
}
|
|
72
|
+
const extendsModifier = fetchOptionalNode<ExtendsModifier>(
|
|
73
|
+
buildContext,
|
|
74
|
+
NodeKind.EXTENDS_MODIFIER,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (extendsModifier) {
|
|
78
|
+
children.push(extendsModifier);
|
|
79
|
+
}
|
|
80
|
+
const bitModifier = fetchOptionalNode<BitModifier>(
|
|
81
|
+
buildContext,
|
|
82
|
+
NodeKind.BIT_MODIFIER,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (bitModifier) {
|
|
86
|
+
children.push(bitModifier);
|
|
87
|
+
}
|
|
88
|
+
const openBracePunctuator = fetchRequiredNode<Token>(
|
|
89
|
+
buildContext,
|
|
90
|
+
NodeKind.TOKEN,
|
|
91
|
+
TokenKind.OPEN_BRACE,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
children.push(openBracePunctuator);
|
|
95
|
+
|
|
96
|
+
const statements = fetchZeroToManyList<AbstractStatement>(
|
|
97
|
+
buildContext,
|
|
98
|
+
NodeKind.STATEMENT,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
children.push(...statements);
|
|
102
|
+
|
|
103
|
+
const closeBracePunctuator = fetchRequiredNode<Token>(
|
|
104
|
+
buildContext,
|
|
105
|
+
NodeKind.TOKEN,
|
|
106
|
+
TokenKind.CLOSE_BRACE,
|
|
107
|
+
);
|
|
108
|
+
children.push(closeBracePunctuator);
|
|
109
|
+
|
|
110
|
+
return new ClassDeclaration(
|
|
111
|
+
alignedModifier,
|
|
112
|
+
expandableModifier,
|
|
113
|
+
abstractKeyword,
|
|
114
|
+
classKeyword,
|
|
115
|
+
identifier,
|
|
116
|
+
parameterList,
|
|
117
|
+
extendsModifier,
|
|
118
|
+
bitModifier,
|
|
119
|
+
openBracePunctuator,
|
|
120
|
+
statements,
|
|
121
|
+
closeBracePunctuator,
|
|
122
|
+
children,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import { ClassDefinition } from "../../node/class-definition.ts";
|
|
3
|
+
import type { ParameterValueList } from "../../node/parameter-value-list.ts";
|
|
4
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
5
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
6
|
+
import { fetchOptionalNode, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
7
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
8
|
+
import type { Token } from "../../node/token.ts";
|
|
9
|
+
|
|
10
|
+
export function buildClassDefinition(
|
|
11
|
+
buildContext: BuildContext,
|
|
12
|
+
): ClassDefinition {
|
|
13
|
+
const children: Array<AbstractNode> = [];
|
|
14
|
+
|
|
15
|
+
const legacyKeyword = fetchOptionalNode<Token>(
|
|
16
|
+
buildContext,
|
|
17
|
+
NodeKind.TOKEN,
|
|
18
|
+
TokenKind.LEGACY,
|
|
19
|
+
);
|
|
20
|
+
if (legacyKeyword) {
|
|
21
|
+
children.push(legacyKeyword);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const classIdentifier = fetchRequiredNode<Token>(
|
|
25
|
+
buildContext,
|
|
26
|
+
NodeKind.IDENTIFIER,
|
|
27
|
+
);
|
|
28
|
+
children.push(classIdentifier);
|
|
29
|
+
const identifier = fetchRequiredNode<Token>(
|
|
30
|
+
buildContext,
|
|
31
|
+
NodeKind.IDENTIFIER,
|
|
32
|
+
);
|
|
33
|
+
children.push(identifier);
|
|
34
|
+
const parameterValueList = fetchOptionalNode<ParameterValueList>(
|
|
35
|
+
buildContext,
|
|
36
|
+
NodeKind.PARAMETER_VALUE_LIST,
|
|
37
|
+
);
|
|
38
|
+
if (parameterValueList) {
|
|
39
|
+
children.push(parameterValueList);
|
|
40
|
+
}
|
|
41
|
+
const semicolonPunctuator = fetchRequiredNode<Token>(
|
|
42
|
+
buildContext,
|
|
43
|
+
NodeKind.TOKEN,
|
|
44
|
+
TokenKind.SEMICOLON,
|
|
45
|
+
);
|
|
46
|
+
children.push(semicolonPunctuator);
|
|
47
|
+
|
|
48
|
+
return new ClassDefinition(
|
|
49
|
+
legacyKeyword,
|
|
50
|
+
classIdentifier,
|
|
51
|
+
identifier,
|
|
52
|
+
parameterValueList,
|
|
53
|
+
semicolonPunctuator,
|
|
54
|
+
children,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ClassId } from "../../node/class-id.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import { ClassIdRange } from "../../node/class-id-range.ts";
|
|
4
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
5
|
+
import type { Token } from "../../node/token.ts";
|
|
6
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
7
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
8
|
+
|
|
9
|
+
export function buildClassIdRange(
|
|
10
|
+
buildContext: BuildContext,
|
|
11
|
+
): ClassIdRange {
|
|
12
|
+
const startClassId = fetchRequiredNode<ClassId>(
|
|
13
|
+
buildContext,
|
|
14
|
+
NodeKind.CLASS_ID,
|
|
15
|
+
);
|
|
16
|
+
const rangeOperator = fetchRequiredNode<Token>(
|
|
17
|
+
buildContext,
|
|
18
|
+
NodeKind.TOKEN,
|
|
19
|
+
TokenKind.RANGE_OPERATOR,
|
|
20
|
+
);
|
|
21
|
+
const endClassId = fetchRequiredNode<ClassId>(
|
|
22
|
+
buildContext,
|
|
23
|
+
NodeKind.CLASS_ID,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return new ClassIdRange(
|
|
27
|
+
startClassId,
|
|
28
|
+
rangeOperator,
|
|
29
|
+
endClassId,
|
|
30
|
+
[startClassId, rangeOperator, endClassId],
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NumberLiteral } from "../../node/number-literal.ts";
|
|
2
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
3
|
+
import { ClassId } from "../../node/class-id.ts";
|
|
4
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
5
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
6
|
+
|
|
7
|
+
export function buildClassId(
|
|
8
|
+
buildContext: BuildContext,
|
|
9
|
+
): ClassId {
|
|
10
|
+
const value = fetchRequiredNode<NumberLiteral>(
|
|
11
|
+
buildContext,
|
|
12
|
+
NodeKind.NUMBER_LITERAL,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return new ClassId(
|
|
16
|
+
value,
|
|
17
|
+
[value],
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
3
|
+
import { ClassMemberAccess } from "../../node/class-member-access.ts";
|
|
4
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
5
|
+
import type { Token } from "../../node/token.ts";
|
|
6
|
+
import { fetchRequiredNode } from "../util/fetch-node.ts";
|
|
7
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
8
|
+
|
|
9
|
+
export function buildClassMemberAccess(
|
|
10
|
+
buildContext: BuildContext,
|
|
11
|
+
): ClassMemberAccess {
|
|
12
|
+
const classMemberAccessOperator = fetchRequiredNode<Token>(
|
|
13
|
+
buildContext,
|
|
14
|
+
NodeKind.TOKEN,
|
|
15
|
+
TokenKind.PERIOD,
|
|
16
|
+
);
|
|
17
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
18
|
+
buildContext,
|
|
19
|
+
NodeKind.IDENTIFIER,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return new ClassMemberAccess(
|
|
23
|
+
classMemberAccessOperator,
|
|
24
|
+
identifier,
|
|
25
|
+
[classMemberAccessOperator, identifier],
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import { CompoundStatement } from "../../node/compound-statement.ts";
|
|
3
|
+
import { AbstractStatement } from "../../node/abstract-statement.ts";
|
|
4
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
5
|
+
import { fetchRequiredNode, fetchZeroToManyList } from "../util/fetch-node.ts";
|
|
6
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
7
|
+
import type { Token } from "../../node/token.ts";
|
|
8
|
+
|
|
9
|
+
export function buildCompoundStatement(
|
|
10
|
+
buildContext: BuildContext,
|
|
11
|
+
): CompoundStatement {
|
|
12
|
+
const openBracePunctuator = fetchRequiredNode<Token>(
|
|
13
|
+
buildContext,
|
|
14
|
+
NodeKind.TOKEN,
|
|
15
|
+
TokenKind.OPEN_BRACE,
|
|
16
|
+
);
|
|
17
|
+
const statements = fetchZeroToManyList<AbstractStatement>(
|
|
18
|
+
buildContext,
|
|
19
|
+
NodeKind.STATEMENT,
|
|
20
|
+
);
|
|
21
|
+
const closeBracePunctuator = fetchRequiredNode<Token>(
|
|
22
|
+
buildContext,
|
|
23
|
+
NodeKind.TOKEN,
|
|
24
|
+
TokenKind.CLOSE_BRACE,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return new CompoundStatement(
|
|
28
|
+
openBracePunctuator,
|
|
29
|
+
statements,
|
|
30
|
+
closeBracePunctuator,
|
|
31
|
+
[openBracePunctuator, ...statements, closeBracePunctuator],
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
2
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
3
|
+
import { ExplicitArrayDimension } from "../../node/explicit-array-dimension.ts";
|
|
4
|
+
import type { ElementaryType } from "../../node/elementary-type.ts";
|
|
5
|
+
import { ComputedArrayDefinition } from "../../node/computed-array-definition.ts";
|
|
6
|
+
import type { BuildContext } from "../util/build-context.ts";
|
|
7
|
+
import type { Token } from "../../node/token.ts";
|
|
8
|
+
import { fetchOneToManyList, fetchRequiredNode } from "../util/fetch-node.ts";
|
|
9
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
10
|
+
import { ArrayDimensionKind } from "../../node/enum/array-dimension-kind.ts";
|
|
11
|
+
|
|
12
|
+
export function buildComputedArrayDefinition(
|
|
13
|
+
buildContext: BuildContext,
|
|
14
|
+
): ComputedArrayDefinition {
|
|
15
|
+
const computedKeyword = fetchRequiredNode<Token>(
|
|
16
|
+
buildContext,
|
|
17
|
+
NodeKind.TOKEN,
|
|
18
|
+
TokenKind.COMPUTED,
|
|
19
|
+
);
|
|
20
|
+
const elementaryType = fetchRequiredNode<ElementaryType>(
|
|
21
|
+
buildContext,
|
|
22
|
+
NodeKind.ELEMENTARY_TYPE,
|
|
23
|
+
);
|
|
24
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
25
|
+
buildContext,
|
|
26
|
+
NodeKind.IDENTIFIER,
|
|
27
|
+
);
|
|
28
|
+
const dimensions = fetchOneToManyList<ExplicitArrayDimension>(
|
|
29
|
+
buildContext,
|
|
30
|
+
NodeKind.ARRAY_DIMENSION,
|
|
31
|
+
ArrayDimensionKind.EXPLICIT,
|
|
32
|
+
);
|
|
33
|
+
const semicolonPunctuator = fetchRequiredNode<Token>(
|
|
34
|
+
buildContext,
|
|
35
|
+
NodeKind.TOKEN,
|
|
36
|
+
TokenKind.SEMICOLON,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return new ComputedArrayDefinition(
|
|
40
|
+
computedKeyword,
|
|
41
|
+
elementaryType,
|
|
42
|
+
identifier,
|
|
43
|
+
dimensions,
|
|
44
|
+
semicolonPunctuator,
|
|
45
|
+
[
|
|
46
|
+
computedKeyword,
|
|
47
|
+
elementaryType,
|
|
48
|
+
identifier,
|
|
49
|
+
...dimensions,
|
|
50
|
+
semicolonPunctuator,
|
|
51
|
+
],
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { InternalScannerError } from "../../../scanner-error.ts";
|
|
2
|
+
import type { AbstractExpression } from "../../node/abstract-expression.ts";
|
|
3
|
+
import type { AbstractNode } from "../../node/abstract-node.ts";
|
|
4
|
+
import { ComputedElementaryTypeDefinition } from "../../node/computed-elementary-type-definition.ts";
|
|
5
|
+
import type { ElementaryType } from "../../node/elementary-type.ts";
|
|
6
|
+
import { NodeKind } from "../../node/enum/node-kind.ts";
|
|
7
|
+
import { TokenKind } from "../../node/enum/token-kind.ts";
|
|
8
|
+
import type { Identifier } from "../../node/identifier.ts";
|
|
9
|
+
import type { NumberLiteral } from "../../node/number-literal.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 type { BuildContext } from "../util/build-context.ts";
|
|
14
|
+
|
|
15
|
+
export function buildComputedElementaryTypeDefinition(
|
|
16
|
+
buildContext: BuildContext,
|
|
17
|
+
): ComputedElementaryTypeDefinition {
|
|
18
|
+
const children: Array<AbstractNode> = [];
|
|
19
|
+
|
|
20
|
+
const computedKeyword = fetchRequiredNode<Token>(
|
|
21
|
+
buildContext,
|
|
22
|
+
NodeKind.TOKEN,
|
|
23
|
+
TokenKind.COMPUTED,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
children.push(computedKeyword);
|
|
27
|
+
|
|
28
|
+
const constKeyword = fetchOptionalNode<Token>(
|
|
29
|
+
buildContext,
|
|
30
|
+
NodeKind.TOKEN,
|
|
31
|
+
TokenKind.CONST,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (constKeyword !== undefined) {
|
|
35
|
+
children.push(constKeyword);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const elementaryType = fetchRequiredNode<ElementaryType>(
|
|
39
|
+
buildContext,
|
|
40
|
+
NodeKind.ELEMENTARY_TYPE,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
children.push(elementaryType);
|
|
44
|
+
|
|
45
|
+
const identifier = fetchRequiredNode<Identifier>(
|
|
46
|
+
buildContext,
|
|
47
|
+
NodeKind.IDENTIFIER,
|
|
48
|
+
);
|
|
49
|
+
children.push(identifier);
|
|
50
|
+
|
|
51
|
+
const assignmentOperator = fetchOptionalNode<Token>(
|
|
52
|
+
buildContext,
|
|
53
|
+
NodeKind.TOKEN,
|
|
54
|
+
TokenKind.ASSIGNMENT,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
let value: OptionalNode<AbstractExpression | Identifier | NumberLiteral> =
|
|
58
|
+
undefined;
|
|
59
|
+
|
|
60
|
+
if (assignmentOperator !== undefined) {
|
|
61
|
+
children.push(assignmentOperator);
|
|
62
|
+
|
|
63
|
+
value = fetchOptionalNode<
|
|
64
|
+
AbstractExpression | Identifier | NumberLiteral
|
|
65
|
+
>(
|
|
66
|
+
buildContext,
|
|
67
|
+
[
|
|
68
|
+
NodeKind.EXPRESSION,
|
|
69
|
+
NodeKind.IDENTIFIER,
|
|
70
|
+
NodeKind.NUMBER_LITERAL,
|
|
71
|
+
],
|
|
72
|
+
);
|
|
73
|
+
if (value !== undefined) {
|
|
74
|
+
children.push(value);
|
|
75
|
+
} else {
|
|
76
|
+
throw new InternalScannerError(
|
|
77
|
+
"Expected value for computed elementary type definition after assignment operator",
|
|
78
|
+
(assignmentOperator as Token).getLocation(),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const semicolonPunctuator = fetchRequiredNode<Token>(
|
|
84
|
+
buildContext,
|
|
85
|
+
NodeKind.TOKEN,
|
|
86
|
+
TokenKind.SEMICOLON,
|
|
87
|
+
);
|
|
88
|
+
children.push(semicolonPunctuator);
|
|
89
|
+
|
|
90
|
+
return new ComputedElementaryTypeDefinition(
|
|
91
|
+
computedKeyword,
|
|
92
|
+
constKeyword,
|
|
93
|
+
elementaryType,
|
|
94
|
+
identifier,
|
|
95
|
+
assignmentOperator,
|
|
96
|
+
value,
|
|
97
|
+
semicolonPunctuator,
|
|
98
|
+
children,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -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 buildDecimalLiteral(
|
|
6
|
+
token: Token,
|
|
7
|
+
): NumberLiteral {
|
|
8
|
+
const value = parseFloat(token.text);
|
|
9
|
+
|
|
10
|
+
return new NumberLiteral(
|
|
11
|
+
NumberLiteralKind.DECIMAL,
|
|
12
|
+
value,
|
|
13
|
+
[token],
|
|
14
|
+
);
|
|
15
|
+
}
|