@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,89 @@
|
|
|
1
|
+
# Elementary type output
|
|
2
|
+
|
|
3
|
+
map offsets (int) {0b00,{1024},0b00,{1024}}
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
[GLOBAL]:
|
|
8
|
+
offsets MAP INTEGER
|
|
9
|
+
[MAP] offsets:
|
|
10
|
+
|
|
11
|
+
errors:
|
|
12
|
+
|
|
13
|
+
SEMANTIC ERROR: Input values in a map declaration must be unique.
|
|
14
|
+
|
|
15
|
+
# Class output
|
|
16
|
+
|
|
17
|
+
map barMap (Bar) {0b00,{1024}}
|
|
18
|
+
|
|
19
|
+
==>
|
|
20
|
+
|
|
21
|
+
[GLOBAL]:
|
|
22
|
+
barMap MAP (class: Bar)
|
|
23
|
+
[MAP] barMap:
|
|
24
|
+
|
|
25
|
+
errors:
|
|
26
|
+
|
|
27
|
+
SEMANTIC ERROR: Class: Bar is not declared
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Escape codes
|
|
31
|
+
|
|
32
|
+
map offsets (int) {0b00,{int(6)}}
|
|
33
|
+
|
|
34
|
+
==>
|
|
35
|
+
|
|
36
|
+
[GLOBAL]:
|
|
37
|
+
offsets MAP INTEGER
|
|
38
|
+
[MAP] offsets:
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Duplicate input values
|
|
42
|
+
|
|
43
|
+
map offsets (int) {0b00,{1024},0b01,{2048},0b00,{4096}}
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
[GLOBAL]:
|
|
48
|
+
offsets MAP INTEGER
|
|
49
|
+
[MAP] offsets:
|
|
50
|
+
|
|
51
|
+
errors:
|
|
52
|
+
|
|
53
|
+
SEMANTIC ERROR: Input values in a map declaration must be unique.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Output value count mismatch for elementary type
|
|
57
|
+
|
|
58
|
+
map offsets (int) {0b00,{1024,2048}}
|
|
59
|
+
|
|
60
|
+
==>
|
|
61
|
+
|
|
62
|
+
[GLOBAL]:
|
|
63
|
+
offsets MAP INTEGER
|
|
64
|
+
[MAP] offsets:
|
|
65
|
+
|
|
66
|
+
errors:
|
|
67
|
+
|
|
68
|
+
SEMANTIC ERROR: The type and number of constituent values within the aggregate output values of the map declaration must match the corresponding constituent types within the map's output_type.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# Map with parsable class output
|
|
72
|
+
|
|
73
|
+
class Bar {int(8) x;}
|
|
74
|
+
map barMap (Bar) {0b00,{1024}}
|
|
75
|
+
|
|
76
|
+
==>
|
|
77
|
+
|
|
78
|
+
[GLOBAL]:
|
|
79
|
+
Bar CLASS
|
|
80
|
+
barMap MAP (class: Bar)
|
|
81
|
+
[CLASS] Bar:
|
|
82
|
+
members:
|
|
83
|
+
x VARIABLE INTEGER
|
|
84
|
+
x VARIABLE INTEGER
|
|
85
|
+
[MAP] barMap:
|
|
86
|
+
|
|
87
|
+
warnings:
|
|
88
|
+
|
|
89
|
+
SEMANTIC WARNING: Declaring a map with an output_value consisting of a class with parsable members will result in undefined behaviour.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Reserved with elementary type output
|
|
2
|
+
|
|
3
|
+
map Offsets (int) {0b00,{1024}}
|
|
4
|
+
class A {reserved unsigned int<Offsets> offset;}
|
|
5
|
+
|
|
6
|
+
==>
|
|
7
|
+
|
|
8
|
+
[GLOBAL]:
|
|
9
|
+
Offsets MAP INTEGER
|
|
10
|
+
A CLASS
|
|
11
|
+
[MAP] Offsets:
|
|
12
|
+
[CLASS] A:
|
|
13
|
+
members:
|
|
14
|
+
offset VARIABLE INTEGER (map: Offsets)
|
|
15
|
+
offset VARIABLE INTEGER (map: Offsets)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Legacy with class output
|
|
19
|
+
|
|
20
|
+
class B {}
|
|
21
|
+
map MapB (B) {0b00,{1024}}
|
|
22
|
+
class A {legacy B<MapB> b;}
|
|
23
|
+
|
|
24
|
+
==>
|
|
25
|
+
|
|
26
|
+
[GLOBAL]:
|
|
27
|
+
B CLASS
|
|
28
|
+
MapB MAP (class: B)
|
|
29
|
+
A CLASS
|
|
30
|
+
[CLASS] B:
|
|
31
|
+
[MAP] MapB:
|
|
32
|
+
[CLASS] A:
|
|
33
|
+
members:
|
|
34
|
+
b VARIABLE (class: B) (map: MapB)
|
|
35
|
+
b VARIABLE (class: B) (map: MapB)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Integer literal
|
|
2
|
+
|
|
3
|
+
computed int a=1;
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
[GLOBAL]:
|
|
8
|
+
a VARIABLE INTEGER COMPUTED
|
|
9
|
+
|
|
10
|
+
errors:
|
|
11
|
+
|
|
12
|
+
SEMANTIC ERROR: The only items that may be present in global scope are: constant computed elementary variable definitions, map declarations, class declarations.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Signed zero floating point placeholder
|
|
16
|
+
|
|
17
|
+
class A {float(32) a = 3.14;}
|
|
18
|
+
|
|
19
|
+
==>
|
|
20
|
+
|
|
21
|
+
[GLOBAL]:
|
|
22
|
+
A CLASS
|
|
23
|
+
[CLASS] A:
|
|
24
|
+
members:
|
|
25
|
+
a VARIABLE FLOATING_POINT
|
|
26
|
+
a VARIABLE FLOATING_POINT
|
|
27
|
+
|
|
28
|
+
warnings:
|
|
29
|
+
|
|
30
|
+
SEMANTIC WARNING: Type coercion required for 'a' value: expected FLOATING_POINT, got DECIMAL
|
|
31
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Valid parameter syntax - no string parameters possible in current SDL grammar
|
|
2
|
+
|
|
3
|
+
class A(int a) {}
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
[GLOBAL]:
|
|
8
|
+
A CLASS
|
|
9
|
+
[CLASS] A:
|
|
10
|
+
members:
|
|
11
|
+
a VARIABLE INTEGER
|
|
12
|
+
a VARIABLE INTEGER
|
|
13
|
+
|
|
14
|
+
errors:
|
|
15
|
+
|
|
16
|
+
SEMANTIC ERROR: A parameter in a parameter list must be referenced within the class declaration.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Global scope access
|
|
2
|
+
|
|
3
|
+
computed const int a = 1;
|
|
4
|
+
|
|
5
|
+
class A {
|
|
6
|
+
int(3) b[a];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
==>
|
|
11
|
+
|
|
12
|
+
[GLOBAL]:
|
|
13
|
+
a VARIABLE INTEGER COMPUTED CONST
|
|
14
|
+
A CLASS
|
|
15
|
+
[CLASS] A:
|
|
16
|
+
members:
|
|
17
|
+
b VARIABLE INTEGER []
|
|
18
|
+
b VARIABLE INTEGER []
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Outer scope access
|
|
22
|
+
|
|
23
|
+
class A {
|
|
24
|
+
computed int a = 1;
|
|
25
|
+
if (a == 1) {
|
|
26
|
+
a--;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
==>
|
|
31
|
+
|
|
32
|
+
[GLOBAL]:
|
|
33
|
+
A CLASS
|
|
34
|
+
[CLASS] A:
|
|
35
|
+
members:
|
|
36
|
+
a VARIABLE INTEGER COMPUTED
|
|
37
|
+
a VARIABLE INTEGER COMPUTED
|
|
38
|
+
[BLOCK] COMPOUND:
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Nested scope visibility override
|
|
42
|
+
|
|
43
|
+
class A {
|
|
44
|
+
computed int a = 1;
|
|
45
|
+
if (a == 1) {
|
|
46
|
+
computed float a = 2;
|
|
47
|
+
if (a == 2) {
|
|
48
|
+
a++;
|
|
49
|
+
// a == 3
|
|
50
|
+
}
|
|
51
|
+
// a == 3
|
|
52
|
+
}
|
|
53
|
+
// a == 1
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
==>
|
|
57
|
+
|
|
58
|
+
[GLOBAL]:
|
|
59
|
+
A CLASS
|
|
60
|
+
[CLASS] A:
|
|
61
|
+
members:
|
|
62
|
+
a VARIABLE INTEGER COMPUTED
|
|
63
|
+
a VARIABLE INTEGER COMPUTED
|
|
64
|
+
[BLOCK] COMPOUND:
|
|
65
|
+
a VARIABLE FLOATING_POINT COMPUTED
|
|
66
|
+
[BLOCK] COMPOUND:
|
|
67
|
+
|
|
68
|
+
warnings:
|
|
69
|
+
|
|
70
|
+
SEMANTIC WARNING: Type coercion required for 'a' value: expected FLOATING_POINT, got INTEGER
|
|
71
|
+
SEMANTIC WARNING: Different types in binary expression, coercion required: FLOATING_POINT vs INTEGER
|
|
72
|
+
SEMANTIC WARNING: Non-integer increment operand, coercion required: FLOATING_POINT
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Duplicate variable in IF conditional branches with braces
|
|
76
|
+
|
|
77
|
+
class A {
|
|
78
|
+
computed int a = 1;
|
|
79
|
+
if (a == 1) {
|
|
80
|
+
int(2) b;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
int(3) b;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
==>
|
|
88
|
+
|
|
89
|
+
[GLOBAL]:
|
|
90
|
+
A CLASS
|
|
91
|
+
[CLASS] A:
|
|
92
|
+
members:
|
|
93
|
+
a VARIABLE INTEGER COMPUTED
|
|
94
|
+
b VARIABLE INTEGER (branch: COMPOUND)
|
|
95
|
+
b VARIABLE INTEGER (branch: COMPOUND#1)
|
|
96
|
+
a VARIABLE INTEGER COMPUTED
|
|
97
|
+
[BLOCK] COMPOUND:
|
|
98
|
+
b VARIABLE INTEGER
|
|
99
|
+
[BLOCK] COMPOUND#1:
|
|
100
|
+
b VARIABLE INTEGER
|
|
101
|
+
|
|
102
|
+
warnings:
|
|
103
|
+
|
|
104
|
+
SEMANTIC WARNING: This if-then-else clauses may result in duplicate class member variables being declared simultaneously.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# Duplicate variable in IF conditional branches without braces
|
|
108
|
+
|
|
109
|
+
class A {
|
|
110
|
+
computed int a = 1;
|
|
111
|
+
if (a == 1)
|
|
112
|
+
int(2) b;
|
|
113
|
+
else
|
|
114
|
+
int(3) b;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
==>
|
|
118
|
+
|
|
119
|
+
[GLOBAL]:
|
|
120
|
+
A CLASS
|
|
121
|
+
[CLASS] A:
|
|
122
|
+
members:
|
|
123
|
+
a VARIABLE INTEGER COMPUTED
|
|
124
|
+
b VARIABLE INTEGER (branch: COMPOUND)
|
|
125
|
+
b VARIABLE INTEGER (branch: COMPOUND#1)
|
|
126
|
+
a VARIABLE INTEGER COMPUTED
|
|
127
|
+
[BLOCK] COMPOUND:
|
|
128
|
+
b VARIABLE INTEGER
|
|
129
|
+
[BLOCK] COMPOUND#1:
|
|
130
|
+
b VARIABLE INTEGER
|
|
131
|
+
|
|
132
|
+
warnings:
|
|
133
|
+
|
|
134
|
+
SEMANTIC WARNING: This if-then-else clauses may result in duplicate class member variables being declared simultaneously.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# Duplicate variable in SWITCH conditional branches
|
|
138
|
+
|
|
139
|
+
class A {
|
|
140
|
+
computed int a = 1;
|
|
141
|
+
switch (a) {
|
|
142
|
+
case 1:
|
|
143
|
+
int(2) b;
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
int(3) b;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
==>
|
|
151
|
+
|
|
152
|
+
[GLOBAL]:
|
|
153
|
+
A CLASS
|
|
154
|
+
[CLASS] A:
|
|
155
|
+
members:
|
|
156
|
+
a VARIABLE INTEGER COMPUTED
|
|
157
|
+
b VARIABLE INTEGER (branch: SWITCH/COMPOUND)
|
|
158
|
+
b VARIABLE INTEGER (branch: SWITCH/COMPOUND#1)
|
|
159
|
+
a VARIABLE INTEGER COMPUTED
|
|
160
|
+
[BLOCK] SWITCH:
|
|
161
|
+
[BLOCK] COMPOUND:
|
|
162
|
+
b VARIABLE INTEGER
|
|
163
|
+
[BLOCK] COMPOUND#1:
|
|
164
|
+
b VARIABLE INTEGER
|
|
165
|
+
|
|
166
|
+
warnings:
|
|
167
|
+
|
|
168
|
+
SEMANTIC WARNING: This switch statement may result in duplicate class member variables being declared simultaneously.
|
|
169
|
+
|
|
170
|
+
# Illegal duplicate variable with different type in IF conditional branches
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class A {
|
|
174
|
+
computed int a = 1;
|
|
175
|
+
if (a == 1) {
|
|
176
|
+
int(2) b;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
float(3) b;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
==>
|
|
184
|
+
|
|
185
|
+
[GLOBAL]:
|
|
186
|
+
A CLASS
|
|
187
|
+
[CLASS] A:
|
|
188
|
+
members:
|
|
189
|
+
a VARIABLE INTEGER COMPUTED
|
|
190
|
+
b VARIABLE INTEGER (branch: COMPOUND)
|
|
191
|
+
a VARIABLE INTEGER COMPUTED
|
|
192
|
+
[BLOCK] COMPOUND:
|
|
193
|
+
b VARIABLE INTEGER
|
|
194
|
+
[BLOCK] COMPOUND#1:
|
|
195
|
+
b VARIABLE FLOATING_POINT
|
|
196
|
+
|
|
197
|
+
errors:
|
|
198
|
+
|
|
199
|
+
SEMANTIC ERROR: Duplicate member variable: b conflicts with type defined in different conditional branch within scope: A
|
|
200
|
+
|
|
201
|
+
warnings:
|
|
202
|
+
|
|
203
|
+
SEMANTIC WARNING: This if-then-else clauses may result in duplicate class member variables being declared simultaneously.
|
|
204
|
+
|
|
205
|
+
# Illegal duplicate variable with different type in SWITCH conditional branches
|
|
206
|
+
|
|
207
|
+
class A {
|
|
208
|
+
computed int a = 1;
|
|
209
|
+
switch (a) {
|
|
210
|
+
case 1:
|
|
211
|
+
int(2) b;
|
|
212
|
+
break;
|
|
213
|
+
default:
|
|
214
|
+
float(3) b;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
==>
|
|
219
|
+
|
|
220
|
+
[GLOBAL]:
|
|
221
|
+
A CLASS
|
|
222
|
+
[CLASS] A:
|
|
223
|
+
members:
|
|
224
|
+
a VARIABLE INTEGER COMPUTED
|
|
225
|
+
b VARIABLE INTEGER (branch: SWITCH/COMPOUND)
|
|
226
|
+
a VARIABLE INTEGER COMPUTED
|
|
227
|
+
[BLOCK] SWITCH:
|
|
228
|
+
[BLOCK] COMPOUND:
|
|
229
|
+
b VARIABLE INTEGER
|
|
230
|
+
[BLOCK] COMPOUND#1:
|
|
231
|
+
b VARIABLE FLOATING_POINT
|
|
232
|
+
|
|
233
|
+
errors:
|
|
234
|
+
|
|
235
|
+
SEMANTIC ERROR: Duplicate member variable: b conflicts with type defined in different conditional branch within scope: A
|
|
236
|
+
|
|
237
|
+
warnings:
|
|
238
|
+
|
|
239
|
+
SEMANTIC WARNING: This switch statement may result in duplicate class member variables being declared simultaneously.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Global scope with valid items
|
|
2
|
+
|
|
3
|
+
computed const int a=1;
|
|
4
|
+
map offsets (int) {0b00,{1024}}
|
|
5
|
+
class A{}
|
|
6
|
+
|
|
7
|
+
==>
|
|
8
|
+
|
|
9
|
+
[GLOBAL]:
|
|
10
|
+
a VARIABLE INTEGER COMPUTED CONST
|
|
11
|
+
offsets MAP INTEGER
|
|
12
|
+
A CLASS
|
|
13
|
+
[MAP] offsets:
|
|
14
|
+
[CLASS] A:
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Non-const computed at global scope
|
|
18
|
+
|
|
19
|
+
computed int a=1;
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
[GLOBAL]:
|
|
24
|
+
a VARIABLE INTEGER COMPUTED
|
|
25
|
+
|
|
26
|
+
errors:
|
|
27
|
+
|
|
28
|
+
SEMANTIC ERROR: The only items that may be present in global scope are: constant computed elementary variable definitions, map declarations, class declarations.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# String definition
|
|
2
|
+
|
|
3
|
+
class A {utf8string foo;}
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
[GLOBAL]:
|
|
8
|
+
A CLASS
|
|
9
|
+
[CLASS] A:
|
|
10
|
+
members:
|
|
11
|
+
foo VARIABLE UCS
|
|
12
|
+
foo VARIABLE UCS
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# utf8list with literal
|
|
16
|
+
|
|
17
|
+
class A {utf8list foo=u"hello world";}
|
|
18
|
+
|
|
19
|
+
==>
|
|
20
|
+
|
|
21
|
+
[GLOBAL]:
|
|
22
|
+
A CLASS
|
|
23
|
+
[CLASS] A:
|
|
24
|
+
members:
|
|
25
|
+
foo VARIABLE UCS
|
|
26
|
+
foo VARIABLE UCS
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# base64 string literal
|
|
30
|
+
|
|
31
|
+
class A {base64string foo="aGVsbG8K";}
|
|
32
|
+
|
|
33
|
+
==>
|
|
34
|
+
|
|
35
|
+
[GLOBAL]:
|
|
36
|
+
A CLASS
|
|
37
|
+
[CLASS] A:
|
|
38
|
+
members:
|
|
39
|
+
foo VARIABLE BASIC
|
|
40
|
+
foo VARIABLE BASIC
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Single case
|
|
2
|
+
|
|
3
|
+
class A {switch(i){case 1:break;}}
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
[GLOBAL]:
|
|
8
|
+
A CLASS
|
|
9
|
+
[CLASS] A:
|
|
10
|
+
[BLOCK] SWITCH:
|
|
11
|
+
[BLOCK] COMPOUND:
|
|
12
|
+
|
|
13
|
+
errors:
|
|
14
|
+
|
|
15
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Single case with braces
|
|
19
|
+
|
|
20
|
+
class A {switch(i){case 1:{break;}}}
|
|
21
|
+
|
|
22
|
+
==>
|
|
23
|
+
|
|
24
|
+
[GLOBAL]:
|
|
25
|
+
A CLASS
|
|
26
|
+
[CLASS] A:
|
|
27
|
+
[BLOCK] SWITCH:
|
|
28
|
+
[BLOCK] COMPOUND:
|
|
29
|
+
|
|
30
|
+
errors:
|
|
31
|
+
|
|
32
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Multiple cases and default
|
|
36
|
+
|
|
37
|
+
class A {switch(i){case 1:break;case 2:{i++;break;}default:i--;}}
|
|
38
|
+
|
|
39
|
+
==>
|
|
40
|
+
|
|
41
|
+
[GLOBAL]:
|
|
42
|
+
A CLASS
|
|
43
|
+
[CLASS] A:
|
|
44
|
+
[BLOCK] SWITCH:
|
|
45
|
+
[BLOCK] COMPOUND:
|
|
46
|
+
[BLOCK] COMPOUND#1:
|
|
47
|
+
[BLOCK] COMPOUND#2:
|
|
48
|
+
|
|
49
|
+
errors:
|
|
50
|
+
|
|
51
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
52
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
53
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Multiple cases with no break and default
|
|
57
|
+
|
|
58
|
+
class A {switch(i){case 1:i++;case 2:i++;default:i--;}}
|
|
59
|
+
|
|
60
|
+
==>
|
|
61
|
+
|
|
62
|
+
[GLOBAL]:
|
|
63
|
+
A CLASS
|
|
64
|
+
[CLASS] A:
|
|
65
|
+
[BLOCK] SWITCH:
|
|
66
|
+
[BLOCK] COMPOUND:
|
|
67
|
+
[BLOCK] COMPOUND#1:
|
|
68
|
+
[BLOCK] COMPOUND#2:
|
|
69
|
+
|
|
70
|
+
errors:
|
|
71
|
+
|
|
72
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
73
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
74
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
75
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Multiple cases with no break and no expression and default
|
|
79
|
+
|
|
80
|
+
class A {switch(i){case 1:case 2:i++;default:i--;}}
|
|
81
|
+
|
|
82
|
+
==>
|
|
83
|
+
|
|
84
|
+
[GLOBAL]:
|
|
85
|
+
A CLASS
|
|
86
|
+
[CLASS] A:
|
|
87
|
+
[BLOCK] SWITCH:
|
|
88
|
+
[BLOCK] COMPOUND:
|
|
89
|
+
[BLOCK] COMPOUND#1:
|
|
90
|
+
[BLOCK] COMPOUND#2:
|
|
91
|
+
|
|
92
|
+
errors:
|
|
93
|
+
|
|
94
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
95
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
96
|
+
SEMANTIC ERROR: Identifier: i is not declared
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { SymbolKind, SymbolTable } from "../../../src/analyser/symbol-table.ts";
|
|
3
|
+
import { getSymbolTableString } from "../../../src/analyser/util/symbol-table-utils.ts";
|
|
4
|
+
import { Identifier } from "../../../src/ast/node/identifier.ts";
|
|
5
|
+
import { TokenKind } from "../../../src/ast/node/enum/token-kind.ts";
|
|
6
|
+
import { Token } from "../../../src/ast/node/token.ts";
|
|
7
|
+
|
|
8
|
+
const node = new Identifier(
|
|
9
|
+
"foo",
|
|
10
|
+
new Token(TokenKind.IDENTIFIER, "foo", { row: 1, column: 1, position: 0 }),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
describe("Symbol Table Utils Tests", () => {
|
|
14
|
+
test("toString outputs human-readable format", () => {
|
|
15
|
+
const table = new SymbolTable();
|
|
16
|
+
|
|
17
|
+
table.addSymbol({
|
|
18
|
+
node,
|
|
19
|
+
name: "MyClass",
|
|
20
|
+
kind: SymbolKind.CLASS,
|
|
21
|
+
attributes: {},
|
|
22
|
+
location: { row: 1, column: 1, position: 0 },
|
|
23
|
+
});
|
|
24
|
+
table.addSymbol({
|
|
25
|
+
node,
|
|
26
|
+
name: "MyMap",
|
|
27
|
+
kind: SymbolKind.MAP,
|
|
28
|
+
attributes: {},
|
|
29
|
+
location: { row: 1, column: 1, position: 0 },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const output = getSymbolTableString(table);
|
|
33
|
+
|
|
34
|
+
expect(output).toContain("[GLOBAL]");
|
|
35
|
+
expect(output).toContain("MyClass CLASS");
|
|
36
|
+
expect(output).toContain("MyMap MAP");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("toString includes nested scopes", () => {
|
|
40
|
+
const table = new SymbolTable();
|
|
41
|
+
|
|
42
|
+
table.addSymbol({
|
|
43
|
+
node,
|
|
44
|
+
name: "GlobalClass",
|
|
45
|
+
kind: SymbolKind.CLASS,
|
|
46
|
+
attributes: {},
|
|
47
|
+
location: { row: 1, column: 1, position: 0 },
|
|
48
|
+
});
|
|
49
|
+
table.enterClassScope("MyClass");
|
|
50
|
+
table.addSymbol({
|
|
51
|
+
node,
|
|
52
|
+
name: "param1",
|
|
53
|
+
kind: SymbolKind.VARIABLE,
|
|
54
|
+
attributes: {},
|
|
55
|
+
location: { row: 2, column: 1, position: 10 },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const output = getSymbolTableString(table);
|
|
59
|
+
|
|
60
|
+
expect(output).toContain("[GLOBAL]");
|
|
61
|
+
expect(output).toContain("GlobalClass CLASS");
|
|
62
|
+
expect(output).toContain("[CLASS] MyClass:");
|
|
63
|
+
expect(output).toContain("param1 VARIABLE");
|
|
64
|
+
});
|
|
65
|
+
});
|