semantifold 0.1.1 → 0.3.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/README.md +42 -10
- package/build/index.d.ts +32 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +99 -4
- package/build/src/acceptance.d.ts +32 -0
- package/build/src/acceptance.d.ts.map +1 -0
- package/build/src/acceptance.js +358 -0
- package/build/src/array.d.ts +7 -0
- package/build/src/array.d.ts.map +1 -0
- package/build/src/array.js +18 -0
- package/build/src/artifact-path.d.ts +13 -0
- package/build/src/artifact-path.d.ts.map +1 -0
- package/build/src/artifact-path.js +30 -0
- package/build/src/artifacts.d.ts +7 -0
- package/build/src/artifacts.d.ts.map +1 -0
- package/build/src/artifacts.js +389 -0
- package/build/src/backends/c-runtime.d.ts +3 -0
- package/build/src/backends/c-runtime.d.ts.map +1 -0
- package/build/src/backends/c-runtime.js +151 -0
- package/build/src/backends/c-validation.d.ts +12 -0
- package/build/src/backends/c-validation.d.ts.map +1 -0
- package/build/src/backends/c-validation.js +85 -0
- package/build/src/backends/c.d.ts +31 -0
- package/build/src/backends/c.d.ts.map +1 -0
- package/build/src/backends/c.js +308 -0
- package/build/src/backends/cpp-runtime.d.ts +3 -0
- package/build/src/backends/cpp-runtime.d.ts.map +1 -0
- package/build/src/backends/cpp-runtime.js +99 -0
- package/build/src/backends/cpp-validation.d.ts +9 -0
- package/build/src/backends/cpp-validation.d.ts.map +1 -0
- package/build/src/backends/cpp-validation.js +74 -0
- package/build/src/backends/cpp.d.ts +16 -0
- package/build/src/backends/cpp.d.ts.map +1 -0
- package/build/src/backends/cpp.js +285 -0
- package/build/src/backends/csharp.d.ts +20 -0
- package/build/src/backends/csharp.d.ts.map +1 -0
- package/build/src/backends/csharp.js +259 -0
- package/build/src/backends/go.d.ts +20 -0
- package/build/src/backends/go.d.ts.map +1 -0
- package/build/src/backends/go.js +374 -0
- package/build/src/backends/identifiers.d.ts +12 -0
- package/build/src/backends/identifiers.d.ts.map +1 -1
- package/build/src/backends/identifiers.js +79 -2
- package/build/src/backends/index.d.ts.map +1 -1
- package/build/src/backends/index.js +27 -37
- package/build/src/backends/native-validation.d.ts +9 -0
- package/build/src/backends/native-validation.d.ts.map +1 -0
- package/build/src/backends/native-validation.js +59 -0
- package/build/src/backends/ordered-expressions.d.ts +74 -0
- package/build/src/backends/ordered-expressions.d.ts.map +1 -0
- package/build/src/backends/ordered-expressions.js +159 -0
- package/build/src/backends/python.d.ts +8 -0
- package/build/src/backends/python.d.ts.map +1 -0
- package/build/src/backends/python.js +162 -0
- package/build/src/backends/scalars.d.ts.map +1 -1
- package/build/src/backends/scalars.js +8 -2
- package/build/src/backends/shared.d.ts.map +1 -1
- package/build/src/backends/shared.js +67 -19
- package/build/src/binary-mapping.d.ts +32 -0
- package/build/src/binary-mapping.d.ts.map +1 -0
- package/build/src/binary-mapping.js +285 -0
- package/build/src/diagnostic.d.ts +36 -4
- package/build/src/diagnostic.d.ts.map +1 -1
- package/build/src/diagnostic.js +42 -3
- package/build/src/frontends/c-parser.d.ts +20 -0
- package/build/src/frontends/c-parser.d.ts.map +1 -0
- package/build/src/frontends/c-parser.js +14 -0
- package/build/src/frontends/c.d.ts +220 -0
- package/build/src/frontends/c.d.ts.map +1 -0
- package/build/src/frontends/c.js +750 -0
- package/build/src/frontends/cpp-parser.d.ts +11 -0
- package/build/src/frontends/cpp-parser.d.ts.map +1 -0
- package/build/src/frontends/cpp-parser.js +15 -0
- package/build/src/frontends/cpp.d.ts +227 -0
- package/build/src/frontends/cpp.d.ts.map +1 -0
- package/build/src/frontends/cpp.js +784 -0
- package/build/src/frontends/csharp.d.ts +14 -0
- package/build/src/frontends/csharp.d.ts.map +1 -0
- package/build/src/frontends/csharp.js +708 -0
- package/build/src/frontends/go.d.ts +15 -0
- package/build/src/frontends/go.d.ts.map +1 -0
- package/build/src/frontends/go.js +712 -0
- package/build/src/frontends/index.d.ts.map +1 -1
- package/build/src/frontends/index.js +5 -23
- package/build/src/frontends/python.d.ts +14 -0
- package/build/src/frontends/python.d.ts.map +1 -0
- package/build/src/frontends/python.js +615 -0
- package/build/src/frontends/scalars.d.ts.map +1 -1
- package/build/src/frontends/scalars.js +21 -1
- package/build/src/language-registry.d.ts +113 -0
- package/build/src/language-registry.d.ts.map +1 -0
- package/build/src/language-registry.js +421 -0
- package/build/src/mapping.js +3 -2
- package/build/src/semantic/location.d.ts +7 -0
- package/build/src/semantic/location.d.ts.map +1 -1
- package/build/src/semantic/location.js +10 -1
- package/build/src/semantic/provenance.js +3 -3
- package/build/src/semantic/types.d.ts +399 -2
- package/build/src/semantic/types.d.ts.map +1 -1
- package/build/src/semantic/types.js +110 -2
- package/build/src/subprocess.d.ts +38 -0
- package/build/src/subprocess.d.ts.map +1 -0
- package/build/src/subprocess.js +233 -0
- package/build/src/timeout.d.ts +8 -0
- package/build/src/timeout.d.ts.map +1 -0
- package/build/src/timeout.js +11 -0
- package/build/src/toolchains.d.ts +107 -0
- package/build/src/toolchains.d.ts.map +1 -0
- package/build/src/toolchains.js +417 -0
- package/docs/architecture.md +23 -5
- package/docs/c.md +60 -0
- package/docs/cpp.md +61 -0
- package/docs/goals.md +4 -2
- package/docs/language-support.md +46 -6
- package/docs/parser-qualification.md +219 -0
- package/docs/plans/2026-09-05-standard-library-portability.md +46 -0
- package/docs/source-maps.md +38 -5
- package/docs/standard-library-portability.md +190 -0
- package/docs/testing.md +131 -3
- package/index.js +109 -4
- package/node_modules/node-addon-api/LICENSE.md +9 -0
- package/node_modules/node-addon-api/README.md +95 -0
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +14 -0
- package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/node-addon-api/napi-inl.h +7250 -0
- package/node_modules/node-addon-api/napi.h +3463 -0
- package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +481 -0
- package/node_modules/node-addon-api/tools/README.md +73 -0
- package/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/node_modules/node-gyp-build/LICENSE +21 -0
- package/node_modules/node-gyp-build/README.md +58 -0
- package/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/node_modules/node-gyp-build/bin.js +84 -0
- package/node_modules/node-gyp-build/build-test.js +19 -0
- package/node_modules/node-gyp-build/index.js +6 -0
- package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/node_modules/node-gyp-build/optional.js +7 -0
- package/node_modules/node-gyp-build/package.json +43 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/LICENSE +15 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/README.md +7 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/README.md +90 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/binding.gyp +79 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/index.js +895 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/package.json +62 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.cc +106 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.cc +1056 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.cc +298 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.cc +383 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.h +39 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.cc +307 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/tree-sitter.d.ts +211 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +221 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +299 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +419 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +14 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +774 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2151 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +230 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4134 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1060 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +382 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +165 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +714 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +50 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +23 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1294 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1823 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/README.md +18 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/binding.gyp +29 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding.cc +20 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding_test.js +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.d.ts +28 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.js +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/grammar.js +1470 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/package.json +60 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/highlights.scm +81 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/tags.scm +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/grammar.json +9735 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/node-types.json +4614 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/parser.c +119615 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/alloc.h +54 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter-c.wasm +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter.json +43 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/README.md +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/binding.gyp +30 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding.cc +20 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding_test.js +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.d.ts +28 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.js +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/grammar.js +1436 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/package.json +61 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/highlights.scm +70 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/injections.scm +3 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/tags.scm +15 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/grammar.json +17084 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/node-types.json +7997 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/parser.c +530368 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/scanner.c +148 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/alloc.h +54 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter-cpp.wasm +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter.json +55 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/package.json +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/src/c.js +152 -0
- package/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/tree-sitter/README.md +128 -0
- package/node_modules/tree-sitter/binding.gyp +88 -0
- package/node_modules/tree-sitter/index.js +950 -0
- package/node_modules/tree-sitter/package.json +76 -0
- package/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/tree-sitter/src/language.cc +105 -0
- package/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/tree-sitter/src/node.cc +1088 -0
- package/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/tree-sitter/src/parser.cc +332 -0
- package/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/tree-sitter/src/query.cc +425 -0
- package/node_modules/tree-sitter/src/query.h +40 -0
- package/node_modules/tree-sitter/src/tree.cc +316 -0
- package/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/tree-sitter/tree-sitter.d.ts +1083 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1478 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +523 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +483 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +54 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +875 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2297 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +286 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +241 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4347 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +912 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1034 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +716 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +75 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +137 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1314 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1937 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/package.json +24 -6
- package/src/acceptance.js +380 -0
- package/src/array.js +19 -0
- package/src/artifact-path.js +34 -0
- package/src/artifacts.js +420 -0
- package/src/backends/c-runtime.js +151 -0
- package/src/backends/c-validation.js +83 -0
- package/src/backends/c.js +308 -0
- package/src/backends/cpp-runtime.js +99 -0
- package/src/backends/cpp-validation.js +70 -0
- package/src/backends/cpp.js +285 -0
- package/src/backends/csharp.js +270 -0
- package/src/backends/go.js +383 -0
- package/src/backends/identifiers.js +80 -1
- package/src/backends/index.js +23 -32
- package/src/backends/native-validation.js +64 -0
- package/src/backends/ordered-expressions.js +161 -0
- package/src/backends/python.js +175 -0
- package/src/backends/scalars.js +8 -1
- package/src/backends/shared.js +64 -17
- package/src/binary-mapping.js +305 -0
- package/src/diagnostic.js +34 -2
- package/src/frontends/c-parser.js +17 -0
- package/src/frontends/c.js +780 -0
- package/src/frontends/cpp-parser.js +18 -0
- package/src/frontends/cpp.js +816 -0
- package/src/frontends/csharp.js +759 -0
- package/src/frontends/go.js +770 -0
- package/src/frontends/index.js +5 -20
- package/src/frontends/python.js +689 -0
- package/src/frontends/scalars.js +20 -0
- package/src/language-registry.js +454 -0
- package/src/mapping.js +2 -1
- package/src/semantic/location.js +10 -0
- package/src/semantic/provenance.js +2 -2
- package/src/semantic/types.js +124 -1
- package/src/subprocess.js +232 -0
- package/src/timeout.js +12 -0
- package/src/toolchains.js +448 -0
- package/tsconfig.json +1 -0
package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/grammar.js
ADDED
|
@@ -0,0 +1,1436 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file C++ grammar for tree-sitter
|
|
3
|
+
* @author Max Brunsfeld <maxbrunsfeld@gmail.com>
|
|
4
|
+
* @author Amaan Qureshi <amaanq12@gmail.com>
|
|
5
|
+
* @author John Drouhard <john@drouhard.dev>
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
10
|
+
// @ts-check
|
|
11
|
+
|
|
12
|
+
const C = require('tree-sitter-c/grammar');
|
|
13
|
+
|
|
14
|
+
const PREC = Object.assign(C.PREC, {
|
|
15
|
+
LAMBDA: 18,
|
|
16
|
+
NEW: C.PREC.CALL + 1,
|
|
17
|
+
STRUCTURED_BINDING: -1,
|
|
18
|
+
THREE_WAY: C.PREC.RELATIONAL + 1,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const FOLD_OPERATORS = [
|
|
22
|
+
'+', '-', '*', '/', '%',
|
|
23
|
+
'^', '&', '|',
|
|
24
|
+
'=', '<', '>',
|
|
25
|
+
'<<', '>>',
|
|
26
|
+
'+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=',
|
|
27
|
+
'>>=', '<<=',
|
|
28
|
+
'==', '!=', '<=', '>=',
|
|
29
|
+
'&&', '||',
|
|
30
|
+
',',
|
|
31
|
+
'.*', '->*',
|
|
32
|
+
'or', 'and', 'bitor', 'xor', 'bitand', 'not_eq',
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const ASSIGNMENT_OPERATORS = [
|
|
36
|
+
'=',
|
|
37
|
+
'*=',
|
|
38
|
+
'/=',
|
|
39
|
+
'%=',
|
|
40
|
+
'+=',
|
|
41
|
+
'-=',
|
|
42
|
+
'<<=',
|
|
43
|
+
'>>=',
|
|
44
|
+
'&=',
|
|
45
|
+
'^=',
|
|
46
|
+
'|=',
|
|
47
|
+
'and_eq',
|
|
48
|
+
'or_eq',
|
|
49
|
+
'xor_eq',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
module.exports = grammar(C, {
|
|
53
|
+
name: 'cpp',
|
|
54
|
+
|
|
55
|
+
externals: $ => [
|
|
56
|
+
$.raw_string_delimiter,
|
|
57
|
+
$.raw_string_content,
|
|
58
|
+
],
|
|
59
|
+
|
|
60
|
+
conflicts: $ => [
|
|
61
|
+
// C
|
|
62
|
+
[$.type_specifier, $._declarator],
|
|
63
|
+
[$.type_specifier, $.expression],
|
|
64
|
+
[$.sized_type_specifier],
|
|
65
|
+
[$.attributed_statement],
|
|
66
|
+
[$._declaration_modifiers, $.attributed_statement],
|
|
67
|
+
[$._top_level_item, $._top_level_statement],
|
|
68
|
+
[$._block_item, $.statement],
|
|
69
|
+
[$.type_qualifier, $.extension_expression],
|
|
70
|
+
|
|
71
|
+
// C++
|
|
72
|
+
[$.template_function, $.template_type],
|
|
73
|
+
[$.template_function, $.template_type, $.expression],
|
|
74
|
+
[$.template_function, $.template_type, $.qualified_identifier],
|
|
75
|
+
[$.template_type, $.qualified_type_identifier],
|
|
76
|
+
[$.qualified_type_identifier, $.qualified_identifier],
|
|
77
|
+
[$.comma_expression, $.initializer_list],
|
|
78
|
+
[$.expression, $._declarator],
|
|
79
|
+
[$.expression, $.structured_binding_declarator],
|
|
80
|
+
[$.expression, $._declarator, $.type_specifier],
|
|
81
|
+
[$.expression, $.identifier_parameter_pack_expansion],
|
|
82
|
+
[$.expression, $._lambda_capture_identifier],
|
|
83
|
+
[$.expression, $._lambda_capture],
|
|
84
|
+
[$.expression, $.structured_binding_declarator, $._lambda_capture_identifier],
|
|
85
|
+
[$.structured_binding_declarator, $._lambda_capture_identifier],
|
|
86
|
+
[$.parameter_list, $.argument_list],
|
|
87
|
+
[$.type_specifier, $.call_expression],
|
|
88
|
+
[$._declaration_specifiers, $._constructor_specifiers],
|
|
89
|
+
[$._binary_fold_operator, $._fold_operator],
|
|
90
|
+
[$._function_declarator_seq],
|
|
91
|
+
[$.type_specifier, $.sized_type_specifier],
|
|
92
|
+
[$.initializer_pair, $.comma_expression],
|
|
93
|
+
[$.expression_statement, $._for_statement_body],
|
|
94
|
+
[$.init_statement, $._for_statement_body],
|
|
95
|
+
[$.field_expression, $.template_method, $.template_type],
|
|
96
|
+
[$.qualified_field_identifier, $.template_method, $.template_type],
|
|
97
|
+
],
|
|
98
|
+
|
|
99
|
+
inline: ($, original) => original.concat([
|
|
100
|
+
$._namespace_identifier,
|
|
101
|
+
]),
|
|
102
|
+
|
|
103
|
+
precedences: $ => [
|
|
104
|
+
[$.argument_list, $.type_qualifier],
|
|
105
|
+
[$._expression_not_binary, $._class_name],
|
|
106
|
+
],
|
|
107
|
+
|
|
108
|
+
rules: {
|
|
109
|
+
_top_level_item: ($, original) => choice(
|
|
110
|
+
...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
|
|
111
|
+
$.namespace_definition,
|
|
112
|
+
$.concept_definition,
|
|
113
|
+
$.namespace_alias_definition,
|
|
114
|
+
$.using_declaration,
|
|
115
|
+
$.alias_declaration,
|
|
116
|
+
$.static_assert_declaration,
|
|
117
|
+
$.template_declaration,
|
|
118
|
+
$.template_instantiation,
|
|
119
|
+
alias($.constructor_or_destructor_definition, $.function_definition),
|
|
120
|
+
alias($.operator_cast_definition, $.function_definition),
|
|
121
|
+
alias($.operator_cast_declaration, $.declaration),
|
|
122
|
+
),
|
|
123
|
+
|
|
124
|
+
_block_item: ($, original) => choice(
|
|
125
|
+
...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
|
|
126
|
+
$.namespace_definition,
|
|
127
|
+
$.concept_definition,
|
|
128
|
+
$.namespace_alias_definition,
|
|
129
|
+
$.using_declaration,
|
|
130
|
+
$.alias_declaration,
|
|
131
|
+
$.static_assert_declaration,
|
|
132
|
+
$.template_declaration,
|
|
133
|
+
$.template_instantiation,
|
|
134
|
+
alias($.constructor_or_destructor_definition, $.function_definition),
|
|
135
|
+
alias($.operator_cast_definition, $.function_definition),
|
|
136
|
+
alias($.operator_cast_declaration, $.declaration),
|
|
137
|
+
),
|
|
138
|
+
|
|
139
|
+
// Types
|
|
140
|
+
|
|
141
|
+
placeholder_type_specifier: $ => prec(1, seq(
|
|
142
|
+
field('constraint', optional($.type_specifier)),
|
|
143
|
+
choice($.auto, alias($.decltype_auto, $.decltype)),
|
|
144
|
+
)),
|
|
145
|
+
|
|
146
|
+
auto: _ => 'auto',
|
|
147
|
+
decltype_auto: $ => seq(
|
|
148
|
+
'decltype',
|
|
149
|
+
'(',
|
|
150
|
+
$.auto,
|
|
151
|
+
')',
|
|
152
|
+
),
|
|
153
|
+
decltype: $ => seq(
|
|
154
|
+
'decltype',
|
|
155
|
+
'(',
|
|
156
|
+
$.expression,
|
|
157
|
+
')',
|
|
158
|
+
),
|
|
159
|
+
|
|
160
|
+
type_specifier: $ => choice(
|
|
161
|
+
$.struct_specifier,
|
|
162
|
+
$.union_specifier,
|
|
163
|
+
$.enum_specifier,
|
|
164
|
+
$.class_specifier,
|
|
165
|
+
$.sized_type_specifier,
|
|
166
|
+
$.primitive_type,
|
|
167
|
+
$.template_type,
|
|
168
|
+
$.dependent_type,
|
|
169
|
+
$.placeholder_type_specifier,
|
|
170
|
+
$.decltype,
|
|
171
|
+
prec.right(choice(
|
|
172
|
+
alias($.qualified_type_identifier, $.qualified_identifier),
|
|
173
|
+
$._type_identifier,
|
|
174
|
+
)),
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
type_qualifier: (_, original) => choice(
|
|
178
|
+
original,
|
|
179
|
+
'mutable',
|
|
180
|
+
'constinit',
|
|
181
|
+
'consteval',
|
|
182
|
+
),
|
|
183
|
+
|
|
184
|
+
type_descriptor: (_, original) => prec.right(original),
|
|
185
|
+
|
|
186
|
+
// When used in a trailing return type, these specifiers can now occur immediately before
|
|
187
|
+
// a compound statement. This introduces a shift/reduce conflict that needs to be resolved
|
|
188
|
+
// with an associativity.
|
|
189
|
+
_class_declaration: $ => seq(
|
|
190
|
+
repeat(choice($.attribute_specifier, $.alignas_qualifier)),
|
|
191
|
+
optional($.ms_declspec_modifier),
|
|
192
|
+
repeat($.attribute_declaration),
|
|
193
|
+
$._class_declaration_item,
|
|
194
|
+
),
|
|
195
|
+
_class_declaration_item: $ => prec.right(seq(
|
|
196
|
+
choice(
|
|
197
|
+
field('name', $._class_name),
|
|
198
|
+
seq(
|
|
199
|
+
optional(field('name', $._class_name)),
|
|
200
|
+
optional($.virtual_specifier),
|
|
201
|
+
optional($.base_class_clause),
|
|
202
|
+
field('body', $.field_declaration_list),
|
|
203
|
+
),
|
|
204
|
+
),
|
|
205
|
+
optional($.attribute_specifier),
|
|
206
|
+
)),
|
|
207
|
+
|
|
208
|
+
class_specifier: $ => seq(
|
|
209
|
+
'class',
|
|
210
|
+
$._class_declaration,
|
|
211
|
+
),
|
|
212
|
+
|
|
213
|
+
union_specifier: $ => seq(
|
|
214
|
+
'union',
|
|
215
|
+
$._class_declaration,
|
|
216
|
+
),
|
|
217
|
+
|
|
218
|
+
struct_specifier: $ => seq(
|
|
219
|
+
'struct',
|
|
220
|
+
$._class_declaration,
|
|
221
|
+
),
|
|
222
|
+
|
|
223
|
+
_class_name: $ => prec.right(choice(
|
|
224
|
+
$._type_identifier,
|
|
225
|
+
$.template_type,
|
|
226
|
+
alias($.qualified_type_identifier, $.qualified_identifier),
|
|
227
|
+
)),
|
|
228
|
+
|
|
229
|
+
function_definition: ($, original) => ({
|
|
230
|
+
...original,
|
|
231
|
+
members: original.members.map(
|
|
232
|
+
(e) => e.name !== 'body' ?
|
|
233
|
+
e :
|
|
234
|
+
field('body', choice(e.content, $.try_statement))),
|
|
235
|
+
}),
|
|
236
|
+
|
|
237
|
+
declaration: $ => seq(
|
|
238
|
+
$._declaration_specifiers,
|
|
239
|
+
commaSep1(field('declarator', choice(
|
|
240
|
+
seq(
|
|
241
|
+
// C uses _declaration_declarator here for some nice macro parsing in function declarators,
|
|
242
|
+
// but this causes a world of pain for C++ so we'll just stick to the normal _declarator here.
|
|
243
|
+
$._declarator,
|
|
244
|
+
optional($.gnu_asm_expression),
|
|
245
|
+
),
|
|
246
|
+
$.init_declarator,
|
|
247
|
+
))),
|
|
248
|
+
';',
|
|
249
|
+
),
|
|
250
|
+
|
|
251
|
+
virtual_specifier: _ => choice(
|
|
252
|
+
'final', // the only legal value here for classes
|
|
253
|
+
'override', // legal for functions in addition to final, plus permutations.
|
|
254
|
+
),
|
|
255
|
+
|
|
256
|
+
_declaration_modifiers: ($, original) => choice(
|
|
257
|
+
original,
|
|
258
|
+
'virtual',
|
|
259
|
+
),
|
|
260
|
+
|
|
261
|
+
explicit_function_specifier: $ => choice(
|
|
262
|
+
'explicit',
|
|
263
|
+
prec(PREC.CALL, seq(
|
|
264
|
+
'explicit',
|
|
265
|
+
'(',
|
|
266
|
+
$.expression,
|
|
267
|
+
')',
|
|
268
|
+
)),
|
|
269
|
+
),
|
|
270
|
+
|
|
271
|
+
base_class_clause: $ => seq(
|
|
272
|
+
':',
|
|
273
|
+
commaSep1(seq(
|
|
274
|
+
repeat($.attribute_declaration),
|
|
275
|
+
optional(choice(
|
|
276
|
+
$.access_specifier,
|
|
277
|
+
seq($.access_specifier, optional('virtual')),
|
|
278
|
+
seq('virtual', optional($.access_specifier)),
|
|
279
|
+
)),
|
|
280
|
+
$._class_name,
|
|
281
|
+
optional('...'),
|
|
282
|
+
)),
|
|
283
|
+
),
|
|
284
|
+
|
|
285
|
+
enum_specifier: $ => prec.right(seq(
|
|
286
|
+
'enum',
|
|
287
|
+
optional(choice('class', 'struct')),
|
|
288
|
+
choice(
|
|
289
|
+
seq(
|
|
290
|
+
field('name', $._class_name),
|
|
291
|
+
optional($._enum_base_clause),
|
|
292
|
+
optional(field('body', $.enumerator_list)),
|
|
293
|
+
),
|
|
294
|
+
field('body', $.enumerator_list),
|
|
295
|
+
),
|
|
296
|
+
optional($.attribute_specifier),
|
|
297
|
+
)),
|
|
298
|
+
|
|
299
|
+
_enum_base_clause: $ => prec.left(seq(
|
|
300
|
+
':',
|
|
301
|
+
field('base', choice(
|
|
302
|
+
alias($.qualified_type_identifier, $.qualified_identifier),
|
|
303
|
+
$._type_identifier,
|
|
304
|
+
$.primitive_type,
|
|
305
|
+
$.sized_type_specifier,
|
|
306
|
+
)),
|
|
307
|
+
)),
|
|
308
|
+
|
|
309
|
+
// The `auto` storage class is removed in C++0x in order to allow for the `auto` type.
|
|
310
|
+
storage_class_specifier: (_, original) => choice(
|
|
311
|
+
...original.members.filter((member) => member.value !== 'auto'),
|
|
312
|
+
'thread_local',
|
|
313
|
+
),
|
|
314
|
+
|
|
315
|
+
dependent_type: $ => prec.dynamic(-1, prec.right(seq(
|
|
316
|
+
'typename',
|
|
317
|
+
$.type_specifier,
|
|
318
|
+
))),
|
|
319
|
+
|
|
320
|
+
// Declarations
|
|
321
|
+
|
|
322
|
+
template_declaration: $ => seq(
|
|
323
|
+
'template',
|
|
324
|
+
field('parameters', $.template_parameter_list),
|
|
325
|
+
optional($.requires_clause),
|
|
326
|
+
choice(
|
|
327
|
+
$._empty_declaration,
|
|
328
|
+
$.alias_declaration,
|
|
329
|
+
$.declaration,
|
|
330
|
+
$.template_declaration,
|
|
331
|
+
$.function_definition,
|
|
332
|
+
$.concept_definition,
|
|
333
|
+
$.friend_declaration,
|
|
334
|
+
alias($.constructor_or_destructor_declaration, $.declaration),
|
|
335
|
+
alias($.constructor_or_destructor_definition, $.function_definition),
|
|
336
|
+
alias($.operator_cast_declaration, $.declaration),
|
|
337
|
+
alias($.operator_cast_definition, $.function_definition),
|
|
338
|
+
),
|
|
339
|
+
),
|
|
340
|
+
|
|
341
|
+
template_instantiation: $ => seq(
|
|
342
|
+
'template',
|
|
343
|
+
optional($._declaration_specifiers),
|
|
344
|
+
field('declarator', $._declarator),
|
|
345
|
+
';',
|
|
346
|
+
),
|
|
347
|
+
|
|
348
|
+
template_parameter_list: $ => seq(
|
|
349
|
+
'<',
|
|
350
|
+
commaSep(choice(
|
|
351
|
+
$.parameter_declaration,
|
|
352
|
+
$.optional_parameter_declaration,
|
|
353
|
+
$.type_parameter_declaration,
|
|
354
|
+
$.variadic_parameter_declaration,
|
|
355
|
+
$.variadic_type_parameter_declaration,
|
|
356
|
+
$.optional_type_parameter_declaration,
|
|
357
|
+
$.template_template_parameter_declaration,
|
|
358
|
+
)),
|
|
359
|
+
alias(token(prec(1, '>')), '>'),
|
|
360
|
+
),
|
|
361
|
+
|
|
362
|
+
type_parameter_declaration: $ => prec(1, seq(
|
|
363
|
+
choice('typename', 'class'),
|
|
364
|
+
optional($._type_identifier),
|
|
365
|
+
)),
|
|
366
|
+
|
|
367
|
+
variadic_type_parameter_declaration: $ => prec(1, seq(
|
|
368
|
+
choice('typename', 'class'),
|
|
369
|
+
'...',
|
|
370
|
+
optional($._type_identifier),
|
|
371
|
+
)),
|
|
372
|
+
|
|
373
|
+
optional_type_parameter_declaration: $ => seq(
|
|
374
|
+
choice('typename', 'class'),
|
|
375
|
+
optional(field('name', $._type_identifier)),
|
|
376
|
+
'=',
|
|
377
|
+
field('default_type', $.type_specifier),
|
|
378
|
+
),
|
|
379
|
+
|
|
380
|
+
template_template_parameter_declaration: $ => seq(
|
|
381
|
+
'template',
|
|
382
|
+
field('parameters', $.template_parameter_list),
|
|
383
|
+
choice(
|
|
384
|
+
$.type_parameter_declaration,
|
|
385
|
+
$.variadic_type_parameter_declaration,
|
|
386
|
+
$.optional_type_parameter_declaration,
|
|
387
|
+
),
|
|
388
|
+
),
|
|
389
|
+
|
|
390
|
+
parameter_list: $ => seq(
|
|
391
|
+
'(',
|
|
392
|
+
commaSep(choice(
|
|
393
|
+
$.parameter_declaration,
|
|
394
|
+
$.optional_parameter_declaration,
|
|
395
|
+
$.variadic_parameter_declaration,
|
|
396
|
+
'...',
|
|
397
|
+
)),
|
|
398
|
+
')',
|
|
399
|
+
),
|
|
400
|
+
|
|
401
|
+
optional_parameter_declaration: $ => seq(
|
|
402
|
+
$._declaration_specifiers,
|
|
403
|
+
field('declarator', optional(choice($._declarator, $.abstract_reference_declarator))),
|
|
404
|
+
'=',
|
|
405
|
+
field('default_value', $.expression),
|
|
406
|
+
),
|
|
407
|
+
|
|
408
|
+
variadic_parameter_declaration: $ => seq(
|
|
409
|
+
$._declaration_specifiers,
|
|
410
|
+
field('declarator', choice(
|
|
411
|
+
$.variadic_declarator,
|
|
412
|
+
alias($.variadic_reference_declarator, $.reference_declarator),
|
|
413
|
+
)),
|
|
414
|
+
),
|
|
415
|
+
|
|
416
|
+
variadic_declarator: $ => seq(
|
|
417
|
+
'...',
|
|
418
|
+
optional($.identifier),
|
|
419
|
+
),
|
|
420
|
+
|
|
421
|
+
variadic_reference_declarator: $ => seq(
|
|
422
|
+
choice('&&', '&'),
|
|
423
|
+
$.variadic_declarator,
|
|
424
|
+
),
|
|
425
|
+
|
|
426
|
+
init_declarator: ($, original) => choice(
|
|
427
|
+
original,
|
|
428
|
+
seq(
|
|
429
|
+
field('declarator', $._declarator),
|
|
430
|
+
field('value', choice(
|
|
431
|
+
$.argument_list,
|
|
432
|
+
$.initializer_list,
|
|
433
|
+
)),
|
|
434
|
+
),
|
|
435
|
+
),
|
|
436
|
+
|
|
437
|
+
operator_cast: $ => prec.right(1, seq(
|
|
438
|
+
'operator',
|
|
439
|
+
$._declaration_specifiers,
|
|
440
|
+
field('declarator', $._abstract_declarator),
|
|
441
|
+
)),
|
|
442
|
+
|
|
443
|
+
// Avoid ambiguity between compound statement and initializer list in a construct like:
|
|
444
|
+
// A b {};
|
|
445
|
+
compound_statement: (_, original) => prec(-1, original),
|
|
446
|
+
|
|
447
|
+
field_initializer_list: $ => seq(
|
|
448
|
+
':',
|
|
449
|
+
commaSep1($.field_initializer),
|
|
450
|
+
),
|
|
451
|
+
|
|
452
|
+
field_initializer: $ => prec(1, seq(
|
|
453
|
+
choice(
|
|
454
|
+
$._field_identifier,
|
|
455
|
+
$.template_method,
|
|
456
|
+
alias($.qualified_field_identifier, $.qualified_identifier),
|
|
457
|
+
),
|
|
458
|
+
choice($.initializer_list, $.argument_list),
|
|
459
|
+
optional('...'),
|
|
460
|
+
)),
|
|
461
|
+
|
|
462
|
+
_field_declaration_list_item: ($, original) => choice(
|
|
463
|
+
original,
|
|
464
|
+
$.template_declaration,
|
|
465
|
+
alias($.inline_method_definition, $.function_definition),
|
|
466
|
+
alias($.constructor_or_destructor_definition, $.function_definition),
|
|
467
|
+
alias($.constructor_or_destructor_declaration, $.declaration),
|
|
468
|
+
alias($.operator_cast_definition, $.function_definition),
|
|
469
|
+
alias($.operator_cast_declaration, $.declaration),
|
|
470
|
+
$.friend_declaration,
|
|
471
|
+
seq($.access_specifier, ':'),
|
|
472
|
+
$.alias_declaration,
|
|
473
|
+
$.using_declaration,
|
|
474
|
+
$.type_definition,
|
|
475
|
+
$.static_assert_declaration,
|
|
476
|
+
';',
|
|
477
|
+
),
|
|
478
|
+
|
|
479
|
+
field_declaration: $ => seq(
|
|
480
|
+
$._declaration_specifiers,
|
|
481
|
+
commaSep(seq(
|
|
482
|
+
field('declarator', $._field_declarator),
|
|
483
|
+
optional(choice(
|
|
484
|
+
$.bitfield_clause,
|
|
485
|
+
field('default_value', $.initializer_list),
|
|
486
|
+
seq('=', field('default_value', choice($.expression, $.initializer_list))),
|
|
487
|
+
)),
|
|
488
|
+
)),
|
|
489
|
+
optional($.attribute_specifier),
|
|
490
|
+
';',
|
|
491
|
+
),
|
|
492
|
+
|
|
493
|
+
inline_method_definition: $ => seq(
|
|
494
|
+
$._declaration_specifiers,
|
|
495
|
+
field('declarator', $._field_declarator),
|
|
496
|
+
choice(
|
|
497
|
+
field('body', choice($.compound_statement, $.try_statement)),
|
|
498
|
+
$.default_method_clause,
|
|
499
|
+
$.delete_method_clause,
|
|
500
|
+
$.pure_virtual_clause,
|
|
501
|
+
),
|
|
502
|
+
),
|
|
503
|
+
|
|
504
|
+
_constructor_specifiers: $ => choice(
|
|
505
|
+
$._declaration_modifiers,
|
|
506
|
+
$.explicit_function_specifier,
|
|
507
|
+
),
|
|
508
|
+
|
|
509
|
+
operator_cast_definition: $ => seq(
|
|
510
|
+
repeat($._constructor_specifiers),
|
|
511
|
+
field('declarator', choice(
|
|
512
|
+
$.operator_cast,
|
|
513
|
+
alias($.qualified_operator_cast_identifier, $.qualified_identifier),
|
|
514
|
+
)),
|
|
515
|
+
field('body', choice($.compound_statement, $.try_statement)),
|
|
516
|
+
),
|
|
517
|
+
|
|
518
|
+
operator_cast_declaration: $ => prec(1, seq(
|
|
519
|
+
repeat($._constructor_specifiers),
|
|
520
|
+
field('declarator', choice(
|
|
521
|
+
$.operator_cast,
|
|
522
|
+
alias($.qualified_operator_cast_identifier, $.qualified_identifier),
|
|
523
|
+
)),
|
|
524
|
+
optional(seq('=', field('default_value', $.expression))),
|
|
525
|
+
';',
|
|
526
|
+
)),
|
|
527
|
+
|
|
528
|
+
constructor_try_statement: $ => seq(
|
|
529
|
+
'try',
|
|
530
|
+
optional($.field_initializer_list),
|
|
531
|
+
field('body', $.compound_statement),
|
|
532
|
+
repeat1($.catch_clause),
|
|
533
|
+
),
|
|
534
|
+
|
|
535
|
+
constructor_or_destructor_definition: $ => seq(
|
|
536
|
+
repeat($._constructor_specifiers),
|
|
537
|
+
field('declarator', $.function_declarator),
|
|
538
|
+
choice(
|
|
539
|
+
seq(
|
|
540
|
+
optional($.field_initializer_list),
|
|
541
|
+
field('body', $.compound_statement),
|
|
542
|
+
),
|
|
543
|
+
alias($.constructor_try_statement, $.try_statement),
|
|
544
|
+
$.default_method_clause,
|
|
545
|
+
$.delete_method_clause,
|
|
546
|
+
$.pure_virtual_clause,
|
|
547
|
+
),
|
|
548
|
+
),
|
|
549
|
+
|
|
550
|
+
constructor_or_destructor_declaration: $ => seq(
|
|
551
|
+
repeat($._constructor_specifiers),
|
|
552
|
+
field('declarator', $.function_declarator),
|
|
553
|
+
';',
|
|
554
|
+
),
|
|
555
|
+
|
|
556
|
+
default_method_clause: _ => seq('=', 'default', ';'),
|
|
557
|
+
delete_method_clause: _ => seq('=', 'delete', ';'),
|
|
558
|
+
pure_virtual_clause: _ => seq('=', /0/, ';'),
|
|
559
|
+
|
|
560
|
+
friend_declaration: $ => seq(
|
|
561
|
+
optional('constexpr'),
|
|
562
|
+
'friend',
|
|
563
|
+
choice(
|
|
564
|
+
$.declaration,
|
|
565
|
+
$.function_definition,
|
|
566
|
+
seq(
|
|
567
|
+
optional(choice(
|
|
568
|
+
'class',
|
|
569
|
+
'struct',
|
|
570
|
+
'union',
|
|
571
|
+
)),
|
|
572
|
+
$._class_name, ';',
|
|
573
|
+
),
|
|
574
|
+
),
|
|
575
|
+
),
|
|
576
|
+
|
|
577
|
+
access_specifier: _ => choice(
|
|
578
|
+
'public',
|
|
579
|
+
'private',
|
|
580
|
+
'protected',
|
|
581
|
+
),
|
|
582
|
+
|
|
583
|
+
_declarator: ($, original) => choice(
|
|
584
|
+
original,
|
|
585
|
+
$.reference_declarator,
|
|
586
|
+
$.qualified_identifier,
|
|
587
|
+
$.template_function,
|
|
588
|
+
$.operator_name,
|
|
589
|
+
$.destructor_name,
|
|
590
|
+
$.structured_binding_declarator,
|
|
591
|
+
),
|
|
592
|
+
|
|
593
|
+
_field_declarator: ($, original) => choice(
|
|
594
|
+
original,
|
|
595
|
+
alias($.reference_field_declarator, $.reference_declarator),
|
|
596
|
+
$.template_method,
|
|
597
|
+
$.operator_name,
|
|
598
|
+
),
|
|
599
|
+
|
|
600
|
+
_type_declarator: ($, original) => choice(
|
|
601
|
+
original,
|
|
602
|
+
alias($.reference_type_declarator, $.reference_declarator),
|
|
603
|
+
),
|
|
604
|
+
|
|
605
|
+
_abstract_declarator: ($, original) => choice(
|
|
606
|
+
original,
|
|
607
|
+
$.abstract_reference_declarator,
|
|
608
|
+
),
|
|
609
|
+
|
|
610
|
+
reference_declarator: $ => prec.dynamic(1, prec.right(seq(choice('&', '&&'), $._declarator))),
|
|
611
|
+
reference_field_declarator: $ => prec.dynamic(1, prec.right(seq(choice('&', '&&'), $._field_declarator))),
|
|
612
|
+
reference_type_declarator: $ => prec.dynamic(1, prec.right(seq(choice('&', '&&'), $._type_declarator))),
|
|
613
|
+
abstract_reference_declarator: $ => prec.right(seq(choice('&', '&&'), optional($._abstract_declarator))),
|
|
614
|
+
|
|
615
|
+
structured_binding_declarator: $ => prec.dynamic(PREC.STRUCTURED_BINDING, seq(
|
|
616
|
+
'[', commaSep1($.identifier), ']',
|
|
617
|
+
)),
|
|
618
|
+
|
|
619
|
+
ref_qualifier: _ => choice('&', '&&'),
|
|
620
|
+
|
|
621
|
+
_function_declarator_seq: $ => seq(
|
|
622
|
+
field('parameters', $.parameter_list),
|
|
623
|
+
optional($._function_attributes_start),
|
|
624
|
+
optional($.ref_qualifier),
|
|
625
|
+
optional($._function_exception_specification),
|
|
626
|
+
optional($._function_attributes_end),
|
|
627
|
+
optional($.trailing_return_type),
|
|
628
|
+
optional($._function_postfix),
|
|
629
|
+
),
|
|
630
|
+
|
|
631
|
+
_function_attributes_start: $ => prec(1, choice(
|
|
632
|
+
seq(repeat1($.attribute_specifier), repeat($.type_qualifier)),
|
|
633
|
+
seq(repeat($.attribute_specifier), repeat1($.type_qualifier)),
|
|
634
|
+
)),
|
|
635
|
+
|
|
636
|
+
_function_exception_specification: $ => choice(
|
|
637
|
+
$.noexcept,
|
|
638
|
+
$.throw_specifier,
|
|
639
|
+
),
|
|
640
|
+
|
|
641
|
+
_function_attributes_end: $ => prec.right(seq(
|
|
642
|
+
optional($.gnu_asm_expression),
|
|
643
|
+
choice(
|
|
644
|
+
seq(repeat1($.attribute_specifier), repeat($.attribute_declaration)),
|
|
645
|
+
seq(repeat($.attribute_specifier), repeat1($.attribute_declaration)),
|
|
646
|
+
),
|
|
647
|
+
)),
|
|
648
|
+
|
|
649
|
+
_function_postfix: $ => prec.right(choice(
|
|
650
|
+
repeat1($.virtual_specifier),
|
|
651
|
+
$.requires_clause,
|
|
652
|
+
)),
|
|
653
|
+
|
|
654
|
+
function_declarator: $ => prec.dynamic(1, seq(
|
|
655
|
+
field('declarator', $._declarator),
|
|
656
|
+
$._function_declarator_seq,
|
|
657
|
+
)),
|
|
658
|
+
|
|
659
|
+
function_field_declarator: $ => prec.dynamic(1, seq(
|
|
660
|
+
field('declarator', $._field_declarator),
|
|
661
|
+
$._function_declarator_seq,
|
|
662
|
+
)),
|
|
663
|
+
|
|
664
|
+
abstract_function_declarator: $ => seq(
|
|
665
|
+
field('declarator', optional($._abstract_declarator)),
|
|
666
|
+
$._function_declarator_seq,
|
|
667
|
+
),
|
|
668
|
+
|
|
669
|
+
trailing_return_type: $ => seq('->', $.type_descriptor),
|
|
670
|
+
|
|
671
|
+
noexcept: $ => prec.right(seq(
|
|
672
|
+
'noexcept',
|
|
673
|
+
optional(
|
|
674
|
+
seq(
|
|
675
|
+
'(',
|
|
676
|
+
optional($.expression),
|
|
677
|
+
')',
|
|
678
|
+
),
|
|
679
|
+
),
|
|
680
|
+
)),
|
|
681
|
+
|
|
682
|
+
throw_specifier: $ => seq(
|
|
683
|
+
'throw',
|
|
684
|
+
seq(
|
|
685
|
+
'(',
|
|
686
|
+
commaSep($.type_descriptor),
|
|
687
|
+
')',
|
|
688
|
+
),
|
|
689
|
+
),
|
|
690
|
+
|
|
691
|
+
template_type: $ => seq(
|
|
692
|
+
field('name', $._type_identifier),
|
|
693
|
+
field('arguments', $.template_argument_list),
|
|
694
|
+
),
|
|
695
|
+
|
|
696
|
+
template_method: $ => seq(
|
|
697
|
+
field('name', choice($._field_identifier, $.operator_name)),
|
|
698
|
+
field('arguments', $.template_argument_list),
|
|
699
|
+
),
|
|
700
|
+
|
|
701
|
+
template_function: $ => seq(
|
|
702
|
+
field('name', $.identifier),
|
|
703
|
+
field('arguments', $.template_argument_list),
|
|
704
|
+
),
|
|
705
|
+
|
|
706
|
+
template_argument_list: $ => seq(
|
|
707
|
+
'<',
|
|
708
|
+
commaSep(choice(
|
|
709
|
+
prec.dynamic(3, $.type_descriptor),
|
|
710
|
+
prec.dynamic(2, alias($.type_parameter_pack_expansion, $.parameter_pack_expansion)),
|
|
711
|
+
prec.dynamic(1, $.expression),
|
|
712
|
+
)),
|
|
713
|
+
alias(token(prec(1, '>')), '>'),
|
|
714
|
+
),
|
|
715
|
+
|
|
716
|
+
namespace_definition: $ => seq(
|
|
717
|
+
optional('inline'),
|
|
718
|
+
'namespace',
|
|
719
|
+
optional($.attribute_declaration),
|
|
720
|
+
field('name', optional(
|
|
721
|
+
choice(
|
|
722
|
+
$._namespace_identifier,
|
|
723
|
+
$.nested_namespace_specifier,
|
|
724
|
+
))),
|
|
725
|
+
field('body', $.declaration_list),
|
|
726
|
+
),
|
|
727
|
+
|
|
728
|
+
namespace_alias_definition: $ => seq(
|
|
729
|
+
'namespace',
|
|
730
|
+
field('name', $._namespace_identifier),
|
|
731
|
+
'=',
|
|
732
|
+
choice(
|
|
733
|
+
$._namespace_identifier,
|
|
734
|
+
$.nested_namespace_specifier,
|
|
735
|
+
),
|
|
736
|
+
';',
|
|
737
|
+
),
|
|
738
|
+
|
|
739
|
+
_namespace_specifier: $ => seq(
|
|
740
|
+
optional('inline'),
|
|
741
|
+
$._namespace_identifier,
|
|
742
|
+
),
|
|
743
|
+
|
|
744
|
+
nested_namespace_specifier: $ => prec(1, seq(
|
|
745
|
+
optional($._namespace_specifier),
|
|
746
|
+
'::',
|
|
747
|
+
choice(
|
|
748
|
+
$.nested_namespace_specifier,
|
|
749
|
+
$._namespace_specifier,
|
|
750
|
+
),
|
|
751
|
+
)),
|
|
752
|
+
|
|
753
|
+
using_declaration: $ => seq(
|
|
754
|
+
'using',
|
|
755
|
+
optional(choice('namespace', 'enum')),
|
|
756
|
+
choice(
|
|
757
|
+
$.identifier,
|
|
758
|
+
$.qualified_identifier,
|
|
759
|
+
),
|
|
760
|
+
';',
|
|
761
|
+
),
|
|
762
|
+
|
|
763
|
+
alias_declaration: $ => seq(
|
|
764
|
+
'using',
|
|
765
|
+
field('name', $._type_identifier),
|
|
766
|
+
repeat($.attribute_declaration),
|
|
767
|
+
'=',
|
|
768
|
+
field('type', $.type_descriptor),
|
|
769
|
+
';',
|
|
770
|
+
),
|
|
771
|
+
|
|
772
|
+
static_assert_declaration: $ => seq(
|
|
773
|
+
'static_assert',
|
|
774
|
+
'(',
|
|
775
|
+
field('condition', $.expression),
|
|
776
|
+
optional(seq(
|
|
777
|
+
',',
|
|
778
|
+
field('message', $._string),
|
|
779
|
+
)),
|
|
780
|
+
')',
|
|
781
|
+
';',
|
|
782
|
+
),
|
|
783
|
+
|
|
784
|
+
concept_definition: $ => seq(
|
|
785
|
+
'concept',
|
|
786
|
+
field('name', $.identifier),
|
|
787
|
+
'=',
|
|
788
|
+
$.expression,
|
|
789
|
+
';',
|
|
790
|
+
),
|
|
791
|
+
|
|
792
|
+
// Statements
|
|
793
|
+
|
|
794
|
+
_top_level_statement: ($, original) => choice(
|
|
795
|
+
original,
|
|
796
|
+
$.co_return_statement,
|
|
797
|
+
$.co_yield_statement,
|
|
798
|
+
$.for_range_loop,
|
|
799
|
+
$.try_statement,
|
|
800
|
+
$.throw_statement,
|
|
801
|
+
),
|
|
802
|
+
|
|
803
|
+
_non_case_statement: ($, original) => choice(
|
|
804
|
+
original,
|
|
805
|
+
$.co_return_statement,
|
|
806
|
+
$.co_yield_statement,
|
|
807
|
+
$.for_range_loop,
|
|
808
|
+
$.try_statement,
|
|
809
|
+
$.throw_statement,
|
|
810
|
+
),
|
|
811
|
+
|
|
812
|
+
switch_statement: $ => seq(
|
|
813
|
+
'switch',
|
|
814
|
+
field('condition', $.condition_clause),
|
|
815
|
+
field('body', $.compound_statement),
|
|
816
|
+
),
|
|
817
|
+
|
|
818
|
+
while_statement: $ => seq(
|
|
819
|
+
'while',
|
|
820
|
+
field('condition', $.condition_clause),
|
|
821
|
+
field('body', $.statement),
|
|
822
|
+
),
|
|
823
|
+
|
|
824
|
+
if_statement: $ => prec.right(seq(
|
|
825
|
+
'if',
|
|
826
|
+
optional('constexpr'),
|
|
827
|
+
field('condition', $.condition_clause),
|
|
828
|
+
field('consequence', $.statement),
|
|
829
|
+
optional(field('alternative', $.else_clause)),
|
|
830
|
+
)),
|
|
831
|
+
|
|
832
|
+
// Using prec(1) instead of prec.dynamic(1) causes issues with the
|
|
833
|
+
// range loop's declaration specifiers if `int` is passed in, it'll
|
|
834
|
+
// always prefer the standard for loop and give us a parse error.
|
|
835
|
+
_for_statement_body: ($, original) => prec.dynamic(1, original),
|
|
836
|
+
for_range_loop: $ => seq(
|
|
837
|
+
'for',
|
|
838
|
+
'(',
|
|
839
|
+
$._for_range_loop_body,
|
|
840
|
+
')',
|
|
841
|
+
field('body', $.statement),
|
|
842
|
+
),
|
|
843
|
+
_for_range_loop_body: $ => seq(
|
|
844
|
+
field('initializer', optional($.init_statement)),
|
|
845
|
+
$._declaration_specifiers,
|
|
846
|
+
field('declarator', $._declarator),
|
|
847
|
+
':',
|
|
848
|
+
field('right', choice(
|
|
849
|
+
$.expression,
|
|
850
|
+
$.initializer_list,
|
|
851
|
+
)),
|
|
852
|
+
),
|
|
853
|
+
|
|
854
|
+
init_statement: $ => choice(
|
|
855
|
+
$.alias_declaration,
|
|
856
|
+
$.type_definition,
|
|
857
|
+
$.declaration,
|
|
858
|
+
$.expression_statement,
|
|
859
|
+
),
|
|
860
|
+
|
|
861
|
+
condition_clause: $ => seq(
|
|
862
|
+
'(',
|
|
863
|
+
field('initializer', optional($.init_statement)),
|
|
864
|
+
field('value', choice(
|
|
865
|
+
$.expression,
|
|
866
|
+
$.comma_expression,
|
|
867
|
+
alias($.condition_declaration, $.declaration),
|
|
868
|
+
)),
|
|
869
|
+
')',
|
|
870
|
+
),
|
|
871
|
+
|
|
872
|
+
condition_declaration: $ => seq(
|
|
873
|
+
$._declaration_specifiers,
|
|
874
|
+
field('declarator', $._declarator),
|
|
875
|
+
choice(
|
|
876
|
+
seq(
|
|
877
|
+
'=',
|
|
878
|
+
field('value', $.expression),
|
|
879
|
+
),
|
|
880
|
+
field('value', $.initializer_list),
|
|
881
|
+
),
|
|
882
|
+
),
|
|
883
|
+
|
|
884
|
+
return_statement: ($, original) => seq(
|
|
885
|
+
choice(
|
|
886
|
+
original,
|
|
887
|
+
seq('return', $.initializer_list, ';'),
|
|
888
|
+
),
|
|
889
|
+
),
|
|
890
|
+
|
|
891
|
+
co_return_statement: $ => seq(
|
|
892
|
+
'co_return',
|
|
893
|
+
optional($.expression),
|
|
894
|
+
';',
|
|
895
|
+
),
|
|
896
|
+
|
|
897
|
+
co_yield_statement: $ => seq(
|
|
898
|
+
'co_yield',
|
|
899
|
+
$.expression,
|
|
900
|
+
';',
|
|
901
|
+
),
|
|
902
|
+
|
|
903
|
+
throw_statement: $ => seq(
|
|
904
|
+
'throw',
|
|
905
|
+
optional($.expression),
|
|
906
|
+
';',
|
|
907
|
+
),
|
|
908
|
+
|
|
909
|
+
try_statement: $ => seq(
|
|
910
|
+
'try',
|
|
911
|
+
field('body', $.compound_statement),
|
|
912
|
+
repeat1($.catch_clause),
|
|
913
|
+
),
|
|
914
|
+
|
|
915
|
+
catch_clause: $ => seq(
|
|
916
|
+
'catch',
|
|
917
|
+
field('parameters', $.parameter_list),
|
|
918
|
+
field('body', $.compound_statement),
|
|
919
|
+
),
|
|
920
|
+
|
|
921
|
+
// Expressions
|
|
922
|
+
|
|
923
|
+
_expression_not_binary: ($, original) => choice(
|
|
924
|
+
original,
|
|
925
|
+
$.co_await_expression,
|
|
926
|
+
$.requires_expression,
|
|
927
|
+
$.requires_clause,
|
|
928
|
+
$.template_function,
|
|
929
|
+
$.qualified_identifier,
|
|
930
|
+
$.new_expression,
|
|
931
|
+
$.delete_expression,
|
|
932
|
+
$.lambda_expression,
|
|
933
|
+
$.parameter_pack_expansion,
|
|
934
|
+
$.this,
|
|
935
|
+
$.user_defined_literal,
|
|
936
|
+
$.fold_expression,
|
|
937
|
+
),
|
|
938
|
+
|
|
939
|
+
_string: $ => choice(
|
|
940
|
+
$.string_literal,
|
|
941
|
+
$.raw_string_literal,
|
|
942
|
+
$.concatenated_string,
|
|
943
|
+
),
|
|
944
|
+
|
|
945
|
+
raw_string_literal: $ => seq(
|
|
946
|
+
choice('R"', 'LR"', 'uR"', 'UR"', 'u8R"'),
|
|
947
|
+
choice(
|
|
948
|
+
seq(
|
|
949
|
+
field('delimiter', $.raw_string_delimiter),
|
|
950
|
+
'(',
|
|
951
|
+
$.raw_string_content,
|
|
952
|
+
')',
|
|
953
|
+
$.raw_string_delimiter,
|
|
954
|
+
),
|
|
955
|
+
seq('(', $.raw_string_content, ')'),
|
|
956
|
+
),
|
|
957
|
+
'"',
|
|
958
|
+
),
|
|
959
|
+
|
|
960
|
+
subscript_expression: $ => prec(PREC.SUBSCRIPT, seq(
|
|
961
|
+
field('argument', $.expression),
|
|
962
|
+
field('indices', $.subscript_argument_list),
|
|
963
|
+
)),
|
|
964
|
+
|
|
965
|
+
subscript_argument_list: $ => seq(
|
|
966
|
+
'[',
|
|
967
|
+
commaSep(choice($.expression, $.initializer_list)),
|
|
968
|
+
']',
|
|
969
|
+
),
|
|
970
|
+
|
|
971
|
+
call_expression: ($, original) => choice(original, seq(
|
|
972
|
+
field('function', $.primitive_type),
|
|
973
|
+
field('arguments', $.argument_list),
|
|
974
|
+
)),
|
|
975
|
+
|
|
976
|
+
co_await_expression: $ => prec.left(PREC.UNARY, seq(
|
|
977
|
+
field('operator', 'co_await'),
|
|
978
|
+
field('argument', $.expression),
|
|
979
|
+
)),
|
|
980
|
+
|
|
981
|
+
new_expression: $ => prec.right(PREC.NEW, seq(
|
|
982
|
+
optional('::'),
|
|
983
|
+
'new',
|
|
984
|
+
field('placement', optional($.argument_list)),
|
|
985
|
+
field('type', $.type_specifier),
|
|
986
|
+
field('declarator', optional($.new_declarator)),
|
|
987
|
+
field('arguments', optional(choice(
|
|
988
|
+
$.argument_list,
|
|
989
|
+
$.initializer_list,
|
|
990
|
+
))),
|
|
991
|
+
)),
|
|
992
|
+
|
|
993
|
+
new_declarator: $ => prec.right(seq(
|
|
994
|
+
'[',
|
|
995
|
+
field('length', $.expression),
|
|
996
|
+
']',
|
|
997
|
+
optional($.new_declarator),
|
|
998
|
+
)),
|
|
999
|
+
|
|
1000
|
+
delete_expression: $ => seq(
|
|
1001
|
+
optional('::'),
|
|
1002
|
+
'delete',
|
|
1003
|
+
optional(seq('[', ']')),
|
|
1004
|
+
$.expression,
|
|
1005
|
+
),
|
|
1006
|
+
|
|
1007
|
+
field_expression: $ => seq(
|
|
1008
|
+
prec(PREC.FIELD, seq(
|
|
1009
|
+
field('argument', $.expression),
|
|
1010
|
+
field('operator', choice('.', '.*', '->')),
|
|
1011
|
+
)),
|
|
1012
|
+
field('field', choice(
|
|
1013
|
+
prec.dynamic(1, $._field_identifier),
|
|
1014
|
+
alias($.qualified_field_identifier, $.qualified_identifier),
|
|
1015
|
+
$.destructor_name,
|
|
1016
|
+
$.template_method,
|
|
1017
|
+
alias($.dependent_field_identifier, $.dependent_name),
|
|
1018
|
+
)),
|
|
1019
|
+
),
|
|
1020
|
+
|
|
1021
|
+
type_requirement: $ => seq('typename', $._class_name),
|
|
1022
|
+
|
|
1023
|
+
compound_requirement: $ => seq(
|
|
1024
|
+
'{', $.expression, '}',
|
|
1025
|
+
optional('noexcept'),
|
|
1026
|
+
optional($.trailing_return_type),
|
|
1027
|
+
';',
|
|
1028
|
+
),
|
|
1029
|
+
|
|
1030
|
+
_requirement: $ => choice(
|
|
1031
|
+
alias($.expression_statement, $.simple_requirement),
|
|
1032
|
+
$.type_requirement,
|
|
1033
|
+
$.compound_requirement,
|
|
1034
|
+
),
|
|
1035
|
+
|
|
1036
|
+
requirement_seq: $ => seq('{', repeat($._requirement), '}'),
|
|
1037
|
+
|
|
1038
|
+
constraint_conjunction: $ => prec.left(PREC.LOGICAL_AND, seq(
|
|
1039
|
+
field('left', $._requirement_clause_constraint),
|
|
1040
|
+
field('operator', choice('&&', 'and')),
|
|
1041
|
+
field('right', $._requirement_clause_constraint)),
|
|
1042
|
+
),
|
|
1043
|
+
|
|
1044
|
+
constraint_disjunction: $ => prec.left(PREC.LOGICAL_OR, seq(
|
|
1045
|
+
field('left', $._requirement_clause_constraint),
|
|
1046
|
+
field('operator', choice('||', 'or')),
|
|
1047
|
+
field('right', $._requirement_clause_constraint)),
|
|
1048
|
+
),
|
|
1049
|
+
|
|
1050
|
+
_requirement_clause_constraint: $ => choice(
|
|
1051
|
+
// Primary expressions"
|
|
1052
|
+
$.true,
|
|
1053
|
+
$.false,
|
|
1054
|
+
$._class_name,
|
|
1055
|
+
$.fold_expression,
|
|
1056
|
+
$.lambda_expression,
|
|
1057
|
+
$.requires_expression,
|
|
1058
|
+
|
|
1059
|
+
// Parenthesized expressions
|
|
1060
|
+
seq('(', $.expression, ')'),
|
|
1061
|
+
|
|
1062
|
+
// conjunction or disjunction of the above
|
|
1063
|
+
$.constraint_conjunction,
|
|
1064
|
+
$.constraint_disjunction,
|
|
1065
|
+
),
|
|
1066
|
+
|
|
1067
|
+
requires_clause: $ => seq(
|
|
1068
|
+
'requires',
|
|
1069
|
+
field('constraint', $._requirement_clause_constraint),
|
|
1070
|
+
),
|
|
1071
|
+
|
|
1072
|
+
requires_parameter_list: $ => seq(
|
|
1073
|
+
'(',
|
|
1074
|
+
commaSep(choice(
|
|
1075
|
+
$.parameter_declaration,
|
|
1076
|
+
$.optional_parameter_declaration,
|
|
1077
|
+
$.variadic_parameter_declaration,
|
|
1078
|
+
)),
|
|
1079
|
+
')',
|
|
1080
|
+
),
|
|
1081
|
+
|
|
1082
|
+
requires_expression: $ => seq(
|
|
1083
|
+
'requires',
|
|
1084
|
+
field('parameters', optional(alias($.requires_parameter_list, $.parameter_list))),
|
|
1085
|
+
field('requirements', $.requirement_seq),
|
|
1086
|
+
),
|
|
1087
|
+
|
|
1088
|
+
lambda_expression: $ => seq(
|
|
1089
|
+
field('captures', $.lambda_capture_specifier),
|
|
1090
|
+
optional(seq(
|
|
1091
|
+
field('template_parameters', $.template_parameter_list),
|
|
1092
|
+
optional(field('constraint', $.requires_clause)),
|
|
1093
|
+
)),
|
|
1094
|
+
optional(field('declarator', $.abstract_function_declarator)),
|
|
1095
|
+
field('body', $.compound_statement),
|
|
1096
|
+
),
|
|
1097
|
+
|
|
1098
|
+
lambda_capture_specifier: $ => prec(PREC.LAMBDA, seq(
|
|
1099
|
+
'[',
|
|
1100
|
+
choice(
|
|
1101
|
+
$.lambda_default_capture,
|
|
1102
|
+
commaSep($._lambda_capture),
|
|
1103
|
+
seq(
|
|
1104
|
+
$.lambda_default_capture,
|
|
1105
|
+
',', commaSep1($._lambda_capture),
|
|
1106
|
+
),
|
|
1107
|
+
),
|
|
1108
|
+
']',
|
|
1109
|
+
)),
|
|
1110
|
+
|
|
1111
|
+
lambda_default_capture: _ => choice('=', '&'),
|
|
1112
|
+
|
|
1113
|
+
_lambda_capture_identifier: $ => seq(
|
|
1114
|
+
optional('&'),
|
|
1115
|
+
choice(
|
|
1116
|
+
$.identifier,
|
|
1117
|
+
$.qualified_identifier,
|
|
1118
|
+
alias($.identifier_parameter_pack_expansion, $.parameter_pack_expansion),
|
|
1119
|
+
),
|
|
1120
|
+
),
|
|
1121
|
+
|
|
1122
|
+
lambda_capture_initializer: $ => seq(
|
|
1123
|
+
optional('&'),
|
|
1124
|
+
optional('...'),
|
|
1125
|
+
field('left', $.identifier),
|
|
1126
|
+
'=',
|
|
1127
|
+
field('right', $.expression),
|
|
1128
|
+
),
|
|
1129
|
+
|
|
1130
|
+
_lambda_capture: $ => choice(
|
|
1131
|
+
seq(optional('*'), $.this),
|
|
1132
|
+
$._lambda_capture_identifier,
|
|
1133
|
+
$.lambda_capture_initializer,
|
|
1134
|
+
),
|
|
1135
|
+
|
|
1136
|
+
_fold_operator: _ => choice(...FOLD_OPERATORS),
|
|
1137
|
+
_binary_fold_operator: _ => choice(...FOLD_OPERATORS.map((operator) => seq(field('operator', operator), '...', operator))),
|
|
1138
|
+
|
|
1139
|
+
_unary_left_fold: $ => seq(
|
|
1140
|
+
field('left', '...'),
|
|
1141
|
+
field('operator', $._fold_operator),
|
|
1142
|
+
field('right', $.expression),
|
|
1143
|
+
),
|
|
1144
|
+
_unary_right_fold: $ => seq(
|
|
1145
|
+
field('left', $.expression),
|
|
1146
|
+
field('operator', $._fold_operator),
|
|
1147
|
+
field('right', '...'),
|
|
1148
|
+
),
|
|
1149
|
+
_binary_fold: $ => seq(
|
|
1150
|
+
field('left', $.expression),
|
|
1151
|
+
$._binary_fold_operator,
|
|
1152
|
+
field('right', $.expression),
|
|
1153
|
+
),
|
|
1154
|
+
|
|
1155
|
+
fold_expression: $ => seq(
|
|
1156
|
+
'(',
|
|
1157
|
+
choice(
|
|
1158
|
+
$._unary_right_fold,
|
|
1159
|
+
$._unary_left_fold,
|
|
1160
|
+
$._binary_fold,
|
|
1161
|
+
),
|
|
1162
|
+
')',
|
|
1163
|
+
),
|
|
1164
|
+
|
|
1165
|
+
parameter_pack_expansion: $ => prec(-1, seq(
|
|
1166
|
+
field('pattern', $.expression),
|
|
1167
|
+
'...',
|
|
1168
|
+
)),
|
|
1169
|
+
|
|
1170
|
+
type_parameter_pack_expansion: $ => seq(
|
|
1171
|
+
field('pattern', $.type_descriptor),
|
|
1172
|
+
'...',
|
|
1173
|
+
),
|
|
1174
|
+
|
|
1175
|
+
identifier_parameter_pack_expansion: $ => seq(
|
|
1176
|
+
field('pattern', $.identifier),
|
|
1177
|
+
'...',
|
|
1178
|
+
),
|
|
1179
|
+
|
|
1180
|
+
sizeof_expression: ($, original) => prec.right(PREC.SIZEOF, choice(
|
|
1181
|
+
original,
|
|
1182
|
+
seq(
|
|
1183
|
+
'sizeof', '...',
|
|
1184
|
+
'(',
|
|
1185
|
+
field('value', $.identifier),
|
|
1186
|
+
')',
|
|
1187
|
+
),
|
|
1188
|
+
)),
|
|
1189
|
+
|
|
1190
|
+
unary_expression: ($, original) => choice(
|
|
1191
|
+
original,
|
|
1192
|
+
prec.left(PREC.UNARY, seq(
|
|
1193
|
+
field('operator', choice('not', 'compl')),
|
|
1194
|
+
field('argument', $.expression),
|
|
1195
|
+
)),
|
|
1196
|
+
),
|
|
1197
|
+
|
|
1198
|
+
binary_expression: ($, original) => {
|
|
1199
|
+
const table = [
|
|
1200
|
+
['<=>', PREC.THREE_WAY],
|
|
1201
|
+
['or', PREC.LOGICAL_OR],
|
|
1202
|
+
['and', PREC.LOGICAL_AND],
|
|
1203
|
+
['bitor', PREC.INCLUSIVE_OR],
|
|
1204
|
+
['xor', PREC.EXCLUSIVE_OR],
|
|
1205
|
+
['bitand', PREC.BITWISE_AND],
|
|
1206
|
+
['not_eq', PREC.EQUAL],
|
|
1207
|
+
];
|
|
1208
|
+
|
|
1209
|
+
return choice(
|
|
1210
|
+
original,
|
|
1211
|
+
...table.map(([operator, precedence]) => {
|
|
1212
|
+
return prec.left(precedence, seq(
|
|
1213
|
+
field('left', $.expression),
|
|
1214
|
+
// @ts-ignore
|
|
1215
|
+
field('operator', operator),
|
|
1216
|
+
field('right', $.expression),
|
|
1217
|
+
));
|
|
1218
|
+
}));
|
|
1219
|
+
},
|
|
1220
|
+
|
|
1221
|
+
// The compound_statement is added to parse macros taking statements as arguments, e.g. MYFORLOOP(1, 10, i, { foo(i); bar(i); })
|
|
1222
|
+
argument_list: $ => seq(
|
|
1223
|
+
'(',
|
|
1224
|
+
commaSep(choice($.expression, $.initializer_list, $.compound_statement)),
|
|
1225
|
+
')',
|
|
1226
|
+
),
|
|
1227
|
+
|
|
1228
|
+
destructor_name: $ => prec(1, seq('~', $.identifier)),
|
|
1229
|
+
|
|
1230
|
+
compound_literal_expression: ($, original) => choice(
|
|
1231
|
+
original,
|
|
1232
|
+
seq(
|
|
1233
|
+
field('type', choice($._class_name, $.primitive_type)),
|
|
1234
|
+
field('value', $.initializer_list),
|
|
1235
|
+
),
|
|
1236
|
+
),
|
|
1237
|
+
|
|
1238
|
+
dependent_identifier: $ => seq('template', $.template_function),
|
|
1239
|
+
dependent_field_identifier: $ => seq('template', $.template_method),
|
|
1240
|
+
dependent_type_identifier: $ => seq('template', $.template_type),
|
|
1241
|
+
|
|
1242
|
+
_scope_resolution: $ => prec(1, seq(
|
|
1243
|
+
field('scope', optional(choice(
|
|
1244
|
+
$._namespace_identifier,
|
|
1245
|
+
$.template_type,
|
|
1246
|
+
$.decltype,
|
|
1247
|
+
alias($.dependent_type_identifier, $.dependent_name),
|
|
1248
|
+
))),
|
|
1249
|
+
'::',
|
|
1250
|
+
)),
|
|
1251
|
+
|
|
1252
|
+
qualified_field_identifier: $ => seq(
|
|
1253
|
+
$._scope_resolution,
|
|
1254
|
+
field('name', choice(
|
|
1255
|
+
alias($.dependent_field_identifier, $.dependent_name),
|
|
1256
|
+
alias($.qualified_field_identifier, $.qualified_identifier),
|
|
1257
|
+
$.template_method,
|
|
1258
|
+
prec.dynamic(1, $._field_identifier),
|
|
1259
|
+
)),
|
|
1260
|
+
),
|
|
1261
|
+
|
|
1262
|
+
qualified_identifier: $ => seq(
|
|
1263
|
+
$._scope_resolution,
|
|
1264
|
+
field('name', choice(
|
|
1265
|
+
alias($.dependent_identifier, $.dependent_name),
|
|
1266
|
+
$.qualified_identifier,
|
|
1267
|
+
$.template_function,
|
|
1268
|
+
seq(optional('template'), $.identifier),
|
|
1269
|
+
$.operator_name,
|
|
1270
|
+
$.destructor_name,
|
|
1271
|
+
$.pointer_type_declarator,
|
|
1272
|
+
)),
|
|
1273
|
+
),
|
|
1274
|
+
|
|
1275
|
+
qualified_type_identifier: $ => seq(
|
|
1276
|
+
$._scope_resolution,
|
|
1277
|
+
field('name', choice(
|
|
1278
|
+
alias($.dependent_type_identifier, $.dependent_name),
|
|
1279
|
+
alias($.qualified_type_identifier, $.qualified_identifier),
|
|
1280
|
+
$.template_type,
|
|
1281
|
+
$._type_identifier,
|
|
1282
|
+
)),
|
|
1283
|
+
),
|
|
1284
|
+
|
|
1285
|
+
qualified_operator_cast_identifier: $ => seq(
|
|
1286
|
+
$._scope_resolution,
|
|
1287
|
+
field('name', choice(
|
|
1288
|
+
alias($.qualified_operator_cast_identifier, $.qualified_identifier),
|
|
1289
|
+
$.operator_cast,
|
|
1290
|
+
)),
|
|
1291
|
+
),
|
|
1292
|
+
|
|
1293
|
+
_assignment_left_expression: ($, original) => choice(
|
|
1294
|
+
original,
|
|
1295
|
+
$.qualified_identifier,
|
|
1296
|
+
$.user_defined_literal,
|
|
1297
|
+
),
|
|
1298
|
+
|
|
1299
|
+
assignment_expression: $ => prec.right(PREC.ASSIGNMENT, seq(
|
|
1300
|
+
field('left', $._assignment_left_expression),
|
|
1301
|
+
field('operator', choice(...ASSIGNMENT_OPERATORS)),
|
|
1302
|
+
field('right', choice($.expression, $.initializer_list)),
|
|
1303
|
+
)),
|
|
1304
|
+
|
|
1305
|
+
_assignment_expression_lhs: $ => seq(
|
|
1306
|
+
field('left', $.expression),
|
|
1307
|
+
field('operator', choice(...ASSIGNMENT_OPERATORS)),
|
|
1308
|
+
field('right', choice($.expression, $.initializer_list)),
|
|
1309
|
+
),
|
|
1310
|
+
|
|
1311
|
+
// This prevents an ambiguity between fold expressions
|
|
1312
|
+
// and assignment expressions within parentheses.
|
|
1313
|
+
parenthesized_expression: ($, original) => choice(
|
|
1314
|
+
original,
|
|
1315
|
+
seq('(', alias($._assignment_expression_lhs, $.assignment_expression), ')'),
|
|
1316
|
+
),
|
|
1317
|
+
|
|
1318
|
+
operator_name: $ => prec(1, seq(
|
|
1319
|
+
'operator',
|
|
1320
|
+
choice(
|
|
1321
|
+
'co_await',
|
|
1322
|
+
'+', '-', '*', '/', '%',
|
|
1323
|
+
'^', '&', '|', '~',
|
|
1324
|
+
'!', '=', '<', '>',
|
|
1325
|
+
'+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=',
|
|
1326
|
+
'<<', '>>', '>>=', '<<=',
|
|
1327
|
+
'==', '!=', '<=', '>=',
|
|
1328
|
+
'<=>',
|
|
1329
|
+
'&&', '||',
|
|
1330
|
+
'++', '--',
|
|
1331
|
+
',',
|
|
1332
|
+
'->*',
|
|
1333
|
+
'->',
|
|
1334
|
+
'()', '[]',
|
|
1335
|
+
'xor', 'bitand', 'bitor', 'compl',
|
|
1336
|
+
'not', 'xor_eq', 'and_eq', 'or_eq', 'not_eq',
|
|
1337
|
+
'and', 'or',
|
|
1338
|
+
seq(choice('new', 'delete'), optional('[]')),
|
|
1339
|
+
seq('""', $.identifier),
|
|
1340
|
+
),
|
|
1341
|
+
)),
|
|
1342
|
+
|
|
1343
|
+
this: _ => 'this',
|
|
1344
|
+
|
|
1345
|
+
concatenated_string: $ => prec.right(seq(
|
|
1346
|
+
choice($.identifier, $.string_literal, $.raw_string_literal),
|
|
1347
|
+
choice($.string_literal, $.raw_string_literal),
|
|
1348
|
+
repeat(choice($.identifier, $.string_literal, $.raw_string_literal)),
|
|
1349
|
+
)),
|
|
1350
|
+
|
|
1351
|
+
number_literal: $ => {
|
|
1352
|
+
const sign = /[-\+]/;
|
|
1353
|
+
const separator = '\'';
|
|
1354
|
+
const binary = /[01]/;
|
|
1355
|
+
const binaryDigits = seq(repeat1(binary), repeat(seq(separator, repeat1(binary))));
|
|
1356
|
+
const decimal = /[0-9]/;
|
|
1357
|
+
const firstDecimal = /[1-9]/;
|
|
1358
|
+
const intDecimalDigits = seq(firstDecimal, repeat(decimal), repeat(seq(separator, repeat1(decimal))));
|
|
1359
|
+
const floatDecimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
|
|
1360
|
+
const hex = /[0-9a-fA-F]/;
|
|
1361
|
+
const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
|
|
1362
|
+
const octal = /[0-7]/;
|
|
1363
|
+
const octalDigits = seq('0', repeat(octal), repeat(seq(separator, repeat1(octal))));
|
|
1364
|
+
const hexExponent = seq(/[pP]/, optional(sign), floatDecimalDigits);
|
|
1365
|
+
const decimalExponent = seq(/[eE]/, optional(sign), floatDecimalDigits);
|
|
1366
|
+
const intSuffix = /(ll|LL)[uU]?|[uU](ll|LL)?|[uU][lL]?|[uU][zZ]?|[lL][uU]?|[zZ][uU]?/;
|
|
1367
|
+
const floatSuffix = /([fF](16|32|64|128)?)|[lL]|(bf16|BF16)/;
|
|
1368
|
+
|
|
1369
|
+
return token(seq(
|
|
1370
|
+
optional(sign),
|
|
1371
|
+
choice(
|
|
1372
|
+
seq(
|
|
1373
|
+
choice(
|
|
1374
|
+
seq(choice('0b', '0B'), binaryDigits),
|
|
1375
|
+
intDecimalDigits,
|
|
1376
|
+
seq(choice('0x', '0X'), hexDigits),
|
|
1377
|
+
octalDigits,
|
|
1378
|
+
),
|
|
1379
|
+
optional(intSuffix),
|
|
1380
|
+
),
|
|
1381
|
+
seq(
|
|
1382
|
+
choice(
|
|
1383
|
+
seq(floatDecimalDigits, decimalExponent),
|
|
1384
|
+
seq(floatDecimalDigits, '.', optional(floatDecimalDigits), optional(decimalExponent)),
|
|
1385
|
+
seq('.', floatDecimalDigits, optional(decimalExponent)),
|
|
1386
|
+
seq(
|
|
1387
|
+
choice('0x', '0X'),
|
|
1388
|
+
choice(
|
|
1389
|
+
hexDigits,
|
|
1390
|
+
seq(hexDigits, '.', optional(hexDigits)),
|
|
1391
|
+
seq('.', hexDigits)),
|
|
1392
|
+
hexExponent,
|
|
1393
|
+
),
|
|
1394
|
+
),
|
|
1395
|
+
optional(floatSuffix),
|
|
1396
|
+
),
|
|
1397
|
+
),
|
|
1398
|
+
));
|
|
1399
|
+
},
|
|
1400
|
+
|
|
1401
|
+
literal_suffix: _ => token.immediate(/[a-zA-Z_]\w*/),
|
|
1402
|
+
|
|
1403
|
+
user_defined_literal: $ => seq(
|
|
1404
|
+
choice(
|
|
1405
|
+
$.number_literal,
|
|
1406
|
+
$.char_literal,
|
|
1407
|
+
$._string,
|
|
1408
|
+
),
|
|
1409
|
+
$.literal_suffix,
|
|
1410
|
+
),
|
|
1411
|
+
|
|
1412
|
+
_namespace_identifier: $ => alias($.identifier, $.namespace_identifier),
|
|
1413
|
+
},
|
|
1414
|
+
});
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1418
|
+
*
|
|
1419
|
+
* @param {Rule} rule
|
|
1420
|
+
*
|
|
1421
|
+
* @returns {ChoiceRule}
|
|
1422
|
+
*/
|
|
1423
|
+
function commaSep(rule) {
|
|
1424
|
+
return optional(commaSep1(rule));
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Creates a rule to match one or more of the rules separated by a comma
|
|
1429
|
+
*
|
|
1430
|
+
* @param {Rule} rule
|
|
1431
|
+
*
|
|
1432
|
+
* @returns {SeqRule}
|
|
1433
|
+
*/
|
|
1434
|
+
function commaSep1(rule) {
|
|
1435
|
+
return seq(rule, repeat(seq(',', rule)));
|
|
1436
|
+
}
|