@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,224 @@
|
|
|
1
|
+
import { type AstPath, type Doc, type ParserOptions } from "prettier";
|
|
2
|
+
import type { AbstractArrayDimension } from "../ast/node/abstract-array-dimension.ts";
|
|
3
|
+
import type { AbstractClassId } from "../ast/node/abstract-class-id.ts";
|
|
4
|
+
import type { AbstractExpression } from "../ast/node/abstract-expression.ts";
|
|
5
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
6
|
+
import type { AbstractStatement } from "../ast/node/abstract-statement.ts";
|
|
7
|
+
import type { AlignedModifier } from "../ast/node/aligned-modifier.ts";
|
|
8
|
+
import type { ArrayElementAccess } from "../ast/node/array-element-access.ts";
|
|
9
|
+
import type { BitModifier } from "../ast/node/bit-modifier.ts";
|
|
10
|
+
import type { ClassMemberAccess } from "../ast/node/class-member-access.ts";
|
|
11
|
+
import type { ElementaryType } from "../ast/node/elementary-type.ts";
|
|
12
|
+
import type { ExpandableModifier } from "../ast/node/expandable-modifier.ts";
|
|
13
|
+
import type { ExtendsModifier } from "../ast/node/extends-modifier.ts";
|
|
14
|
+
import type { LengthAttribute } from "../ast/node/length-attribute.ts";
|
|
15
|
+
import type { MapEntry } from "../ast/node/map-entry.ts";
|
|
16
|
+
import type { NumberLiteral } from "../ast/node/number-literal.ts";
|
|
17
|
+
import type { Parameter } from "../ast/node/parameter.ts";
|
|
18
|
+
import type { ParameterList } from "../ast/node/parameter-list.ts";
|
|
19
|
+
import type { ParameterValueList } from "../ast/node/parameter-value-list.ts";
|
|
20
|
+
import type { Specification } from "../ast/node/specification.ts";
|
|
21
|
+
import type { CaseClause } from "../ast/node/case-clause.ts";
|
|
22
|
+
import type { DefaultClause } from "../ast/node/default-clause.ts";
|
|
23
|
+
import type { Identifier } from "../ast/node/identifier.ts";
|
|
24
|
+
import type { StringLiteral } from "../ast/node/string-literal.ts";
|
|
25
|
+
import type { AggregateOutputValue } from "../ast/node/aggregate-output-value.ts";
|
|
26
|
+
import type { ElementaryTypeOutputValue } from "../ast/node/elementary-type-output-value.ts";
|
|
27
|
+
import type { Token } from "../ast/node/token.ts";
|
|
28
|
+
import type { UnexpectedError } from "../ast/node/unexpected-error.ts";
|
|
29
|
+
import type { RequiredNode } from "../ast/util/types.ts";
|
|
30
|
+
import { NodeKind } from "../ast/node/enum/node-kind.ts";
|
|
31
|
+
import { printAbstractExpression } from "./print-abstract-expression.ts";
|
|
32
|
+
import { printMapEntry } from "./print-map-entry.ts";
|
|
33
|
+
import { printSpecification } from "./print-specification.ts";
|
|
34
|
+
import { printElementaryType } from "./print-elementary-type.ts";
|
|
35
|
+
import { printStringLiteral } from "./print-string-literal.ts";
|
|
36
|
+
import { printAbstractStatement } from "./print-abstract-statement.ts";
|
|
37
|
+
import {
|
|
38
|
+
addTrailingTriviaDoc,
|
|
39
|
+
endsWithHardline,
|
|
40
|
+
getLeadingTriviaDoc,
|
|
41
|
+
getTrailingTriviaDoc,
|
|
42
|
+
removeLeadingBlanklines,
|
|
43
|
+
removeTrailingHardline,
|
|
44
|
+
} from "./util/print-utils.ts";
|
|
45
|
+
import { printUnexpectedError } from "./print-unexpected-error.ts";
|
|
46
|
+
import { printAlignedModifier } from "./print-aligned-modifier.ts";
|
|
47
|
+
import { printIdentifier } from "./print-identifier.ts";
|
|
48
|
+
import { printLengthAttribute } from "./print-length-attribute.ts";
|
|
49
|
+
import { printNumberLiteral } from "./print-number-literal.ts";
|
|
50
|
+
import { printBitModifier } from "./print-bit-modifier.ts";
|
|
51
|
+
import { printAbstractClassId } from "./print-abstract-class-id.ts";
|
|
52
|
+
import { printExpandableModifier } from "./print-expandable-modifier.ts";
|
|
53
|
+
import { printExtendsModifier } from "./print-extends-modifier.ts";
|
|
54
|
+
import { printParameter } from "./print-parameter.ts";
|
|
55
|
+
import { printParameterList } from "./print-parameter-list.ts";
|
|
56
|
+
import { printParameterValueList } from "./print-parameter-value-list.ts";
|
|
57
|
+
import { printArrayElementAccess } from "./print-array-element-access.ts";
|
|
58
|
+
import { printClassMemberAccess } from "./print-class-member-access.ts";
|
|
59
|
+
import { printAggregateOutputValue } from "./print-aggregate-output-value.ts";
|
|
60
|
+
import { printElementaryTypeOutputValue } from "./print-elementary-type-output-value.ts";
|
|
61
|
+
import { printAbstractArrayDimension } from "./print-abstract-array-dimension.ts";
|
|
62
|
+
import { printCaseClause } from "./print-case-clause.ts";
|
|
63
|
+
import { printDefaultClause } from "./print-default-clause.ts";
|
|
64
|
+
import { printToken } from "./print-token.ts";
|
|
65
|
+
import { StatementKind } from "../ast/node/enum/statement-kind.ts";
|
|
66
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
67
|
+
|
|
68
|
+
export function printAbstractNode(
|
|
69
|
+
path: AstPath<RequiredNode<AbstractNode>>,
|
|
70
|
+
_options: ParserOptions<AbstractNode>,
|
|
71
|
+
print: (_path: AstPath<RequiredNode<AbstractNode>>) => Doc,
|
|
72
|
+
): Doc {
|
|
73
|
+
const node = path.node;
|
|
74
|
+
const nodeKind = node.nodeKind;
|
|
75
|
+
|
|
76
|
+
let doc: Doc = [];
|
|
77
|
+
|
|
78
|
+
let leadingTriviaDoc = getLeadingTriviaDoc(node);
|
|
79
|
+
|
|
80
|
+
if (leadingTriviaDoc) {
|
|
81
|
+
// prevent extra lines at beginning of compount statement
|
|
82
|
+
if (
|
|
83
|
+
(nodeKind === NodeKind.STATEMENT) &&
|
|
84
|
+
((node as AbstractStatement).statementKind === StatementKind.COMPOUND)
|
|
85
|
+
) {
|
|
86
|
+
leadingTriviaDoc = removeLeadingBlanklines(leadingTriviaDoc);
|
|
87
|
+
}
|
|
88
|
+
doc.push(leadingTriviaDoc);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
switch (nodeKind) {
|
|
92
|
+
case NodeKind.AGGREGATE_OUTPUT_VALUE:
|
|
93
|
+
doc.push(printAggregateOutputValue(
|
|
94
|
+
path as AstPath<AggregateOutputValue>,
|
|
95
|
+
print,
|
|
96
|
+
));
|
|
97
|
+
break;
|
|
98
|
+
case NodeKind.ALIGNED_MODIFIER:
|
|
99
|
+
doc.push(printAlignedModifier(path as AstPath<AlignedModifier>, print));
|
|
100
|
+
break;
|
|
101
|
+
case NodeKind.ARRAY_DIMENSION:
|
|
102
|
+
doc.push(printAbstractArrayDimension(
|
|
103
|
+
path as AstPath<AbstractArrayDimension>,
|
|
104
|
+
print,
|
|
105
|
+
));
|
|
106
|
+
break;
|
|
107
|
+
case NodeKind.ARRAY_ELEMENT_ACCESS:
|
|
108
|
+
doc.push(printArrayElementAccess(
|
|
109
|
+
path as AstPath<ArrayElementAccess>,
|
|
110
|
+
print,
|
|
111
|
+
));
|
|
112
|
+
break;
|
|
113
|
+
case NodeKind.BIT_MODIFIER:
|
|
114
|
+
doc.push(printBitModifier(path as AstPath<BitModifier>, print));
|
|
115
|
+
break;
|
|
116
|
+
case NodeKind.CASE_CLAUSE:
|
|
117
|
+
doc.push(printCaseClause(path as AstPath<CaseClause>, print));
|
|
118
|
+
break;
|
|
119
|
+
case NodeKind.CLASS_ID:
|
|
120
|
+
doc.push(printAbstractClassId(path as AstPath<AbstractClassId>, print));
|
|
121
|
+
break;
|
|
122
|
+
case NodeKind.CLASS_MEMBER_ACCESS:
|
|
123
|
+
doc.push(
|
|
124
|
+
printClassMemberAccess(path as AstPath<ClassMemberAccess>, print),
|
|
125
|
+
);
|
|
126
|
+
break;
|
|
127
|
+
case NodeKind.DEFAULT_CLAUSE:
|
|
128
|
+
doc.push(printDefaultClause(
|
|
129
|
+
path as AstPath<DefaultClause>,
|
|
130
|
+
print,
|
|
131
|
+
));
|
|
132
|
+
break;
|
|
133
|
+
case NodeKind.ELEMENTARY_TYPE:
|
|
134
|
+
doc.push(printElementaryType(path as AstPath<ElementaryType>, print));
|
|
135
|
+
break;
|
|
136
|
+
case NodeKind.ELEMENTARY_TYPE_OUTPUT_VALUE:
|
|
137
|
+
doc.push(printElementaryTypeOutputValue(
|
|
138
|
+
path as AstPath<ElementaryTypeOutputValue>,
|
|
139
|
+
print,
|
|
140
|
+
));
|
|
141
|
+
break;
|
|
142
|
+
case NodeKind.EXPRESSION:
|
|
143
|
+
doc.push(printAbstractExpression(
|
|
144
|
+
path as AstPath<AbstractExpression>,
|
|
145
|
+
print,
|
|
146
|
+
));
|
|
147
|
+
break;
|
|
148
|
+
case NodeKind.EXPANDABLE_MODIFIER:
|
|
149
|
+
doc.push(printExpandableModifier(
|
|
150
|
+
path as AstPath<ExpandableModifier>,
|
|
151
|
+
print,
|
|
152
|
+
));
|
|
153
|
+
break;
|
|
154
|
+
case NodeKind.EXTENDS_MODIFIER:
|
|
155
|
+
doc.push(printExtendsModifier(path as AstPath<ExtendsModifier>, print));
|
|
156
|
+
break;
|
|
157
|
+
case NodeKind.IDENTIFIER:
|
|
158
|
+
doc.push(printIdentifier(path as AstPath<Identifier>, print));
|
|
159
|
+
break;
|
|
160
|
+
case NodeKind.LENGTH_ATTRIBUTE:
|
|
161
|
+
doc.push(printLengthAttribute(path as AstPath<LengthAttribute>, print));
|
|
162
|
+
break;
|
|
163
|
+
case NodeKind.MAP_ENTRY:
|
|
164
|
+
doc.push(printMapEntry(path as AstPath<MapEntry>, print));
|
|
165
|
+
break;
|
|
166
|
+
case NodeKind.NUMBER_LITERAL:
|
|
167
|
+
doc.push(printNumberLiteral(path as AstPath<NumberLiteral>, print));
|
|
168
|
+
break;
|
|
169
|
+
case NodeKind.PARAMETER:
|
|
170
|
+
doc.push(printParameter(path as AstPath<Parameter>, print));
|
|
171
|
+
break;
|
|
172
|
+
case NodeKind.PARAMETER_LIST:
|
|
173
|
+
doc.push(printParameterList(path as AstPath<ParameterList>, print));
|
|
174
|
+
break;
|
|
175
|
+
case NodeKind.PARAMETER_VALUE_LIST:
|
|
176
|
+
doc.push(printParameterValueList(
|
|
177
|
+
path as AstPath<ParameterValueList>,
|
|
178
|
+
print,
|
|
179
|
+
));
|
|
180
|
+
break;
|
|
181
|
+
case NodeKind.SPECIFICATION:
|
|
182
|
+
doc.push(printSpecification(path as AstPath<Specification>, print));
|
|
183
|
+
break;
|
|
184
|
+
case NodeKind.STATEMENT:
|
|
185
|
+
doc.push(
|
|
186
|
+
printAbstractStatement(path as AstPath<AbstractStatement>, print),
|
|
187
|
+
);
|
|
188
|
+
break;
|
|
189
|
+
case NodeKind.STRING_LITERAL:
|
|
190
|
+
doc.push(printStringLiteral(path as AstPath<StringLiteral>, print));
|
|
191
|
+
break;
|
|
192
|
+
case NodeKind.TOKEN:
|
|
193
|
+
doc.push(printToken(path as AstPath<Token>));
|
|
194
|
+
break;
|
|
195
|
+
case NodeKind.UNEXPECTED_ERROR:
|
|
196
|
+
doc.push(printUnexpectedError(path as AstPath<UnexpectedError>, print));
|
|
197
|
+
break;
|
|
198
|
+
default: {
|
|
199
|
+
const exhaustiveCheck: never = nodeKind;
|
|
200
|
+
throw new InternalScannerError(
|
|
201
|
+
"Unreachable code reached, nodeKind == " + exhaustiveCheck,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const trailingTriviaDoc = getTrailingTriviaDoc(node);
|
|
207
|
+
if (trailingTriviaDoc) {
|
|
208
|
+
// prevent extra lines at end of specification
|
|
209
|
+
if (
|
|
210
|
+
(nodeKind === NodeKind.SPECIFICATION) && endsWithHardline(doc) &&
|
|
211
|
+
endsWithHardline(trailingTriviaDoc)
|
|
212
|
+
) {
|
|
213
|
+
doc = removeTrailingHardline(doc);
|
|
214
|
+
}
|
|
215
|
+
doc = addTrailingTriviaDoc(doc, trailingTriviaDoc);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// trim unneeded arrays
|
|
219
|
+
while (Array.isArray(doc) && (doc.length === 1)) {
|
|
220
|
+
doc = doc[0];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return doc;
|
|
224
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { AstPath, type Doc, doc } from "prettier";
|
|
2
|
+
import { addIndentedStatements } from "./util/print-utils.ts";
|
|
3
|
+
import { printArrayDefinition } from "./print-array-definition.ts";
|
|
4
|
+
import { printDoStatement } from "./print-do-statement.ts";
|
|
5
|
+
import { printForStatement } from "./print-for-statement.ts";
|
|
6
|
+
import { printWhileStatement } from "./print-while-statement.ts";
|
|
7
|
+
import { printIfStatement } from "./print-if-statement.ts";
|
|
8
|
+
import { printSwitchStatement } from "./print-switch-statement.ts";
|
|
9
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
10
|
+
import type { AbstractStatement } from "../ast/node/abstract-statement.ts";
|
|
11
|
+
import type { ArrayDefinition } from "../ast/node/array-definition.ts";
|
|
12
|
+
import type { ClassDefinition } from "../ast/node/class-definition.ts";
|
|
13
|
+
import type { CompoundStatement } from "../ast/node/compound-statement.ts";
|
|
14
|
+
import type { ComputedArrayDefinition } from "../ast/node/computed-array-definition.ts";
|
|
15
|
+
import type { ComputedElementaryTypeDefinition } from "../ast/node/computed-elementary-type-definition.ts";
|
|
16
|
+
import type { ElementaryTypeDefinition } from "../ast/node/elementary-type-definition.ts";
|
|
17
|
+
import { StatementKind } from "../ast/node/enum/statement-kind.ts";
|
|
18
|
+
import type { MapDeclaration } from "../ast/node/map-declaration.ts";
|
|
19
|
+
import type { MapDefinition } from "../ast/node/map-definition.ts";
|
|
20
|
+
import type { StringDefinition } from "../ast/node/string-definition.ts";
|
|
21
|
+
import type { ExpressionStatement } from "../ast/node/expression-statement.ts";
|
|
22
|
+
import type { SwitchStatement } from "../ast/node/switch-statement.ts";
|
|
23
|
+
import type { IfStatement } from "../ast/node/if-statement.ts";
|
|
24
|
+
import type { WhileStatement } from "../ast/node/while-statement.ts";
|
|
25
|
+
import type { ForStatement } from "../ast/node/for-statement.ts";
|
|
26
|
+
import type { DoStatement } from "../ast/node/do-statement.ts";
|
|
27
|
+
import type { ClassDeclaration } from "../ast/node/class-declaration.ts";
|
|
28
|
+
import { printClassDeclaration } from "./print-class-declaration.ts";
|
|
29
|
+
import { printClassDefinition } from "./print-class-definition.ts";
|
|
30
|
+
import { printComputedArrayDefinition } from "./print-computed-array-definition.ts";
|
|
31
|
+
import { printMapDeclaration } from "./print-map-declaration.ts";
|
|
32
|
+
import { printStringDefinition } from "./print-string-definition.ts";
|
|
33
|
+
import { printMapDefinition } from "./print-map-definition.ts";
|
|
34
|
+
import { printComputedElementaryTypeDefinition } from "./print-computed-elementary-type-definition.ts";
|
|
35
|
+
import { printElementaryTypeDefinition } from "./print-elementary-type-definition.ts";
|
|
36
|
+
import { InternalScannerError } from "../scanner-error.ts";
|
|
37
|
+
|
|
38
|
+
const { fill } = doc.builders;
|
|
39
|
+
|
|
40
|
+
function printCompoundStatement(
|
|
41
|
+
path: AstPath<CompoundStatement>,
|
|
42
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
43
|
+
): Doc {
|
|
44
|
+
let doc: Doc = [];
|
|
45
|
+
|
|
46
|
+
const statementsDoc = path.map(print, "statements");
|
|
47
|
+
doc = addIndentedStatements(
|
|
48
|
+
doc,
|
|
49
|
+
statementsDoc,
|
|
50
|
+
path.call(print, "openBracePunctuator"),
|
|
51
|
+
path.call(print, "closeBracePunctuator"),
|
|
52
|
+
);
|
|
53
|
+
return doc;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function printExpressionStatement(
|
|
57
|
+
path: AstPath<ExpressionStatement>,
|
|
58
|
+
print: (_path: AstPath<AbstractNode>) => Doc,
|
|
59
|
+
): Doc {
|
|
60
|
+
return fill([
|
|
61
|
+
path.call(print, "expression"),
|
|
62
|
+
path.call(print, "semicolonPunctuator"),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function printAbstractStatement(
|
|
67
|
+
path: AstPath<AbstractStatement>,
|
|
68
|
+
print: (_path: AstPath<AbstractNode>) => Doc,
|
|
69
|
+
): Doc {
|
|
70
|
+
const abstractStatement = path.node;
|
|
71
|
+
const statementKind = abstractStatement.statementKind;
|
|
72
|
+
switch (statementKind) {
|
|
73
|
+
case StatementKind.ARRAY_DEFINITION:
|
|
74
|
+
return printArrayDefinition(path as AstPath<ArrayDefinition>, print);
|
|
75
|
+
case StatementKind.COMPUTED_ARRAY_DEFINITION:
|
|
76
|
+
return printComputedArrayDefinition(
|
|
77
|
+
path as AstPath<ComputedArrayDefinition>,
|
|
78
|
+
print,
|
|
79
|
+
);
|
|
80
|
+
case StatementKind.COMPUTED_ELEMENTARY_TYPE_DEFINITION:
|
|
81
|
+
return printComputedElementaryTypeDefinition(
|
|
82
|
+
path as AstPath<ComputedElementaryTypeDefinition>,
|
|
83
|
+
print,
|
|
84
|
+
);
|
|
85
|
+
case StatementKind.CLASS_DECLARATION:
|
|
86
|
+
return printClassDeclaration(path as AstPath<ClassDeclaration>, print);
|
|
87
|
+
case StatementKind.CLASS_DEFINITION:
|
|
88
|
+
return printClassDefinition(path as AstPath<ClassDefinition>, print);
|
|
89
|
+
case StatementKind.COMPOUND:
|
|
90
|
+
return printCompoundStatement(path as AstPath<CompoundStatement>, print);
|
|
91
|
+
case StatementKind.DO:
|
|
92
|
+
return printDoStatement(path as AstPath<DoStatement>, print);
|
|
93
|
+
case StatementKind.ELEMENTARY_TYPE_DEFINITION:
|
|
94
|
+
return printElementaryTypeDefinition(
|
|
95
|
+
path as AstPath<ElementaryTypeDefinition>,
|
|
96
|
+
print,
|
|
97
|
+
);
|
|
98
|
+
case StatementKind.EXPRESSION:
|
|
99
|
+
return printExpressionStatement(
|
|
100
|
+
path as AstPath<ExpressionStatement>,
|
|
101
|
+
print,
|
|
102
|
+
);
|
|
103
|
+
case StatementKind.FOR:
|
|
104
|
+
return printForStatement(path as AstPath<ForStatement>, print);
|
|
105
|
+
case StatementKind.IF:
|
|
106
|
+
return printIfStatement(path as AstPath<IfStatement>, print);
|
|
107
|
+
case StatementKind.MAP_DECLARATION:
|
|
108
|
+
return printMapDeclaration(path as AstPath<MapDeclaration>, print);
|
|
109
|
+
case StatementKind.MAP_DEFINITION:
|
|
110
|
+
return printMapDefinition(path as AstPath<MapDefinition>, print);
|
|
111
|
+
case StatementKind.STRING_DEFINITION:
|
|
112
|
+
return printStringDefinition(path as AstPath<StringDefinition>, print);
|
|
113
|
+
case StatementKind.SWITCH:
|
|
114
|
+
return printSwitchStatement(path as AstPath<SwitchStatement>, print);
|
|
115
|
+
case StatementKind.WHILE:
|
|
116
|
+
return printWhileStatement(path as AstPath<WhileStatement>, print);
|
|
117
|
+
default: {
|
|
118
|
+
const exhaustiveCheck: never = statementKind;
|
|
119
|
+
throw new InternalScannerError(
|
|
120
|
+
"Unreachable code reached, statementKind == " + exhaustiveCheck,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AstPath, Doc, doc } from "prettier";
|
|
2
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
3
|
+
import type { AggregateOutputValue } from "../ast/node/aggregate-output-value.ts";
|
|
4
|
+
import {
|
|
5
|
+
addNonBreakingWhitespace,
|
|
6
|
+
interleaveCommaSeparatorDocs,
|
|
7
|
+
} from "./util/print-utils.ts";
|
|
8
|
+
|
|
9
|
+
export function printAggregateOutputValue(
|
|
10
|
+
path: AstPath<AggregateOutputValue>,
|
|
11
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
12
|
+
): doc.builders.Doc {
|
|
13
|
+
const doc: Doc = [];
|
|
14
|
+
|
|
15
|
+
doc.push(
|
|
16
|
+
path.call(print, "openBracePunctuator"),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
addNonBreakingWhitespace(doc);
|
|
20
|
+
|
|
21
|
+
const outputValuesDoc = path.map(print, "outputValues");
|
|
22
|
+
|
|
23
|
+
doc.push(
|
|
24
|
+
interleaveCommaSeparatorDocs(
|
|
25
|
+
outputValuesDoc,
|
|
26
|
+
path.map(print, "commaPunctuators"),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
addNonBreakingWhitespace(doc);
|
|
31
|
+
|
|
32
|
+
doc.push(path.call(print, "closeBracePunctuator"));
|
|
33
|
+
|
|
34
|
+
return doc;
|
|
35
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AlignedModifier } from "../ast/node/aligned-modifier.ts";
|
|
3
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
4
|
+
|
|
5
|
+
export function printAlignedModifier(
|
|
6
|
+
path: AstPath<AlignedModifier>,
|
|
7
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
8
|
+
): Doc {
|
|
9
|
+
const alignedModifier = path.node;
|
|
10
|
+
|
|
11
|
+
const doc: Doc = [];
|
|
12
|
+
|
|
13
|
+
const d = path.call(print, "alignedKeyword");
|
|
14
|
+
doc.push(d);
|
|
15
|
+
|
|
16
|
+
if (alignedModifier.openParenthesisPunctuator) {
|
|
17
|
+
doc.push(
|
|
18
|
+
path.call(
|
|
19
|
+
print,
|
|
20
|
+
"openParenthesisPunctuator" as keyof AlignedModifier[
|
|
21
|
+
"openParenthesisPunctuator"
|
|
22
|
+
],
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (alignedModifier.bitCountModifierToken) {
|
|
28
|
+
doc.push(
|
|
29
|
+
path.call(
|
|
30
|
+
print,
|
|
31
|
+
"bitCountModifierToken" as keyof AlignedModifier[
|
|
32
|
+
"bitCountModifierToken"
|
|
33
|
+
],
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (alignedModifier.closeParenthesisPunctuator) {
|
|
39
|
+
doc.push(
|
|
40
|
+
path.call(
|
|
41
|
+
print,
|
|
42
|
+
"closeParenthesisPunctuator" as keyof AlignedModifier[
|
|
43
|
+
"closeParenthesisPunctuator"
|
|
44
|
+
],
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return doc;
|
|
50
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AstPath, type Doc, doc } from "prettier";
|
|
2
|
+
import {
|
|
3
|
+
addBreakingWhitespace,
|
|
4
|
+
addNonBreakingWhitespace,
|
|
5
|
+
} from "./util/print-utils.ts";
|
|
6
|
+
import type { ArrayDefinition } from "../ast/node/array-definition.ts";
|
|
7
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
8
|
+
|
|
9
|
+
const { fill } = doc.builders;
|
|
10
|
+
|
|
11
|
+
export function printArrayDefinition(
|
|
12
|
+
path: AstPath<ArrayDefinition>,
|
|
13
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
14
|
+
): Doc {
|
|
15
|
+
const arrayDefinition = path.node;
|
|
16
|
+
let doc: Doc = [];
|
|
17
|
+
|
|
18
|
+
if (arrayDefinition.reservedKeyword) {
|
|
19
|
+
doc.push(
|
|
20
|
+
path.call(
|
|
21
|
+
print,
|
|
22
|
+
"reservedKeyword" as keyof ArrayDefinition["reservedKeyword"],
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
addNonBreakingWhitespace(doc);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (arrayDefinition.legacyKeyword) {
|
|
29
|
+
doc.push(
|
|
30
|
+
path.call(
|
|
31
|
+
print,
|
|
32
|
+
"legacyKeyword" as keyof ArrayDefinition["legacyKeyword"],
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
addNonBreakingWhitespace(doc);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (arrayDefinition.alignedModifier !== undefined) {
|
|
39
|
+
doc.push(
|
|
40
|
+
path.call(
|
|
41
|
+
print,
|
|
42
|
+
"alignedModifier" as keyof ArrayDefinition["alignedModifier"],
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
addNonBreakingWhitespace(doc);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (arrayDefinition.elementaryType !== undefined) {
|
|
49
|
+
const subDoc: Doc = [
|
|
50
|
+
path.call(
|
|
51
|
+
print,
|
|
52
|
+
"elementaryType" as keyof ArrayDefinition["elementaryType"],
|
|
53
|
+
),
|
|
54
|
+
path.call(
|
|
55
|
+
print,
|
|
56
|
+
"lengthAttribute" as keyof ArrayDefinition["lengthAttribute"],
|
|
57
|
+
),
|
|
58
|
+
];
|
|
59
|
+
doc.push(subDoc);
|
|
60
|
+
} else {
|
|
61
|
+
doc.push(
|
|
62
|
+
path.call(
|
|
63
|
+
print,
|
|
64
|
+
"classIdentifier" as keyof ArrayDefinition["classIdentifier"],
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
doc = addBreakingWhitespace(doc);
|
|
70
|
+
|
|
71
|
+
const identifierClause = [
|
|
72
|
+
path.call(print, "identifier"),
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
if (arrayDefinition.implicitArrayDimension) {
|
|
76
|
+
identifierClause.push(
|
|
77
|
+
path.call(
|
|
78
|
+
print,
|
|
79
|
+
"implicitArrayDimension" as keyof ArrayDefinition[
|
|
80
|
+
"implicitArrayDimension"
|
|
81
|
+
],
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (arrayDefinition.dimensions) {
|
|
87
|
+
identifierClause.push(...path.map(print, "dimensions"));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
identifierClause.push(path.call(print, "semicolonPunctuator"));
|
|
91
|
+
|
|
92
|
+
doc.push(identifierClause);
|
|
93
|
+
|
|
94
|
+
return fill(doc);
|
|
95
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
3
|
+
import type { ArrayElementAccess } from "../ast/node/array-element-access.ts";
|
|
4
|
+
|
|
5
|
+
export function printArrayElementAccess(
|
|
6
|
+
path: AstPath<ArrayElementAccess>,
|
|
7
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
8
|
+
): Doc {
|
|
9
|
+
return [
|
|
10
|
+
path.call(print, "openBracketPunctuator"),
|
|
11
|
+
path.call(print, "index"),
|
|
12
|
+
path.call(print, "closeBracketPunctuator"),
|
|
13
|
+
];
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
3
|
+
import type { BitModifier } from "../ast/node/bit-modifier.ts";
|
|
4
|
+
import {
|
|
5
|
+
addBreakingWhitespace,
|
|
6
|
+
addNonBreakingWhitespace,
|
|
7
|
+
} from "./util/print-utils.ts";
|
|
8
|
+
|
|
9
|
+
export function printBitModifier(
|
|
10
|
+
path: AstPath<BitModifier>,
|
|
11
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
12
|
+
): Doc {
|
|
13
|
+
const bitModifier = path.node;
|
|
14
|
+
let doc: Doc = [];
|
|
15
|
+
|
|
16
|
+
doc.push(path.call(print, "colonPunctuator"));
|
|
17
|
+
addNonBreakingWhitespace(doc);
|
|
18
|
+
|
|
19
|
+
const subDoc: Doc = [];
|
|
20
|
+
|
|
21
|
+
subDoc.push(path.call(print, "bitKeyword"));
|
|
22
|
+
subDoc.push(path.call(print, "openParenthesisPunctuator"));
|
|
23
|
+
subDoc.push(path.call(print, "length"));
|
|
24
|
+
subDoc.push(path.call(print, "closeParenthesisPunctuator"));
|
|
25
|
+
doc.push(subDoc);
|
|
26
|
+
addNonBreakingWhitespace(doc);
|
|
27
|
+
|
|
28
|
+
if (bitModifier.identifier !== undefined) {
|
|
29
|
+
doc.push(
|
|
30
|
+
path.call(
|
|
31
|
+
print,
|
|
32
|
+
"identifier" as keyof BitModifier["identifier"],
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
addNonBreakingWhitespace(doc);
|
|
36
|
+
doc.push(
|
|
37
|
+
path.call(
|
|
38
|
+
print,
|
|
39
|
+
"assignmentOperator" as keyof BitModifier["assignmentOperator"],
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
doc = addBreakingWhitespace(doc);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
doc.push(path.call(print, "classId"));
|
|
46
|
+
|
|
47
|
+
return doc;
|
|
48
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { AstPath, Doc } from "prettier";
|
|
2
|
+
import type { AbstractNode } from "../ast/node/abstract-node.ts";
|
|
3
|
+
import {
|
|
4
|
+
addIndentedStatements,
|
|
5
|
+
addNonBreakingWhitespace,
|
|
6
|
+
} from "./util/print-utils.ts";
|
|
7
|
+
import type { CaseClause } from "../ast/node/case-clause.ts";
|
|
8
|
+
|
|
9
|
+
export function printCaseClause(
|
|
10
|
+
path: AstPath<CaseClause>,
|
|
11
|
+
print: (path: AstPath<AbstractNode>) => Doc,
|
|
12
|
+
): Doc {
|
|
13
|
+
const caseClause = path.node;
|
|
14
|
+
let doc: Doc = [];
|
|
15
|
+
|
|
16
|
+
doc.push(path.call(print, "caseKeyword"));
|
|
17
|
+
addNonBreakingWhitespace(doc);
|
|
18
|
+
|
|
19
|
+
doc.push([
|
|
20
|
+
path.call(print, "value"),
|
|
21
|
+
path.call(print, "colonPunctuator"),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const statementsDocs: Doc[] = [];
|
|
25
|
+
|
|
26
|
+
if (caseClause.statements.length > 0) {
|
|
27
|
+
statementsDocs.push(path.map(print, "statements"));
|
|
28
|
+
}
|
|
29
|
+
if (caseClause.breakKeyword !== undefined) {
|
|
30
|
+
statementsDocs.push([[
|
|
31
|
+
path.call(print, "breakKeyword" as keyof CaseClause["breakKeyword"]),
|
|
32
|
+
path.call(
|
|
33
|
+
print,
|
|
34
|
+
"semicolonPunctuator" as keyof CaseClause["semicolonPunctuator"],
|
|
35
|
+
),
|
|
36
|
+
]]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (caseClause.openBracePunctuator !== undefined) {
|
|
40
|
+
doc.push(" ");
|
|
41
|
+
doc = addIndentedStatements(
|
|
42
|
+
doc,
|
|
43
|
+
statementsDocs,
|
|
44
|
+
path.call(
|
|
45
|
+
print,
|
|
46
|
+
"openBracePunctuator" as keyof CaseClause["openBracePunctuator"],
|
|
47
|
+
),
|
|
48
|
+
path.call(
|
|
49
|
+
print,
|
|
50
|
+
"closeBracePunctuator" as keyof CaseClause["closeBracePunctuator"],
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
doc = addIndentedStatements(doc, statementsDocs);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return doc;
|
|
58
|
+
}
|