@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
package/src/location.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a location within a text document.
|
|
3
|
+
*
|
|
4
|
+
* @interface Location
|
|
5
|
+
* @property {number} row - The one-based row number in the text document.
|
|
6
|
+
* @property {number} column - The one-based column number in the text document.
|
|
7
|
+
* @property {number} position - The zero-based position within the entire text.
|
|
8
|
+
*/
|
|
9
|
+
export interface Location {
|
|
10
|
+
readonly row: number;
|
|
11
|
+
readonly column: number;
|
|
12
|
+
readonly position: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type Tree } from "@lezer/common";
|
|
2
|
+
import type { NodeHandler } from "./ast/visitor/node-handler.ts";
|
|
3
|
+
import type { Specification } from "./ast/node/specification.ts";
|
|
4
|
+
import { SyntaxError } from "./scanner-error.ts";
|
|
5
|
+
import { TraversingVisitor } from "./ast/visitor/traversing-visitor.ts";
|
|
6
|
+
import * as prettier from "prettier/standalone.js";
|
|
7
|
+
import { prettierPluginSdl } from "./prettier/prettier-plugin-sdl.ts";
|
|
8
|
+
import type { Plugin } from "prettier";
|
|
9
|
+
import { Text } from "@codemirror/state";
|
|
10
|
+
import type { AbstractNode } from "./ast/node/abstract-node.ts";
|
|
11
|
+
import { SdlStringInput } from "./lezer/sdl-string-input.ts";
|
|
12
|
+
import { createSyntaxErrorFromTextAndCursor } from "./lezer/create-syntax-error-from-text-and-cursor.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a dynamic prettier plugin for SDL using the pre-parsed AST.
|
|
16
|
+
*/
|
|
17
|
+
function getPreParsedAstPrettierPlugin(
|
|
18
|
+
specification: Specification,
|
|
19
|
+
): Plugin<AbstractNode> {
|
|
20
|
+
const prettierPluginSdlParser = prettierPluginSdl.parsers!.sdl!;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
languages: prettierPluginSdl.languages,
|
|
24
|
+
parsers: {
|
|
25
|
+
sdl: {
|
|
26
|
+
astFormat: prettierPluginSdlParser.astFormat,
|
|
27
|
+
parse: () => specification,
|
|
28
|
+
locStart: prettierPluginSdlParser.locStart,
|
|
29
|
+
locEnd: prettierPluginSdlParser.locEnd,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
printers: prettierPluginSdl.printers,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Return a collated list of syntax errors from the parse tree.
|
|
38
|
+
*
|
|
39
|
+
* @param parseTree The parse tree generated from the source string.
|
|
40
|
+
* @param sdlStringInput The SDL source `StringInput`.
|
|
41
|
+
*/
|
|
42
|
+
export function collateSyntaxErrors(
|
|
43
|
+
parseTree: Tree,
|
|
44
|
+
sdlStringInput: SdlStringInput,
|
|
45
|
+
): SyntaxError[] {
|
|
46
|
+
const text = Text.of(
|
|
47
|
+
sdlStringInput.read(0, sdlStringInput.length).split("\n"),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const syntaxErrors = [];
|
|
51
|
+
const cursor = parseTree.cursor();
|
|
52
|
+
do {
|
|
53
|
+
if (cursor.type.isError) {
|
|
54
|
+
syntaxErrors.push(createSyntaxErrorFromTextAndCursor(text, cursor));
|
|
55
|
+
}
|
|
56
|
+
} while (cursor.next());
|
|
57
|
+
|
|
58
|
+
return syntaxErrors;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Prettify the source.
|
|
63
|
+
*
|
|
64
|
+
* @param specification The specification to be used for the pre-parsed AST.
|
|
65
|
+
* @param sdlStringInput The SDL source `StringInput`.
|
|
66
|
+
* @param lineWidth The line width to format to.
|
|
67
|
+
*/
|
|
68
|
+
export function prettyPrint(
|
|
69
|
+
specification: Specification,
|
|
70
|
+
sdlStringInput: SdlStringInput,
|
|
71
|
+
lineWidth = 80,
|
|
72
|
+
): Promise<string> {
|
|
73
|
+
return prettier.format(sdlStringInput.read(0, sdlStringInput.length), {
|
|
74
|
+
parser: "sdl",
|
|
75
|
+
plugins: [getPreParsedAstPrettierPlugin(specification)],
|
|
76
|
+
printWidth: lineWidth,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Dispatch a node handler to visit all nodes in the abstract syntax tree.
|
|
82
|
+
*
|
|
83
|
+
* @param specification The specification to be traversed.
|
|
84
|
+
* @param nodeHandler The handler to perform operations on each node.
|
|
85
|
+
*/
|
|
86
|
+
export function dispatchNodeHandler(
|
|
87
|
+
specification: Specification,
|
|
88
|
+
nodeHandler: NodeHandler,
|
|
89
|
+
) {
|
|
90
|
+
const traversingVisitor = new TraversingVisitor(nodeHandler);
|
|
91
|
+
|
|
92
|
+
traversingVisitor.visit(specification);
|
|
93
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Parser, Plugin, Printer, SupportLanguage } from "prettier";
|
|
2
|
+
import { printAbstractNode } from "./print-abstract-node.ts";
|
|
3
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
4
|
+
import { createLenientSdlParser } from "../lezer/create-sdl-parser.ts";
|
|
5
|
+
import { buildAst } from "../ast/build-ast.ts";
|
|
6
|
+
import { SdlStringInput } from "../lezer/sdl-string-input.ts";
|
|
7
|
+
import {
|
|
8
|
+
isCompositeNode,
|
|
9
|
+
isToken,
|
|
10
|
+
type RequiredNode,
|
|
11
|
+
} from "../ast/util/types.ts";
|
|
12
|
+
import type { Token } from "../ast/node/token.ts";
|
|
13
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
14
|
+
import { NodeKind } from "../ast/node/enum/node-kind.ts";
|
|
15
|
+
|
|
16
|
+
const languages: SupportLanguage[] = [
|
|
17
|
+
{
|
|
18
|
+
name: "sdl",
|
|
19
|
+
parsers: ["sdl"],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const parsers: Record<string, Parser<RequiredNode<AbstractNode>>> = {
|
|
24
|
+
sdl: {
|
|
25
|
+
astFormat: "sdl",
|
|
26
|
+
parse: (sdlSpecification: string) => {
|
|
27
|
+
const sdlStringInput = new SdlStringInput(sdlSpecification);
|
|
28
|
+
const sdlParser = createLenientSdlParser();
|
|
29
|
+
const parseTree = sdlParser.parse(sdlSpecification);
|
|
30
|
+
|
|
31
|
+
return buildAst(parseTree, sdlStringInput, true);
|
|
32
|
+
},
|
|
33
|
+
locStart: (node: RequiredNode<AbstractNode>) => {
|
|
34
|
+
let token: Token;
|
|
35
|
+
if (isCompositeNode(node)) {
|
|
36
|
+
if (!node.startToken) {
|
|
37
|
+
throw new InternalScannerError(
|
|
38
|
+
"Composite node does not have a start token.",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
token = node.startToken;
|
|
42
|
+
} else if (isToken(node)) {
|
|
43
|
+
token = node;
|
|
44
|
+
} else {
|
|
45
|
+
throw new InternalScannerError(
|
|
46
|
+
"Unsupported node for prettierPluginSdl: " + NodeKind[node.nodeKind],
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return (token.leadingTrivia &&
|
|
50
|
+
(token.leadingTrivia.length > 0))
|
|
51
|
+
? token.leadingTrivia[0].location.position
|
|
52
|
+
: token.getLocation().position;
|
|
53
|
+
},
|
|
54
|
+
locEnd: (node: RequiredNode<AbstractNode>) => {
|
|
55
|
+
let token: Token;
|
|
56
|
+
if (isCompositeNode(node)) {
|
|
57
|
+
if (!node.endToken) {
|
|
58
|
+
throw new InternalScannerError(
|
|
59
|
+
"Composite node does not have an end token.",
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
token = node.endToken;
|
|
63
|
+
} else if (isToken(node)) {
|
|
64
|
+
token = node;
|
|
65
|
+
} else {
|
|
66
|
+
throw new InternalScannerError(
|
|
67
|
+
"Unsupported node for prettierPluginSdl: " + NodeKind[node.nodeKind],
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return (token.trailingTrivia &&
|
|
71
|
+
(token.trailingTrivia.length > 0))
|
|
72
|
+
? token.trailingTrivia[token.trailingTrivia.length - 1].location
|
|
73
|
+
.position
|
|
74
|
+
: token.getLocation().position;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const printers: Record<string, Printer<RequiredNode<AbstractNode>>> = {
|
|
80
|
+
"sdl": {
|
|
81
|
+
print: printAbstractNode,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const prettierPluginSdl: Plugin = {
|
|
86
|
+
languages,
|
|
87
|
+
parsers,
|
|
88
|
+
printers,
|
|
89
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AbstractArrayDimension } from "../ast/node/abstract-array-dimension.ts";
|
|
3
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
4
|
+
import { ArrayDimensionKind } from "../ast/node/enum/array-dimension-kind.ts";
|
|
5
|
+
import type { ExplicitArrayDimension } from "../ast/node/explicit-array-dimension.ts";
|
|
6
|
+
import type { ImplicitArrayDimension } from "../ast/node/implicit-array-dimension.ts";
|
|
7
|
+
import type { PartialArrayDimension } from "../ast/node/partial-array-dimension.ts";
|
|
8
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
9
|
+
|
|
10
|
+
export function printAbstractArrayDimension(
|
|
11
|
+
path: AstPath<AbstractArrayDimension>,
|
|
12
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
13
|
+
): Doc {
|
|
14
|
+
const { arrayDimensionKind } = path.node;
|
|
15
|
+
|
|
16
|
+
switch (arrayDimensionKind) {
|
|
17
|
+
case ArrayDimensionKind.EXPLICIT: {
|
|
18
|
+
return [
|
|
19
|
+
path.call(print, "openBracketPunctuator"),
|
|
20
|
+
(path as AstPath<ExplicitArrayDimension>).call(print, "size"),
|
|
21
|
+
path.call(print, "closeBracketPunctuator"),
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
case ArrayDimensionKind.PARTIAL: {
|
|
25
|
+
return [
|
|
26
|
+
path.call(print, "openBracketPunctuator"),
|
|
27
|
+
(path as AstPath<PartialArrayDimension>).call(
|
|
28
|
+
print,
|
|
29
|
+
"innerOpenBracketPunctuator",
|
|
30
|
+
),
|
|
31
|
+
(path as AstPath<PartialArrayDimension>).call(print, "index"),
|
|
32
|
+
(path as AstPath<PartialArrayDimension>).call(
|
|
33
|
+
print,
|
|
34
|
+
"innerCloseBracketPunctuator",
|
|
35
|
+
),
|
|
36
|
+
path.call(print, "closeBracketPunctuator"),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
case ArrayDimensionKind.IMPLICIT: {
|
|
40
|
+
const node = path.node as ImplicitArrayDimension;
|
|
41
|
+
const doc: Doc = [];
|
|
42
|
+
|
|
43
|
+
doc.push(
|
|
44
|
+
path.call(print, "openBracketPunctuator"),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (node.rangeStart !== undefined) {
|
|
48
|
+
doc.push(
|
|
49
|
+
path.call(
|
|
50
|
+
print,
|
|
51
|
+
"rangeStart" as keyof ImplicitArrayDimension["rangeStart"],
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (node.rangeOperator !== undefined) {
|
|
57
|
+
doc.push(
|
|
58
|
+
path.call(
|
|
59
|
+
print,
|
|
60
|
+
"rangeOperator" as keyof ImplicitArrayDimension["rangeOperator"],
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
doc.push(
|
|
64
|
+
path.call(
|
|
65
|
+
print,
|
|
66
|
+
"rangeEnd" as keyof ImplicitArrayDimension["rangeEnd"],
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
doc.push(
|
|
72
|
+
path.call(print, "closeBracketPunctuator"),
|
|
73
|
+
);
|
|
74
|
+
return doc;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
default: {
|
|
78
|
+
const exhaustiveCheck: never = arrayDimensionKind;
|
|
79
|
+
throw new InternalScannerError(
|
|
80
|
+
"Unreachable code reached, arrayDimensionKind == " + exhaustiveCheck,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AbstractClassId } from "../ast/node/abstract-class-id.ts";
|
|
3
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
4
|
+
import type { ClassId } from "../ast/node/class-id.ts";
|
|
5
|
+
import type { ClassIdRange } from "../ast/node/class-id-range.ts";
|
|
6
|
+
import { ClassIdKind } from "../ast/node/enum/class-id-kind.ts";
|
|
7
|
+
import type { ExtendedClassIdRange } from "../ast/node/extended-class-id-range.ts";
|
|
8
|
+
import { interleaveCommaSeparatorDocs } from "./util/print-utils.ts";
|
|
9
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
10
|
+
|
|
11
|
+
export function printAbstractClassId(
|
|
12
|
+
path: AstPath<AbstractClassId>,
|
|
13
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
14
|
+
): Doc {
|
|
15
|
+
const { classIdKind } = path.node;
|
|
16
|
+
|
|
17
|
+
switch (classIdKind) {
|
|
18
|
+
case ClassIdKind.SINGLE:
|
|
19
|
+
return (path as AstPath<ClassId>).call(print, "value");
|
|
20
|
+
case ClassIdKind.RANGE: {
|
|
21
|
+
return [
|
|
22
|
+
(path as AstPath<ClassIdRange>).call(print, "startClassId"),
|
|
23
|
+
(path as AstPath<ClassIdRange>).call(print, "rangeOperator"),
|
|
24
|
+
(path as AstPath<ClassIdRange>).call(print, "endClassId"),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
case ClassIdKind.EXTENDED_RANGE: {
|
|
28
|
+
const doc: Doc = [];
|
|
29
|
+
const outputValuesDoc = (path as AstPath<ExtendedClassIdRange>).map(
|
|
30
|
+
print,
|
|
31
|
+
"classIds",
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
doc.push(
|
|
35
|
+
interleaveCommaSeparatorDocs(
|
|
36
|
+
outputValuesDoc,
|
|
37
|
+
(path as AstPath<ExtendedClassIdRange>).map(
|
|
38
|
+
print,
|
|
39
|
+
"commaPunctuators",
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return doc;
|
|
45
|
+
}
|
|
46
|
+
default: {
|
|
47
|
+
const exhaustiveCheck: never = classIdKind;
|
|
48
|
+
throw new InternalScannerError(
|
|
49
|
+
"Unreachable code reached, classIdKind == " + exhaustiveCheck,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { AstPath, type Doc, doc } from "prettier";
|
|
2
|
+
import {
|
|
3
|
+
addBreakingWhitespace,
|
|
4
|
+
addNonBreakingWhitespace,
|
|
5
|
+
} from "./util/print-utils.ts";
|
|
6
|
+
import type { AbstractExpression } from "../ast/node/abstract-expression.ts";
|
|
7
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
8
|
+
import { ExpressionKind } from "../ast/node/enum/expression-kind.ts";
|
|
9
|
+
import type { LengthofExpression } from "../ast/node/length-of-expression.ts";
|
|
10
|
+
import type { BinaryExpression } from "../ast/node/binary-expression.ts";
|
|
11
|
+
import type { UnaryExpression } from "../ast/node/unary-expression.ts";
|
|
12
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
13
|
+
|
|
14
|
+
const { fill } = doc.builders;
|
|
15
|
+
type IfBreak = doc.builders.IfBreak;
|
|
16
|
+
|
|
17
|
+
function printUnaryExpression(
|
|
18
|
+
path: AstPath<UnaryExpression>,
|
|
19
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
20
|
+
): Doc {
|
|
21
|
+
const unaryExpression = path.node;
|
|
22
|
+
|
|
23
|
+
const doc: Doc = [];
|
|
24
|
+
|
|
25
|
+
if (unaryExpression.unaryOperator !== undefined) {
|
|
26
|
+
doc.push(
|
|
27
|
+
path.call(
|
|
28
|
+
print,
|
|
29
|
+
"unaryOperator" as keyof UnaryExpression["unaryOperator"],
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (unaryExpression.openParenthesisPunctuator !== undefined) {
|
|
35
|
+
doc.push(
|
|
36
|
+
path.call(
|
|
37
|
+
print,
|
|
38
|
+
"openParenthesisPunctuator" as keyof UnaryExpression[
|
|
39
|
+
"openParenthesisPunctuator"
|
|
40
|
+
],
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
doc.push(
|
|
46
|
+
path.call(
|
|
47
|
+
print,
|
|
48
|
+
"operand",
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (unaryExpression.arrayElementAccess !== undefined) {
|
|
53
|
+
doc.push(
|
|
54
|
+
...(
|
|
55
|
+
path.call(
|
|
56
|
+
print,
|
|
57
|
+
"arrayElementAccess" as keyof UnaryExpression["arrayElementAccess"],
|
|
58
|
+
) as Doc[]
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (unaryExpression.classMemberAccess !== undefined) {
|
|
64
|
+
doc.push(
|
|
65
|
+
...(path.call(
|
|
66
|
+
print,
|
|
67
|
+
"classMemberAccess" as keyof UnaryExpression["classMemberAccess"],
|
|
68
|
+
) as Doc[]),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (unaryExpression.closeParenthesisPunctuator !== undefined) {
|
|
73
|
+
doc.push(
|
|
74
|
+
path.call(
|
|
75
|
+
print,
|
|
76
|
+
"closeParenthesisPunctuator" as keyof UnaryExpression[
|
|
77
|
+
"closeParenthesisPunctuator"
|
|
78
|
+
],
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (unaryExpression.postfixOperator !== undefined) {
|
|
84
|
+
doc.push(
|
|
85
|
+
path.call(
|
|
86
|
+
print,
|
|
87
|
+
"postfixOperator" as keyof UnaryExpression["postfixOperator"],
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return doc;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function printBinaryExpression(
|
|
96
|
+
path: AstPath<BinaryExpression>,
|
|
97
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
98
|
+
): Doc {
|
|
99
|
+
let subDoc: Doc = [];
|
|
100
|
+
|
|
101
|
+
subDoc.push(path.call(print, "leftOperand"));
|
|
102
|
+
addNonBreakingWhitespace(subDoc);
|
|
103
|
+
subDoc.push(path.call(print, "binaryOperator"));
|
|
104
|
+
|
|
105
|
+
let doc: Doc = [];
|
|
106
|
+
|
|
107
|
+
doc.push(fill(subDoc));
|
|
108
|
+
|
|
109
|
+
const rightDoc = path.call(print, "rightOperand");
|
|
110
|
+
if (
|
|
111
|
+
Array.isArray(rightDoc) && (rightDoc.length === 3) &&
|
|
112
|
+
((rightDoc[1] as IfBreak).type === "if-break")
|
|
113
|
+
) {
|
|
114
|
+
subDoc = addBreakingWhitespace(subDoc);
|
|
115
|
+
subDoc.push(rightDoc[0]);
|
|
116
|
+
doc.push(rightDoc[1]);
|
|
117
|
+
doc.push(rightDoc[2]);
|
|
118
|
+
} else {
|
|
119
|
+
doc = addBreakingWhitespace(doc);
|
|
120
|
+
doc.push(rightDoc);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return doc;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function printLengthOfExpression(
|
|
127
|
+
path: AstPath<LengthofExpression>,
|
|
128
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
129
|
+
): Doc {
|
|
130
|
+
const doc: Doc = [];
|
|
131
|
+
|
|
132
|
+
doc.push(
|
|
133
|
+
path.call(print, "lengthOfKeyword"),
|
|
134
|
+
);
|
|
135
|
+
doc.push(
|
|
136
|
+
path.call(print, "openParenthesisPunctuator"),
|
|
137
|
+
);
|
|
138
|
+
doc.push(path.call(print, "operand"));
|
|
139
|
+
doc.push(
|
|
140
|
+
path.call(print, "closeParenthesisPunctuator"),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
return doc;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function printAbstractExpression(
|
|
147
|
+
path: AstPath<AbstractExpression>,
|
|
148
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
149
|
+
): Doc {
|
|
150
|
+
const { expressionKind } = path.node;
|
|
151
|
+
switch (expressionKind) {
|
|
152
|
+
case ExpressionKind.BINARY:
|
|
153
|
+
return printBinaryExpression(path as AstPath<BinaryExpression>, print);
|
|
154
|
+
case ExpressionKind.LENGTHOF:
|
|
155
|
+
return printLengthOfExpression(
|
|
156
|
+
path as AstPath<LengthofExpression>,
|
|
157
|
+
print,
|
|
158
|
+
);
|
|
159
|
+
case ExpressionKind.UNARY:
|
|
160
|
+
return printUnaryExpression(path as AstPath<UnaryExpression>, print);
|
|
161
|
+
default: {
|
|
162
|
+
const exhaustiveCheck: never = expressionKind;
|
|
163
|
+
throw new InternalScannerError(
|
|
164
|
+
"Unreachable code reached, expressionKind == " + exhaustiveCheck,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|