@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,463 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { buildAst } from "../../src/ast/build-ast.ts";
|
|
3
|
+
import {
|
|
4
|
+
createLenientSdlParser,
|
|
5
|
+
createStrictSdlParser,
|
|
6
|
+
} from "../../src/lezer/create-sdl-parser.ts";
|
|
7
|
+
import { SdlStringInput } from "../../src/lezer/sdl-string-input.ts";
|
|
8
|
+
import { Specification } from "../../src/ast/node/specification.ts";
|
|
9
|
+
import { ClassDeclaration } from "../../src/ast/node/class-declaration.ts";
|
|
10
|
+
import { Identifier } from "../../src/ast/node/identifier.ts";
|
|
11
|
+
import { ExpressionStatement } from "../../src/ast/node/expression-statement.ts";
|
|
12
|
+
import { UnaryExpression } from "../../src/ast/node/unary-expression.ts";
|
|
13
|
+
import { Token } from "../../src/ast/node/token.ts";
|
|
14
|
+
import { TokenKind } from "../../src/ast/node/enum/token-kind.ts";
|
|
15
|
+
import { MissingError } from "../../src/ast/node/missing-error.ts";
|
|
16
|
+
import { UnexpectedError } from "../../src/ast/node/unexpected-error.ts";
|
|
17
|
+
|
|
18
|
+
const lenientSdlParser = createLenientSdlParser();
|
|
19
|
+
const strictSdlParser = createStrictSdlParser();
|
|
20
|
+
|
|
21
|
+
describe("buildAst Tests", () => {
|
|
22
|
+
test("Parse tree with parse error of missing token SyntaxError fails with non-lenient AST", () => {
|
|
23
|
+
const sdlStringInput = new SdlStringInput("int i;");
|
|
24
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
25
|
+
|
|
26
|
+
expect(() => buildAst(parseTree, sdlStringInput)).toThrow(
|
|
27
|
+
"SYNTAX ERROR: Expected: computed => { row: 1, column: 1, position: 0 }",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("Parse tree with parse error of missing expected node SyntaxError fails with non-lenient AST", () => {
|
|
32
|
+
const sdlStringInput = new SdlStringInput("§");
|
|
33
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
34
|
+
|
|
35
|
+
expect(() => buildAst(parseTree, sdlStringInput)).toThrow(
|
|
36
|
+
"SYNTAX ERROR: Unknown token: § => { row: 1, column: 1, position: 0 }",
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Parse tree with no content works with non-lenient AST", () => {
|
|
41
|
+
const sdlStringInput = new SdlStringInput("");
|
|
42
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
43
|
+
|
|
44
|
+
buildAst(parseTree, sdlStringInput);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("Parse tree with parse error of unexpected token SyntaxError fails with non-lenient AST", () => {
|
|
48
|
+
const sdlStringInput = new SdlStringInput("1");
|
|
49
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
50
|
+
|
|
51
|
+
expect(() => buildAst(parseTree, sdlStringInput)).toThrow(
|
|
52
|
+
"SYNTAX ERROR: Unexpected: 1 => { row: 1, column: 1, position: 0 }",
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("Parse tree with parse error of token SyntaxError works with lenient AST", () => {
|
|
57
|
+
const sdlStringInput = new SdlStringInput("int i;");
|
|
58
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
59
|
+
|
|
60
|
+
buildAst(parseTree, sdlStringInput, true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("Parse tree with parse error of missing expected node SyntaxError works with lenient AST", () => {
|
|
64
|
+
const sdlStringInput = new SdlStringInput("§");
|
|
65
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
66
|
+
|
|
67
|
+
buildAst(parseTree, sdlStringInput, true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("Parse tree with no content works with lenient AST", () => {
|
|
71
|
+
const sdlStringInput = new SdlStringInput("");
|
|
72
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
73
|
+
|
|
74
|
+
buildAst(parseTree, sdlStringInput, true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("Parse tree with parse error of unexpected node SyntaxError works with lenient AST", () => {
|
|
78
|
+
const sdlStringInput = new SdlStringInput("1");
|
|
79
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
80
|
+
|
|
81
|
+
buildAst(parseTree, sdlStringInput, true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("Comment only", () => {
|
|
85
|
+
const sdlStringInput = new SdlStringInput(" // hello world");
|
|
86
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
87
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
88
|
+
const expected = new Specification([]);
|
|
89
|
+
|
|
90
|
+
expected.trailingTrivia = [
|
|
91
|
+
{ text: "// hello world", location: { row: 1, column: 2, position: 1 } },
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
expect(
|
|
95
|
+
specification,
|
|
96
|
+
).toEqual(
|
|
97
|
+
expected,
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("Simple", () => {
|
|
102
|
+
const sdlStringInput = new SdlStringInput("class A {}");
|
|
103
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
104
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
105
|
+
const classToken = new Token(
|
|
106
|
+
TokenKind.CLASS,
|
|
107
|
+
"class",
|
|
108
|
+
{ row: 1, column: 1, position: 0 },
|
|
109
|
+
);
|
|
110
|
+
const identifier = new Identifier(
|
|
111
|
+
"A",
|
|
112
|
+
new Token(
|
|
113
|
+
TokenKind.IDENTIFIER,
|
|
114
|
+
"A",
|
|
115
|
+
{ row: 1, column: 7, position: 6 },
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
const openBraceToken = new Token(
|
|
119
|
+
TokenKind.OPEN_BRACE,
|
|
120
|
+
"{",
|
|
121
|
+
{ row: 1, column: 9, position: 8 },
|
|
122
|
+
);
|
|
123
|
+
const closeBraceToken = new Token(
|
|
124
|
+
TokenKind.CLOSE_BRACE,
|
|
125
|
+
"}",
|
|
126
|
+
{ row: 1, column: 10, position: 9 },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(
|
|
130
|
+
specification,
|
|
131
|
+
).toEqual(
|
|
132
|
+
new Specification(
|
|
133
|
+
[
|
|
134
|
+
new ClassDeclaration(
|
|
135
|
+
undefined,
|
|
136
|
+
undefined,
|
|
137
|
+
undefined,
|
|
138
|
+
classToken,
|
|
139
|
+
identifier,
|
|
140
|
+
undefined,
|
|
141
|
+
undefined,
|
|
142
|
+
undefined,
|
|
143
|
+
openBraceToken,
|
|
144
|
+
[],
|
|
145
|
+
closeBraceToken,
|
|
146
|
+
[classToken, identifier, openBraceToken, closeBraceToken],
|
|
147
|
+
),
|
|
148
|
+
],
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("Simple with comments", () => {
|
|
154
|
+
const sdlStringInput = new SdlStringInput(
|
|
155
|
+
"// hello\nclass A {// world\n}// again",
|
|
156
|
+
);
|
|
157
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
158
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
159
|
+
|
|
160
|
+
const classToken = new Token(
|
|
161
|
+
TokenKind.CLASS,
|
|
162
|
+
"class",
|
|
163
|
+
{ row: 2, column: 1, position: 9 },
|
|
164
|
+
);
|
|
165
|
+
const identifier = new Identifier(
|
|
166
|
+
"A",
|
|
167
|
+
new Token(
|
|
168
|
+
TokenKind.IDENTIFIER,
|
|
169
|
+
"A",
|
|
170
|
+
{ row: 2, column: 7, position: 15 },
|
|
171
|
+
),
|
|
172
|
+
);
|
|
173
|
+
const openBraceToken = new Token(
|
|
174
|
+
TokenKind.OPEN_BRACE,
|
|
175
|
+
"{",
|
|
176
|
+
{ row: 2, column: 9, position: 17 },
|
|
177
|
+
);
|
|
178
|
+
const closeBraceToken = new Token(
|
|
179
|
+
TokenKind.CLOSE_BRACE,
|
|
180
|
+
"}",
|
|
181
|
+
{ row: 3, column: 1, position: 27 },
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const classDeclaration = new ClassDeclaration(
|
|
185
|
+
undefined,
|
|
186
|
+
undefined,
|
|
187
|
+
undefined,
|
|
188
|
+
classToken,
|
|
189
|
+
identifier,
|
|
190
|
+
undefined,
|
|
191
|
+
undefined,
|
|
192
|
+
undefined,
|
|
193
|
+
openBraceToken,
|
|
194
|
+
[],
|
|
195
|
+
closeBraceToken,
|
|
196
|
+
[classToken, identifier, openBraceToken, closeBraceToken],
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
classDeclaration.leadingTrivia = [
|
|
200
|
+
{ text: "// hello", location: { row: 1, column: 1, position: 0 } },
|
|
201
|
+
];
|
|
202
|
+
classDeclaration.trailingTrivia = [
|
|
203
|
+
{ text: "// again", location: { row: 3, column: 2, position: 28 } },
|
|
204
|
+
];
|
|
205
|
+
openBraceToken.trailingTrivia = [
|
|
206
|
+
{ text: "// world", location: { row: 2, column: 10, position: 18 } },
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
expect(
|
|
210
|
+
specification,
|
|
211
|
+
).toEqual(
|
|
212
|
+
new Specification(
|
|
213
|
+
[
|
|
214
|
+
classDeclaration,
|
|
215
|
+
],
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("Lenient with missing identifier", () => {
|
|
221
|
+
const sdlStringInput = new SdlStringInput("class {}");
|
|
222
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
223
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
224
|
+
const classToken = new Token(
|
|
225
|
+
TokenKind.CLASS,
|
|
226
|
+
"class",
|
|
227
|
+
{ row: 1, column: 1, position: 0 },
|
|
228
|
+
);
|
|
229
|
+
const identifier = new MissingError({ row: 1, column: 7, position: 6 });
|
|
230
|
+
const openBraceToken = new Token(
|
|
231
|
+
TokenKind.OPEN_BRACE,
|
|
232
|
+
"{",
|
|
233
|
+
{ row: 1, column: 7, position: 6 },
|
|
234
|
+
);
|
|
235
|
+
const closeBraceToken = new Token(
|
|
236
|
+
TokenKind.CLOSE_BRACE,
|
|
237
|
+
"}",
|
|
238
|
+
{ row: 1, column: 8, position: 7 },
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
expect(
|
|
242
|
+
specification,
|
|
243
|
+
).toEqual(
|
|
244
|
+
new Specification(
|
|
245
|
+
[
|
|
246
|
+
new ClassDeclaration(
|
|
247
|
+
undefined,
|
|
248
|
+
undefined,
|
|
249
|
+
undefined,
|
|
250
|
+
classToken,
|
|
251
|
+
identifier,
|
|
252
|
+
undefined,
|
|
253
|
+
undefined,
|
|
254
|
+
undefined,
|
|
255
|
+
openBraceToken,
|
|
256
|
+
[],
|
|
257
|
+
closeBraceToken,
|
|
258
|
+
[classToken, identifier, openBraceToken, closeBraceToken],
|
|
259
|
+
),
|
|
260
|
+
],
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("Lenient with multiple missing tokens", () => {
|
|
266
|
+
const sdlStringInput = new SdlStringInput("class A { - }");
|
|
267
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
268
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
269
|
+
|
|
270
|
+
const classToken = new Token(
|
|
271
|
+
TokenKind.CLASS,
|
|
272
|
+
"class",
|
|
273
|
+
{ row: 1, column: 1, position: 0 },
|
|
274
|
+
);
|
|
275
|
+
const identifier = new Identifier(
|
|
276
|
+
"A",
|
|
277
|
+
new Token(
|
|
278
|
+
TokenKind.IDENTIFIER,
|
|
279
|
+
"A",
|
|
280
|
+
{ row: 1, column: 7, position: 6 },
|
|
281
|
+
),
|
|
282
|
+
);
|
|
283
|
+
const openBraceToken = new Token(
|
|
284
|
+
TokenKind.OPEN_BRACE,
|
|
285
|
+
"{",
|
|
286
|
+
{ row: 1, column: 9, position: 8 },
|
|
287
|
+
);
|
|
288
|
+
const unaryOperatorToken = new Token(
|
|
289
|
+
TokenKind.UNARY_NEGATION,
|
|
290
|
+
"-",
|
|
291
|
+
{ row: 1, column: 11, position: 10 },
|
|
292
|
+
);
|
|
293
|
+
const missingOperandToken = new MissingError({
|
|
294
|
+
row: 1,
|
|
295
|
+
column: 13,
|
|
296
|
+
position: 12,
|
|
297
|
+
});
|
|
298
|
+
const unaryExpression = new UnaryExpression(
|
|
299
|
+
unaryOperatorToken,
|
|
300
|
+
undefined,
|
|
301
|
+
missingOperandToken,
|
|
302
|
+
undefined,
|
|
303
|
+
undefined,
|
|
304
|
+
undefined,
|
|
305
|
+
undefined,
|
|
306
|
+
[unaryOperatorToken, missingOperandToken],
|
|
307
|
+
);
|
|
308
|
+
const missingSemicolonPunctuator = new MissingError({
|
|
309
|
+
row: 1,
|
|
310
|
+
column: 13,
|
|
311
|
+
position: 12,
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const expressionStatement = new ExpressionStatement(
|
|
315
|
+
unaryExpression,
|
|
316
|
+
missingSemicolonPunctuator,
|
|
317
|
+
[unaryExpression, missingSemicolonPunctuator],
|
|
318
|
+
);
|
|
319
|
+
const closeBraceToken = new Token(
|
|
320
|
+
TokenKind.CLOSE_BRACE,
|
|
321
|
+
"}",
|
|
322
|
+
{ row: 1, column: 13, position: 12 },
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(
|
|
326
|
+
specification,
|
|
327
|
+
).toEqual(
|
|
328
|
+
new Specification(
|
|
329
|
+
[
|
|
330
|
+
new ClassDeclaration(
|
|
331
|
+
undefined,
|
|
332
|
+
undefined,
|
|
333
|
+
undefined,
|
|
334
|
+
classToken,
|
|
335
|
+
identifier,
|
|
336
|
+
undefined,
|
|
337
|
+
undefined,
|
|
338
|
+
undefined,
|
|
339
|
+
openBraceToken,
|
|
340
|
+
[
|
|
341
|
+
expressionStatement,
|
|
342
|
+
],
|
|
343
|
+
closeBraceToken,
|
|
344
|
+
[
|
|
345
|
+
classToken,
|
|
346
|
+
identifier,
|
|
347
|
+
openBraceToken,
|
|
348
|
+
expressionStatement,
|
|
349
|
+
closeBraceToken,
|
|
350
|
+
],
|
|
351
|
+
),
|
|
352
|
+
],
|
|
353
|
+
),
|
|
354
|
+
);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("Comment within syntax element", () => {
|
|
358
|
+
const sdlStringInput = new SdlStringInput("class A {i++// comment\n;}");
|
|
359
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
360
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
361
|
+
|
|
362
|
+
expect(specification).toMatchSnapshot();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("JSON", () => {
|
|
366
|
+
const sdlStringInput = new SdlStringInput("computed int i;");
|
|
367
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
368
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
369
|
+
const actual = JSON.stringify(specification);
|
|
370
|
+
|
|
371
|
+
expect(actual).toMatchSnapshot();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test("Leading comment", () => {
|
|
375
|
+
const sdlStringInput = new SdlStringInput(
|
|
376
|
+
"class A{\n // Le lorem ipsum est, en imprimerie, une suite de mots sans signification utilisée\n}",
|
|
377
|
+
);
|
|
378
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
379
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
380
|
+
|
|
381
|
+
expect(specification).toMatchSnapshot();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test("Leading and trailing comments", () => {
|
|
385
|
+
const sdlStringInput = new SdlStringInput(
|
|
386
|
+
"class A {// trailing 1\ni++; // trailing 2\n//leading 1\nN = N + // trailing 3\n 1;}\n// trailing 4",
|
|
387
|
+
);
|
|
388
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
389
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
390
|
+
|
|
391
|
+
expect(specification).toMatchSnapshot();
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test("Switch statement", () => {
|
|
395
|
+
const sdlStringInput = new SdlStringInput(
|
|
396
|
+
"class A{switch (1) { case 1: break; default: i++; }}",
|
|
397
|
+
);
|
|
398
|
+
const parseTree = strictSdlParser.parse(sdlStringInput);
|
|
399
|
+
const specification = buildAst(parseTree, sdlStringInput);
|
|
400
|
+
|
|
401
|
+
expect(specification).toMatchSnapshot();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
test("Invalid elementary type definition", () => {
|
|
405
|
+
const sdlStringInput = new SdlStringInput(
|
|
406
|
+
"class A{bit transport_priority;}",
|
|
407
|
+
);
|
|
408
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
409
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
410
|
+
|
|
411
|
+
expect(specification).toMatchSnapshot();
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("Single invalid token", () => {
|
|
415
|
+
const sdlStringInput = new SdlStringInput(
|
|
416
|
+
"§\n",
|
|
417
|
+
);
|
|
418
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
419
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
420
|
+
|
|
421
|
+
const unknownToken = new Token(
|
|
422
|
+
TokenKind.ERROR_UNKNOWN_TOKEN,
|
|
423
|
+
"§",
|
|
424
|
+
{ row: 1, column: 1, position: 0 },
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
const unexpectedError = new UnexpectedError(unknownToken);
|
|
428
|
+
|
|
429
|
+
expect(specification).toEqual(
|
|
430
|
+
new Specification([unexpectedError]),
|
|
431
|
+
);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("Invalid various elements 1", () => {
|
|
435
|
+
const sdlStringInput = new SdlStringInput(
|
|
436
|
+
"class A{if(a fie==1) {}}\n",
|
|
437
|
+
);
|
|
438
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
439
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
440
|
+
|
|
441
|
+
expect(specification).toMatchSnapshot();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test("Invalid various elements 2", () => {
|
|
445
|
+
const sdlStringInput = new SdlStringInput(
|
|
446
|
+
"class A{if(a fie==1){}}\n",
|
|
447
|
+
);
|
|
448
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
449
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
450
|
+
|
|
451
|
+
expect(specification).toMatchSnapshot();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("While statement", () => {
|
|
455
|
+
const sdlStringInput = new SdlStringInput(
|
|
456
|
+
"class A{while(i<2){i++;}}\n",
|
|
457
|
+
);
|
|
458
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
459
|
+
const specification = buildAst(parseTree, sdlStringInput, true);
|
|
460
|
+
|
|
461
|
+
expect(specification).toMatchSnapshot();
|
|
462
|
+
});
|
|
463
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { type Buffer } from "node:buffer";
|
|
4
|
+
import { promises as fs } from "node:fs";
|
|
5
|
+
import HistoryRecordingNodeHandler, {
|
|
6
|
+
expectedHistory,
|
|
7
|
+
} from "../../fixtures/history-recording-node-handler.ts";
|
|
8
|
+
import { createStrictSdlParser } from "../../../src/lezer/create-sdl-parser.ts";
|
|
9
|
+
import { TraversingVisitor } from "../../../src/ast/visitor/traversing-visitor.ts";
|
|
10
|
+
import { SdlStringInput } from "../../../src/lezer/sdl-string-input.ts";
|
|
11
|
+
import { buildAst } from "../../../src/ast/build-ast.ts";
|
|
12
|
+
|
|
13
|
+
describe("TraversingVisitor Tests", () => {
|
|
14
|
+
test("Test traversing visitor", async () => {
|
|
15
|
+
const sdlSource = await fs.readFile(
|
|
16
|
+
path.join(__dirname, "../../sample-specifications/sample.sdl"),
|
|
17
|
+
).then((buffer: Buffer) => buffer.toString());
|
|
18
|
+
const sdlStringInput = new SdlStringInput(sdlSource);
|
|
19
|
+
const sdlParser = createStrictSdlParser();
|
|
20
|
+
const sdlParseTree = sdlParser.parse(sdlStringInput);
|
|
21
|
+
const specification = buildAst(sdlParseTree, sdlStringInput);
|
|
22
|
+
|
|
23
|
+
const historyRecordingNodeHandler = new HistoryRecordingNodeHandler();
|
|
24
|
+
const traversingVisitor = new TraversingVisitor(
|
|
25
|
+
historyRecordingNodeHandler,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
traversingVisitor.visit(specification);
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
historyRecordingNodeHandler.nodeHistory,
|
|
32
|
+
).toEqual(
|
|
33
|
+
expectedHistory,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, test } from "bun:test";
|
|
2
|
+
import { testPotentialSyntacticTokensScenario } from "./test-potential-syntactic-tokens-scenario.ts";
|
|
3
|
+
|
|
4
|
+
describe("getPotentialSyntacticTokens Tests", () => {
|
|
5
|
+
test("Test missing length attribute potential syntactic token scenario", () => {
|
|
6
|
+
testPotentialSyntacticTokensScenario(
|
|
7
|
+
"class A { bit b; }",
|
|
8
|
+
14,
|
|
9
|
+
["("],
|
|
10
|
+
);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("Test duplicate identifier potential syntactic token scenario", () => {
|
|
14
|
+
testPotentialSyntacticTokensScenario(
|
|
15
|
+
"class A {if (f oo) {bit(8) c;}}",
|
|
16
|
+
15,
|
|
17
|
+
[
|
|
18
|
+
"!=",
|
|
19
|
+
"%",
|
|
20
|
+
"&",
|
|
21
|
+
"&&",
|
|
22
|
+
"*",
|
|
23
|
+
"+",
|
|
24
|
+
"-",
|
|
25
|
+
"/",
|
|
26
|
+
"<",
|
|
27
|
+
"<<",
|
|
28
|
+
"<=",
|
|
29
|
+
"==",
|
|
30
|
+
">",
|
|
31
|
+
">=",
|
|
32
|
+
">>",
|
|
33
|
+
"|",
|
|
34
|
+
"||",
|
|
35
|
+
].sort(),
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Test complex potential syntactic token scenario", () => {
|
|
40
|
+
testPotentialSyntacticTokensScenario(
|
|
41
|
+
"class A {if (a b == 0b01 || c == 0b11) {bit(8) c;}}",
|
|
42
|
+
15,
|
|
43
|
+
[
|
|
44
|
+
"!=",
|
|
45
|
+
"%",
|
|
46
|
+
"&",
|
|
47
|
+
"&&",
|
|
48
|
+
")",
|
|
49
|
+
"*",
|
|
50
|
+
"+",
|
|
51
|
+
"-",
|
|
52
|
+
"/",
|
|
53
|
+
"<",
|
|
54
|
+
"<<",
|
|
55
|
+
"<=",
|
|
56
|
+
"==",
|
|
57
|
+
">",
|
|
58
|
+
">=",
|
|
59
|
+
">>",
|
|
60
|
+
"|",
|
|
61
|
+
"||",
|
|
62
|
+
].sort(),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("Test global scope potential syntactic token scenario", () => {
|
|
67
|
+
testPotentialSyntacticTokensScenario(
|
|
68
|
+
"",
|
|
69
|
+
0,
|
|
70
|
+
["abstract", "aligned", "class", "computed", "expandable", "map"].sort(),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("Test global scope with previous comment potential syntactic token scenario 1", () => {
|
|
75
|
+
testPotentialSyntacticTokensScenario(
|
|
76
|
+
"// foo",
|
|
77
|
+
6,
|
|
78
|
+
undefined,
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("Test global scope with previous comment potential syntactic token scenario 2", () => {
|
|
83
|
+
testPotentialSyntacticTokensScenario(
|
|
84
|
+
"// foo\n ",
|
|
85
|
+
8,
|
|
86
|
+
["abstract", "aligned", "class", "computed", "expandable", "map"].sort(),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, test } from "bun:test";
|
|
2
|
+
import { testPotentialTokenTypeIdsScenario } from "./test-potential-token-type-ids-scenario.ts";
|
|
3
|
+
|
|
4
|
+
// Generated by Lezer from the SDL grammar
|
|
5
|
+
import * as TokenTypeId from "../../src/lezer/parser.terms.ts";
|
|
6
|
+
|
|
7
|
+
describe("getPotentialTokenTypeIds Tests", () => {
|
|
8
|
+
test("Test missing length attribute expected token type scenario", () => {
|
|
9
|
+
testPotentialTokenTypeIdsScenario(
|
|
10
|
+
"class A { bit b; }",
|
|
11
|
+
[TokenTypeId.LengthAttribute],
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("Test duplicate identifier expected token type scenario", () => {
|
|
16
|
+
testPotentialTokenTypeIdsScenario(
|
|
17
|
+
"class A {if (f oo) {bit(8) c;}}",
|
|
18
|
+
[
|
|
19
|
+
TokenTypeId.Multiplication,
|
|
20
|
+
TokenTypeId.Division,
|
|
21
|
+
TokenTypeId.Modulus,
|
|
22
|
+
TokenTypeId.Addition,
|
|
23
|
+
TokenTypeId.Subtraction,
|
|
24
|
+
TokenTypeId.BitwiseShiftLeft,
|
|
25
|
+
TokenTypeId.BitwiseShiftRight,
|
|
26
|
+
TokenTypeId.RelationalLessThan,
|
|
27
|
+
TokenTypeId.RelationalLessThanOrEqual,
|
|
28
|
+
TokenTypeId.RelationalGreaterThan,
|
|
29
|
+
TokenTypeId.RelationalGreaterThanOrEqual,
|
|
30
|
+
TokenTypeId.RelationalEqual,
|
|
31
|
+
TokenTypeId.RelationalNotEqual,
|
|
32
|
+
TokenTypeId.BitwiseAnd,
|
|
33
|
+
TokenTypeId.BitwiseOr,
|
|
34
|
+
TokenTypeId.LogicalAnd,
|
|
35
|
+
TokenTypeId.LogicalOr,
|
|
36
|
+
].sort((a, b) => a - b),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Test complex expected token type scenario", () => {
|
|
41
|
+
testPotentialTokenTypeIdsScenario(
|
|
42
|
+
"class A {if (a b == 0b01 || c == 0b11) {bit(8) c;}}",
|
|
43
|
+
[
|
|
44
|
+
TokenTypeId.CloseParenthesis,
|
|
45
|
+
TokenTypeId.Multiplication,
|
|
46
|
+
TokenTypeId.Division,
|
|
47
|
+
TokenTypeId.Modulus,
|
|
48
|
+
TokenTypeId.Addition,
|
|
49
|
+
TokenTypeId.Subtraction,
|
|
50
|
+
TokenTypeId.BitwiseShiftLeft,
|
|
51
|
+
TokenTypeId.BitwiseShiftRight,
|
|
52
|
+
TokenTypeId.RelationalLessThan,
|
|
53
|
+
TokenTypeId.RelationalLessThanOrEqual,
|
|
54
|
+
TokenTypeId.RelationalGreaterThan,
|
|
55
|
+
TokenTypeId.RelationalGreaterThanOrEqual,
|
|
56
|
+
TokenTypeId.RelationalEqual,
|
|
57
|
+
TokenTypeId.RelationalNotEqual,
|
|
58
|
+
TokenTypeId.BitwiseAnd,
|
|
59
|
+
TokenTypeId.BitwiseOr,
|
|
60
|
+
TokenTypeId.LogicalAnd,
|
|
61
|
+
TokenTypeId.LogicalOr,
|
|
62
|
+
].sort((a, b) => a - b),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("Test global scope expected token type scenario", () => {
|
|
67
|
+
testPotentialTokenTypeIdsScenario(
|
|
68
|
+
"",
|
|
69
|
+
[
|
|
70
|
+
TokenTypeId.ClassDeclaration,
|
|
71
|
+
TokenTypeId.ComputedElementaryTypeDefinition,
|
|
72
|
+
TokenTypeId.MapDeclaration,
|
|
73
|
+
].sort((a, b) => a - b),
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect } from "bun:test";
|
|
2
|
+
import { createLenientSdlParser } from "../../src/lezer/create-sdl-parser.ts";
|
|
3
|
+
import { SdlStringInput } from "../../index.ts";
|
|
4
|
+
import { getPotentialSyntacticTokens } from "../../src/completion/get-potential-syntactic-tokens.ts";
|
|
5
|
+
|
|
6
|
+
const lenientSdlParser = createLenientSdlParser();
|
|
7
|
+
|
|
8
|
+
export function testPotentialSyntacticTokensScenario(
|
|
9
|
+
source: string,
|
|
10
|
+
position: number,
|
|
11
|
+
expectedSyntacticTokens: string[] | undefined,
|
|
12
|
+
) {
|
|
13
|
+
const sdlStringInput = new SdlStringInput(source);
|
|
14
|
+
const parseTree = lenientSdlParser.parse(sdlStringInput);
|
|
15
|
+
const lastNode = parseTree.resolveInner(position, -1);
|
|
16
|
+
|
|
17
|
+
const actualSyntacticTokens = getPotentialSyntacticTokens(lastNode.cursor());
|
|
18
|
+
|
|
19
|
+
if (!actualSyntacticTokens && expectedSyntacticTokens) {
|
|
20
|
+
throw new Error("Expected syntactic tokens to be defined");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
expect(actualSyntacticTokens).toEqual(expectedSyntacticTokens);
|
|
24
|
+
}
|