pax_global_header00006660000000000000000000000064151607464240014523gustar00rootroot0000000000000052 comment=b12e12672ba29233e5ac91358b5be5df1157f3b9 tree-sitter-rust-orchard-0.16.3+ds/000077500000000000000000000000001516074642400170765ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/.editorconfig000066400000000000000000000010351516074642400215520ustar00rootroot00000000000000root = true [*] charset = utf-8 [*.{json,toml,yml,gyp}] indent_style = space indent_size = 2 [*.js] indent_style = space indent_size = 2 [*.scm] indent_style = space indent_size = 2 [*.{c,cc,h}] indent_style = space indent_size = 4 [*.rs] indent_style = space indent_size = 4 [*.{py,pyi}] indent_style = space indent_size = 4 [*.swift] indent_style = space indent_size = 4 [*.go] indent_style = tab indent_size = 8 [Makefile] indent_style = tab indent_size = 8 [parser.c] indent_size = 2 [{alloc,array,parser}.h] indent_size = 2 tree-sitter-rust-orchard-0.16.3+ds/.forgejo/000077500000000000000000000000001516074642400206075ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/.forgejo/workflows/000077500000000000000000000000001516074642400226445ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/.forgejo/workflows/ci.yml000066400000000000000000000030451516074642400237640ustar00rootroot00000000000000on: push: branches: - main pull_request: branches: - main jobs: test: runs-on: ubuntu-with-rust-1.89 steps: - name: Check out repository uses: actions/checkout@v4 - name: Cache build dependencies uses: actions/cache@v4 with: path: | ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}} lock ${{ hashFiles('**/Cargo.lock') }}" - name: Set up tree-sitter run: | if [ ! -e ~/.cargo/bin/tree-sitter ]; then cargo install tree-sitter-cli --version 0.25.5 --locked fi - name: Run tree-sitter generate run: tree-sitter generate --abi 14 - name: Run tests run: tree-sitter test - name: Set up examples run: |- git clone https://github.com/rust-lang-nursery/bitflags examples/bitflags --single-branch --depth=1 --filter=blob:none git clone https://github.com/rust-lang/regex examples/regex --single-branch --depth=1 --filter=blob:none git clone https://github.com/serde-rs/serde examples/serde --single-branch --depth=1 --filter=blob:none git clone https://github.com/tokio-rs/tokio examples/tokio --single-branch --depth=1 --filter=blob:none - name: Check that the examples parse uses: https://github.com/tree-sitter/parse-action@v3 with: files: examples/**/*.rs tree-sitter-rust-orchard-0.16.3+ds/.forgejo/workflows/release.yml000066400000000000000000000062761516074642400250220ustar00rootroot00000000000000on: push: tags: '*' jobs: release: runs-on: ubuntu-with-rust-1.89 steps: - name: Check out repository uses: actions/checkout@v4 with: fetch-depth: 0 # for changelog generation fetch-tags: true # for changelog generation - name: Cache build dependencies uses: actions/cache@v4 with: path: | ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}} lock ${{ hashFiles('**/Cargo.lock') }}" - name: Set up tree-sitter and git-cliff run: | if [ ! -e ~/.cargo/bin/tree-sitter ]; then cargo install tree-sitter-cli --version 0.25.5 --locked fi - name: Run tree-sitter generate run: tree-sitter generate --abi 14 - name: Run tests run: tree-sitter test - name: Generate release notes run: | { echo 'RELEASE_NOTES<> "$GITHUB_ENV" - name: Create release archive run: | export GRAMMAR_NAME=$(jq -r ".grammars[0].name" < tree-sitter.json) export GRAMMAR_VERSION=$(jq -r ".metadata.version" < tree-sitter.json) mkdir release_artifacts tar -zc --exclude-vcs --exclude "release_artifacts*" . -f release_artifacts/${GRAMMAR_NAME}_${GRAMMAR_VERSION}_generated.tar.gz - name: Create release uses: https://code.forgejo.org/actions/forgejo-release@v2.7.3 with: direction: upload token: ${{ secrets.CODEBERG_WRITE_TOKEN }} tag: "${{ github.ref_name }}" sha: "${{ github.sha }}" release-dir: ./release_artifacts release-notes: ${{ env.RELEASE_NOTES }} override: true # Crates.io publishing - name: Login on crates.io run: echo "${{ secrets.CRATES_IO_API_TOKEN }}" | cargo login - name: Publish on crates.io run: cargo publish --allow-dirty # PyPI publishing - name: Install Python dependencies run: pip install --break-system-packages build setuptools twine - name: Build Python package run: | python -m build -n -s # Workaround to adapt the name of the generated sdist to something that PyPI accepts export ORIG_SDIST_NAME=$(ls dist | grep .tar.gz) mv dist/${ORIG_SDIST_NAME} . export NEW_SDIST_NAME=$(echo "${ORIG_SDIST_NAME}" | sed -e 's/-\([^0-9]\)/_\1/g') mv ${ORIG_SDIST_NAME} dist/${NEW_SDIST_NAME} - name: Publish to PyPI run: twine upload dist/* env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} # NPM publishing - name: Install emscripten run: | apt-get update apt-get install -y emscripten - name: Publish on npm run: | echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc tree-sitter build --wasm npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_API_TOKEN }} tree-sitter-rust-orchard-0.16.3+ds/.gitattributes000066400000000000000000000015361516074642400217760ustar00rootroot00000000000000* text=auto eol=lf # Generated source files src/*.json linguist-generated src/parser.c linguist-generated src/tree_sitter/* linguist-generated # C bindings bindings/c/* linguist-generated CMakeLists.txt linguist-generated Makefile linguist-generated # Rust bindings bindings/rust/* linguist-generated Cargo.toml linguist-generated Cargo.lock linguist-generated # Node.js bindings bindings/node/* linguist-generated binding.gyp linguist-generated package.json linguist-generated package-lock.json linguist-generated # Python bindings bindings/python/** linguist-generated setup.py linguist-generated pyproject.toml linguist-generated # Go bindings bindings/go/* linguist-generated go.mod linguist-generated go.sum linguist-generated # Swift bindings bindings/swift/** linguist-generated Package.swift linguist-generated Package.resolved linguist-generated tree-sitter-rust-orchard-0.16.3+ds/.gitignore000066400000000000000000000006071516074642400210710ustar00rootroot00000000000000# Tree-sitter artifacts src/parser.c src/*.json src/tree_sitter/ # Rust artifacts target/ # Node artifacts build/ prebuilds/ node_modules/ # Swift artifacts .build/ # Go artifacts _obj/ # Python artifacts .venv/ dist/ *.egg-info *.whl # C artifacts *.a *.so *.so.* *.dylib *.dll *.pc # Example dirs /examples/*/ # Grammar volatiles *.wasm *.obj *.o # Archives *.tar.gz *.tgz *.zip tree-sitter-rust-orchard-0.16.3+ds/CMakeLists.txt000066400000000000000000000056011516074642400216400ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.13) project(tree-sitter-rust-orchard VERSION "0.16.3" DESCRIPTION "Grammar for Rust that aims to be closer to the actual AST" HOMEPAGE_URL "https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard" LANGUAGES C) option(BUILD_SHARED_LIBS "Build using shared libraries" ON) option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) set(TREE_SITTER_ABI_VERSION 15 CACHE STRING "Tree-sitter ABI version") if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") unset(TREE_SITTER_ABI_VERSION CACHE) message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") endif() find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json --abi=${TREE_SITTER_ABI_VERSION} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating parser.c") add_library(tree-sitter-rust-orchard src/parser.c) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) target_sources(tree-sitter-rust-orchard PRIVATE src/scanner.c) endif() target_include_directories(tree-sitter-rust-orchard PRIVATE src INTERFACE $ $) target_compile_definitions(tree-sitter-rust-orchard PRIVATE $<$:TREE_SITTER_REUSE_ALLOCATOR> $<$:TREE_SITTER_DEBUG>) set_target_properties(tree-sitter-rust-orchard PROPERTIES C_STANDARD 11 POSITION_INDEPENDENT_CODE ON SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" DEFINE_SYMBOL "") configure_file(bindings/c/tree-sitter-rust-orchard.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-rust-orchard.pc" @ONLY) include(GNUInstallDirs) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-rust-orchard.pc" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") install(TARGETS tree-sitter-rust-orchard LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") file(GLOB QUERIES queries/*.scm) install(FILES ${QUERIES} DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/rust-orchard") add_custom_target(ts-test "${TREE_SITTER_CLI}" test WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "tree-sitter test") tree-sitter-rust-orchard-0.16.3+ds/CONTRIBUTING.md000066400000000000000000000001221516074642400213220ustar00rootroot00000000000000See https://codeberg.org/grammar-orchard/.profile/src/branch/main/CONTRIBUTING.md tree-sitter-rust-orchard-0.16.3+ds/Cargo.lock000066400000000000000000000130021516074642400207770ustar00rootroot00000000000000# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "aho-corasick" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] [[package]] name = "cc" version = "1.2.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" dependencies = [ "find-msvc-tools", "shlex", ] [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "indexmap" version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "memchr" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "proc-macro2" version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "regex" version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "serde" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", ] [[package]] name = "serde_core" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "indexmap", "itoa", "memchr", "serde", "serde_core", "zmij", ] [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "streaming-iterator" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" [[package]] name = "syn" version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tree-sitter" version = "0.25.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78f873475d258561b06f1c595d93308a7ed124d9977cb26b148c2084a4a3cc87" dependencies = [ "cc", "regex", "regex-syntax", "serde_json", "streaming-iterator", "tree-sitter-language", ] [[package]] name = "tree-sitter-language" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "009994f150cc0cd50ff54917d5bc8bffe8cad10ca10d81c34da2ec421ae61782" [[package]] name = "tree-sitter-rust-orchard" version = "0.16.3" dependencies = [ "cc", "tree-sitter", "tree-sitter-language", ] [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" tree-sitter-rust-orchard-0.16.3+ds/Cargo.toml000066400000000000000000000014751516074642400210350ustar00rootroot00000000000000[package] name = "tree-sitter-rust-orchard" description = "Grammar for Rust that aims to be closer to the actual AST" version = "0.16.3" authors = [ "Max Brunsfeld ", "Amaan Qureshi ", ] license = "MIT" readme = "README.md" keywords = ["incremental", "parsing", "tree-sitter", "rust-orchard"] categories = ["parser-implementations", "parsing", "text-editors"] repository = "https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard" edition = "2021" autoexamples = false build = "bindings/rust/build.rs" include = [ "bindings/rust/*", "grammar.js", "queries/*", "src/*", "tree-sitter.json", "LICENSE", ] [lib] path = "bindings/rust/lib.rs" [dependencies] tree-sitter-language = "0.1" [build-dependencies] cc = "1.2" [dev-dependencies] tree-sitter = "0.25.5" tree-sitter-rust-orchard-0.16.3+ds/GOVERNANCE.md000066400000000000000000000001201516074642400210400ustar00rootroot00000000000000See https://codeberg.org/grammar-orchard/.profile/src/branch/main/GOVERNANCE.md tree-sitter-rust-orchard-0.16.3+ds/LICENSE000066400000000000000000000020701516074642400201020ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2017 Maxim Sokolov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tree-sitter-rust-orchard-0.16.3+ds/Makefile000066400000000000000000000066401516074642400205440ustar00rootroot00000000000000ifeq ($(OS),Windows_NT) $(error Windows is not supported) endif LANGUAGE_NAME := tree-sitter-rust-orchard HOMEPAGE_URL := https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard VERSION := 0.16.3 # repository SRC_DIR := src TS ?= tree-sitter # install directory layout PREFIX ?= /usr/local DATADIR ?= $(PREFIX)/share INCLUDEDIR ?= $(PREFIX)/include LIBDIR ?= $(PREFIX)/lib PCLIBDIR ?= $(LIBDIR)/pkgconfig # source/object files PARSER := $(SRC_DIR)/parser.c EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) # flags ARFLAGS ?= rcs override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC # ABI versioning SONAME_MAJOR = $(shell sed -n 's/\#define LANGUAGE_VERSION //p' $(PARSER)) SONAME_MINOR = $(word 1,$(subst ., ,$(VERSION))) # OS-specific bits ifeq ($(shell uname),Darwin) SOEXT = dylib SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT) SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT) LINKSHARED = -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks else SOEXT = so SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR) SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR) LINKSHARED = -shared -Wl,-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) endif ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) PCLIBDIR := $(PREFIX)/libdata/pkgconfig endif all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a: $(OBJS) $(AR) $(ARFLAGS) $@ $^ lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ ifneq ($(STRIP),) $(STRIP) $@ endif $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \ -e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \ -e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR:$(PREFIX)/%=%)|' \ -e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \ -e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \ -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@ $(PARSER): $(SRC_DIR)/grammar.json $(TS) generate $^ install: all install -d '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/rust-orchard '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) ifneq ($(wildcard queries/*.scm),) install -m644 queries/*.scm '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/rust-orchard endif uninstall: $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc $(RM) -r '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/rust-orchard clean: $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) test: $(TS) test .PHONY: all install uninstall clean test tree-sitter-rust-orchard-0.16.3+ds/Package.resolved000066400000000000000000000005151516074642400221770ustar00rootroot00000000000000{ "object": { "pins": [ { "package": "SwiftTreeSitter", "repositoryURL": "https://github.com/ChimeHQ/SwiftTreeSitter", "state": { "branch": null, "revision": "2599e95310b3159641469d8a21baf2d3d200e61f", "version": "0.8.0" } } ] }, "version": 1 } tree-sitter-rust-orchard-0.16.3+ds/Package.swift000066400000000000000000000021451516074642400215110ustar00rootroot00000000000000// swift-tools-version:5.3 import Foundation import PackageDescription var sources = ["src/parser.c"] if FileManager.default.fileExists(atPath: "src/scanner.c") { sources.append("src/scanner.c") } let package = Package( name: "TreeSitterRustOrchard", products: [ .library(name: "TreeSitterRustOrchard", targets: ["TreeSitterRustOrchard"]), ], dependencies: [ .package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.8.0"), ], targets: [ .target( name: "TreeSitterRustOrchard", dependencies: [], path: ".", sources: sources, resources: [ .copy("queries") ], publicHeadersPath: "bindings/swift", cSettings: [.headerSearchPath("src")] ), .testTarget( name: "TreeSitterRustOrchardTests", dependencies: [ "SwiftTreeSitter", "TreeSitterRustOrchard", ], path: "bindings/swift/TreeSitterRustOrchardTests" ) ], cLanguageStandard: .c11 ) tree-sitter-rust-orchard-0.16.3+ds/README.md000066400000000000000000000021171516074642400203560ustar00rootroot00000000000000# tree-sitter-rust-orchard [![crates][crates]](https://crates.io/crates/tree-sitter-rust-orchard) [![pypi][pypi]](https://pypi.org/project/tree-sitter-rust-orchard) [![npm][npm]](https://www.npmjs.com/package/tree-sitter-rust-orchard) This is a fork of the [tree-sitter-rust](https://github.com/tree-sitter/tree-sitter-rust) grammar. It focuses on: - faithfulness of the produced trees with the semantics of Rust - ability to parse Rust files with recent syntactic constructs - proactive reviewing of contributions and onboarding of their authors into the project, via the [governance model](https://codeberg.org/grammar-orchard/.profile/src/branch/main/GOVERNANCE.md) Note that unlike upstream, generated files are not checked into git, so you need to run `tree-sitter generate` after cloning this repository. Contributions are welcome, so are co-maintainers. [crates]: https://img.shields.io/crates/v/tree-sitter-rust-orchard?logo=rust [pypi]: https://img.shields.io/pypi/v/tree-sitter-rust-orchard?logo=pypi&logoColor=ffd242 [npm]: https://img.shields.io/npm/v/tree-sitter-rust-orchard?logo=npm tree-sitter-rust-orchard-0.16.3+ds/binding.gyp000066400000000000000000000014031516074642400212270ustar00rootroot00000000000000{ "targets": [ { "target_name": "tree_sitter_rust_orchard_binding", "dependencies": [ " typedef struct TSLanguage TSLanguage; extern "C" TSLanguage *tree_sitter_rust_orchard(); // "tree-sitter", "language" hashed with BLAKE2 const napi_type_tag LANGUAGE_TYPE_TAG = { 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 }; Napi::Object Init(Napi::Env env, Napi::Object exports) { auto language = Napi::External::New(env, tree_sitter_rust_orchard()); language.TypeTag(&LANGUAGE_TYPE_TAG); exports["language"] = language; return exports; } NODE_API_MODULE(tree_sitter_rust_orchard_binding, Init) tree-sitter-rust-orchard-0.16.3+ds/bindings/node/binding_test.js000066400000000000000000000003721516074642400246310ustar00rootroot00000000000000const assert = require("node:assert"); const { test } = require("node:test"); const Parser = require("tree-sitter"); test("can load grammar", () => { const parser = new Parser(); assert.doesNotThrow(() => parser.setLanguage(require("."))); }); tree-sitter-rust-orchard-0.16.3+ds/bindings/node/index.d.ts000066400000000000000000000006641516074642400235270ustar00rootroot00000000000000type BaseNode = { type: string; named: boolean; }; type ChildNode = { multiple: boolean; required: boolean; types: BaseNode[]; }; type NodeInfo = | (BaseNode & { subtypes: BaseNode[]; }) | (BaseNode & { fields: { [name: string]: ChildNode }; children: ChildNode[]; }); type Language = { language: unknown; nodeTypeInfo: NodeInfo[]; }; declare const language: Language; export = language; tree-sitter-rust-orchard-0.16.3+ds/bindings/node/index.js000066400000000000000000000007151516074642400232700ustar00rootroot00000000000000const root = require("path").join(__dirname, "..", ".."); module.exports = typeof process.versions.bun === "string" // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time ? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-rust-orchard.node`) : require("node-gyp-build")(root); try { module.exports.nodeTypeInfo = require("../../src/node-types.json"); } catch (_) {} tree-sitter-rust-orchard-0.16.3+ds/bindings/python/000077500000000000000000000000001516074642400222145ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tests/000077500000000000000000000000001516074642400233565ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tests/test_binding.py000066400000000000000000000004701516074642400264020ustar00rootroot00000000000000from unittest import TestCase import tree_sitter import tree_sitter_rust_orchard class TestLanguage(TestCase): def test_can_load_grammar(self): try: tree_sitter.Language(tree_sitter_rust_orchard.language()) except Exception: self.fail("Error loading Rust grammar") tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tree_sitter_rust_orchard/000077500000000000000000000000001516074642400273245ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tree_sitter_rust_orchard/__init__.py000066400000000000000000000022361516074642400314400ustar00rootroot00000000000000"""Grammar for Rust that aims to be closer to the actual AST""" from importlib.resources import files as _files from ._binding import language def _get_query(name, file): query = _files(f"{__package__}.queries") / file globals()[name] = query.read_text() return globals()[name] def __getattr__(name): # NOTE: uncomment these to include any queries that this grammar contains: # if name == "HIGHLIGHTS_QUERY": # return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") # if name == "INJECTIONS_QUERY": # return _get_query("INJECTIONS_QUERY", "injections.scm") # if name == "LOCALS_QUERY": # return _get_query("LOCALS_QUERY", "locals.scm") # if name == "TAGS_QUERY": # return _get_query("TAGS_QUERY", "tags.scm") raise AttributeError(f"module {__name__!r} has no attribute {name!r}") __all__ = [ "language", # "HIGHLIGHTS_QUERY", # "INJECTIONS_QUERY", # "LOCALS_QUERY", # "TAGS_QUERY", ] def __dir__(): return sorted(__all__ + [ "__all__", "__builtins__", "__cached__", "__doc__", "__file__", "__loader__", "__name__", "__package__", "__path__", "__spec__", ]) tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tree_sitter_rust_orchard/__init__.pyi000066400000000000000000000003671516074642400316140ustar00rootroot00000000000000from typing import Final # NOTE: uncomment these to include any queries that this grammar contains: # HIGHLIGHTS_QUERY: Final[str] # INJECTIONS_QUERY: Final[str] # LOCALS_QUERY: Final[str] # TAGS_QUERY: Final[str] def language() -> object: ... tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tree_sitter_rust_orchard/binding.c000066400000000000000000000015201516074642400311000ustar00rootroot00000000000000#include typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_rust_orchard(void); static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { return PyCapsule_New(tree_sitter_rust_orchard(), "tree_sitter.Language", NULL); } static struct PyModuleDef_Slot slots[] = { #ifdef Py_GIL_DISABLED {Py_mod_gil, Py_MOD_GIL_NOT_USED}, #endif {0, NULL} }; static PyMethodDef methods[] = { {"language", _binding_language, METH_NOARGS, "Get the tree-sitter language for this grammar."}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef module = { .m_base = PyModuleDef_HEAD_INIT, .m_name = "_binding", .m_doc = NULL, .m_size = 0, .m_methods = methods, .m_slots = slots, }; PyMODINIT_FUNC PyInit__binding(void) { return PyModuleDef_Init(&module); } tree-sitter-rust-orchard-0.16.3+ds/bindings/python/tree_sitter_rust_orchard/py.typed000066400000000000000000000000001516074642400310110ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/rust/000077500000000000000000000000001516074642400216705ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/rust/build.rs000066400000000000000000000011531516074642400233350ustar00rootroot00000000000000fn main() { let src_dir = std::path::Path::new("src"); let mut c_config = cc::Build::new(); c_config.std("c11").include(src_dir); #[cfg(target_env = "msvc")] c_config.flag("-utf-8"); let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); let scanner_path = src_dir.join("scanner.c"); if scanner_path.exists() { c_config.file(&scanner_path); println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); } c_config.compile("tree-sitter-rust-orchard"); } tree-sitter-rust-orchard-0.16.3+ds/bindings/rust/lib.rs000066400000000000000000000035441516074642400230120ustar00rootroot00000000000000//! This crate provides Rust language support for the [tree-sitter][] parsing library. //! //! Typically, you will use the [`LANGUAGE`] constant to add this language to a //! tree-sitter [`Parser`], and then use the parser to parse some code: //! //! ``` //! let code = r#" //! fn double(x: i32) -> i32 { //! x * 2 //! } //! "#; //! let mut parser = tree_sitter::Parser::new(); //! let language = tree_sitter_rust_orchard::LANGUAGE; //! parser //! .set_language(&language.into()) //! .expect("Error loading Rust parser"); //! let tree = parser.parse(code, None).unwrap(); //! assert!(!tree.root_node().has_error()); //! ``` //! //! [`Parser`]: https://docs.rs/tree-sitter/0.25.5/tree_sitter/struct.Parser.html //! [tree-sitter]: https://tree-sitter.github.io/ use tree_sitter_language::LanguageFn; extern "C" { fn tree_sitter_rust_orchard() -> *const (); } /// The tree-sitter [`LanguageFn`] for this grammar. pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_rust_orchard) }; /// The content of the [`node-types.json`] file for this grammar. /// /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); /// The syntax highlighting query for this language. pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); /// The injections query for this language. pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); /// The symbol tagging query for this language. pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { #[test] fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser .set_language(&super::LANGUAGE.into()) .expect("Error loading Rust parser"); } } tree-sitter-rust-orchard-0.16.3+ds/bindings/swift/000077500000000000000000000000001516074642400220275ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/swift/TreeSitterRustOrchard/000077500000000000000000000000001516074642400263025ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/swift/TreeSitterRustOrchard/rust_orchard.h000066400000000000000000000004161516074642400311530ustar00rootroot00000000000000#ifndef TREE_SITTER_RUST_ORCHARD_H_ #define TREE_SITTER_RUST_ORCHARD_H_ typedef struct TSLanguage TSLanguage; #ifdef __cplusplus extern "C" { #endif const TSLanguage *tree_sitter_rust_orchard(void); #ifdef __cplusplus } #endif #endif // TREE_SITTER_RUST_ORCHARD_H_ tree-sitter-rust-orchard-0.16.3+ds/bindings/swift/TreeSitterRustOrchardTests/000077500000000000000000000000001516074642400273255ustar00rootroot00000000000000TreeSitterRustOrchardTests.swift000066400000000000000000000005751516074642400356310ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/bindings/swift/TreeSitterRustOrchardTestsimport XCTest import SwiftTreeSitter import TreeSitterRustOrchard final class TreeSitterRustOrchardTests: XCTestCase { func testCanLoadGrammar() throws { let parser = Parser() let language = Language(language: tree_sitter_rust_orchard()) XCTAssertNoThrow(try parser.setLanguage(language), "Error loading Rust grammar") } } tree-sitter-rust-orchard-0.16.3+ds/cliff.toml000066400000000000000000000105331516074642400210600ustar00rootroot00000000000000# git-cliff ~ configuration file # https://git-cliff.org/docs/configuration [changelog] # A Tera template to be rendered as the changelog's footer. # See https://keats.github.io/tera/docs/#introduction header = """ """ # A Tera template to be rendered for each release in the changelog. # See https://keats.github.io/tera/docs/#introduction body = """ {% for group, commits in commits | group_by(attribute="group") %} ### {{ group | striptags | trim | upper_first }} {% for commit in commits %} - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ {% if commit.breaking %}[**breaking**] {% endif %}\ {{ commit.message | upper_first }}\ {% if commit.remote.username %} by @{{ commit.remote.username }}{% else %} ({{ commit.id }}){%- endif %}\ {% endfor %} {% endfor %}\n """ # A Tera template to be rendered as the changelog's footer. # See https://keats.github.io/tera/docs/#introduction footer = """ """ # Remove leading and trailing whitespaces from the changelog's body. trim = true # Render body even when there are no releases to process. render_always = true # An array of regex based postprocessors to modify the changelog. postprocessors = [ # Replace the placeholder with a URL. #{ pattern = '', replace = "https://github.com/orhun/git-cliff" }, ] # render body even when there are no releases to process # render_always = true # output file path # output = "test.md" [git] # Parse commits according to the conventional commits specification. # See https://www.conventionalcommits.org conventional_commits = true # Exclude commits that do not match the conventional commits specification. filter_unconventional = true # Require all commits to be conventional. # Takes precedence over filter_unconventional. require_conventional = false # Split commits on newlines, treating each line as an individual commit. split_commits = false # An array of regex based parsers to modify commit messages prior to further processing. commit_preprocessors = [ # Replace issue numbers with link templates to be updated in `changelog.postprocessors`. #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, # Check spelling of the commit message using https://github.com/crate-ci/typos. # If the spelling is incorrect, it will be fixed automatically. #{ pattern = '.*', replace_command = 'typos --write-changes -' }, ] # Prevent commits that are breaking from being excluded by commit parsers. protect_breaking_commits = false # An array of regex based parsers for extracting data from the commit message. # Assigns commits to groups. # Optionally sets the commit's scope and can decide to exclude commits from further processing. commit_parsers = [ { message = "^feat", group = "🚀 Features" }, { message = "^fix", group = "🐛 Bug Fixes" }, { message = "^doc", group = "📚 Documentation" }, { message = "^perf", group = "⚡ Performance" }, { message = "^refactor", group = "🚜 Refactor" }, { message = "^style", group = "🎨 Styling" }, { message = "^test", group = "🧪 Testing" }, { message = "^chore\\(release\\): prepare for", skip = true }, { message = "^chore\\(deps.*\\)", skip = true }, { message = "^chore\\(pr\\)", skip = true }, { message = "^chore\\(pull\\)", skip = true }, { message = "^chore|^ci", group = "⚙️ Miscellaneous Tasks" }, { body = ".*security", group = "🛡️ Security" }, { message = "^revert", group = "◀️ Revert" }, { message = ".*", group = "💼 Other" }, ] # Exclude commits that are not matched by any commit parser. filter_commits = false # An array of link parsers for extracting external references, and turning them into URLs, using regex. link_parsers = [] # Include only the tags that belong to the current branch. use_branch_tags = false # Order releases topologically instead of chronologically. topo_order = false # Order releases topologically instead of chronologically. topo_order_commits = true # Order of commits in each group/release within the changelog. # Allowed values: newest, oldest sort_commits = "oldest" # Process submodules commits recurse_submodules = false [remote.gitea] owner = "grammar-orchard" repo = "tree-sitter-rust-orchard" tree-sitter-rust-orchard-0.16.3+ds/eslint.config.mjs000066400000000000000000000001311516074642400223460ustar00rootroot00000000000000import treesitter from 'eslint-config-treesitter'; export default [ ...treesitter, ]; tree-sitter-rust-orchard-0.16.3+ds/go.mod000066400000000000000000000001751516074642400202070ustar00rootroot00000000000000module codeberg.org/grammar-orchard/tree-sitter-rust-orchard go 1.22 require github.com/tree-sitter/go-tree-sitter v0.24.0 tree-sitter-rust-orchard-0.16.3+ds/go.sum000066400000000000000000000075151516074642400202410ustar00rootroot00000000000000github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0= github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tree-sitter/go-tree-sitter v0.24.0 h1:kRZb6aBNfcI/u0Qh8XEt3zjNVnmxTisDBN+kXK0xRYQ= github.com/tree-sitter/go-tree-sitter v0.24.0/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk= github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb h1:A8425heRM8mylnv4H58FPUiH+aYivyitre0PzxrfmWs= github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb/go.mod h1:dOF6gtQiF9UwNh995T5OphYmtIypkjsp3ap7r9AN/iA= github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148 h1:AfFPZwtwGN01BW1jDdqBVqscTwetvMpydqYZz57RSlc= github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148/go.mod h1:Bh6U3viD57rFXRYIQ+kmiYtr+1Bx0AceypDLJJSyi9s= github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33 h1:TwqSV3qLp3tKSqirGLRHnjFk9Tc2oy57LIl+FQ4GjI4= github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33/go.mod h1:CvCKCt3v04Ufos1zZnNCelBDeCGRpPucaN8QczoUsN4= github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012 h1:Xvxck3tE5FW7F7bTS97iNM2ADMyCMJztVqn5HYKdJGo= github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012/go.mod h1:T40D0O1cPvUU/+AmiXVXy1cncYQT6wem4Z0g4SfAYvY= github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0 h1:c46K6uh5Dz00zJeU9BfjXdb8I+E4RkUdfnWJpQADXFo= github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0/go.mod h1:hcNt/kOJHcIcuMvouE7LJcYdeFUFbVpBJ6d4wmOA+tU= github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495 h1:jrt4qbJVEFs4H93/ITxygHc6u0TGqAkkate7TQ4wFSA= github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495/go.mod h1:oyaR7fLnRV0hT9z6qwE9GkaeTom/hTDwK3H2idcOJFc= github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5 h1:om4X9AVg3asL8gxNJDcz4e/Wp+VpQj1PY3uJXKr6EOg= github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5/go.mod h1:nNqgPoV/h9uYWk6kYEFdEAhNVOacpfpRW5SFmdaP4tU= github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5 h1:pfV3G3k7NCKqKk8THBmyuh2zA33lgYHS3GVrzRR8ry4= github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5/go.mod h1:GbMKRjLfk0H+PI7nLi1Sx5lHf5wCpLz9al8tQYSxpEk= github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1 h1:ZXZMDwE+IhUtGug4Brv6NjJWUU3rfkZBKpemf6RY8/g= github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1/go.mod h1:UKCLuYnJ312Mei+3cyTmGOHzn0YAnaPRECgJmHtzrqs= github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb h1:EXEM82lFM7JjJb6qiKZXkpIDaCcbV2obNn82ghwj9lw= github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb/go.mod h1:lXCF1nGG5Dr4J3BTS0ObN4xJCCICiSu/b+Xe/VqMV7g= github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d h1:fcYCvoXdcP1uRQYXqJHRy6Hec+uKScQdKVtMwK9JeCI= github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d/go.mod h1:T1nShQ4v5AJtozZ8YyAS4uzUtDAJj/iv4YfwXSbUHzg= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= tree-sitter-rust-orchard-0.16.3+ds/grammar.js000066400000000000000000001255621516074642400210750ustar00rootroot00000000000000/** * @file Rust grammar for tree-sitter * @author Maxim Sokolov * @author Max Brunsfeld * @author Amaan Qureshi * @license MIT */ /// // @ts-check // https://doc.rust-lang.org/reference/expressions.html#expression-precedence const PREC = { call: 16, field: 15, try: 14, unary: 13, cast: 12, multiplicative: 11, additive: 10, shift: 9, bitand: 8, bitxor: 7, bitor: 6, comparative: 5, and: 4, or: 3, range: 2, attribute: 1, assign: 0, closure: -1, }; const numericTypes = [ 'u8', 'i8', 'u16', 'i16', 'u32', 'i32', 'u64', 'i64', 'u128', 'i128', 'isize', 'usize', 'f16', 'f32', 'f64', 'f128', ]; // https://doc.rust-lang.org/reference/tokens.html#punctuation const TOKEN_TREE_NON_SPECIAL_PUNCTUATION = [ '+', '-', '*', '/', '%', '^', '!', '&', '|', '&&', '||', '<<', '>>', '+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '<<=', '>>=', '=', '==', '!=', '>', '<', '>=', '<=', '@', '_', '.', '..', '...', '..=', ',', ';', ':', '::', '->', '=>', '#', '?', ]; const primitiveTypes = numericTypes.concat(['bool', 'str', 'char']); module.exports = grammar({ name: 'rust_orchard', extras: $ => [ /\s/, $.line_comment, $.block_comment, ], externals: $ => [ $.string_content, $._raw_string_literal_start, $.raw_string_literal_content, $._raw_string_literal_end, $.float_literal, $._outer_block_doc_comment_start, $._outer_line_doc_comment_start, $._inner_block_doc_comment_marker, $._block_comment_content, $._line_doc_content, $._frontmatter_start, $.frontmatter_content, $._frontmatter_end, $._error_sentinel, ], supertypes: $ => [ $._expression, $._type, $._literal, $._literal_pattern, $._declaration_statement, $._pattern, ], inline: $ => [ $._path, $._type_identifier, $._tokens, $._any_string_literal, $._field_identifier, $._field_identifier_or_index, $._non_special_token, $._reserved_identifier, $._expression_ending_with_block, $._expression_ending_with_block_without_attribute, ], conflicts: $ => [ // Local ambiguity due to anonymous types: // See https://internals.rust-lang.org/t/pre-rfc-deprecating-anonymous-parameters/3710 [$._type, $._pattern], [$.unit_type, $.tuple_pattern], [$.scoped_identifier, $.scoped_type_identifier], [$.parameters, $._pattern], [$.parameters, $.tuple_struct_pattern], [$.generic_type_with_turbofish, $.generic_pattern], [$.visibility_modifier], [$.visibility_modifier, $.scoped_identifier, $.scoped_type_identifier], [$.trait_bounds], // due to allowing empty bounds ], word: $ => $.identifier, rules: { source_file: $ => seq( optional($.shebang), optional($.frontmatter), repeat($._statement), ), _statement: $ => choice( $.expression_statement, $._declaration_statement, ), empty_statement: $ => seq( optional(field('attributes', $.attributes)), ';' ), expression_statement: $ => choice( seq($._expression, ';'), prec(1, $._expression_ending_with_block), ), _declaration_statement: $ => choice( $.const_item, $.macro_invocation_item, $.macro_definition, $.macro_definition_v2, $.empty_statement, $.inner_attribute_item, $.mod_item, $.foreign_mod_item, $.struct_item, $.union_item, $.enum_item, $.type_item, $.function_item, $.function_signature_item, $.impl_item, $.trait_item, $.let_declaration, $.use_declaration, $.extern_crate_declaration, $.static_item, ), // Section - Macro definitions macro_definition_v2: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'macro', field('name', choice($.identifier, $.metavariable)), choice( seq( field('arguments', $.macro_arguments_declaration), field('body', $.macro_body_v2) ), field('rules', $.macro_rules_v2) ) ), macro_arguments_declaration: $ => seq( '(', repeat($._token_pattern), ')', ), macro_body_v2: $ => seq( '{', repeat($._tokens), '}' ), macro_rules_v2: $ => seq( '{', sepBy(',', $.macro_rule_v2), '}' ), // this will accept '()', '[]' and '{}' for delimiters on the left and right, // whereas in v2 only '()' is legal on the left-hand side and '{}' on the right-hand side. // TODO: this could be made more restrictive macro_rule_v2: $ => seq( field('left', $.token_tree_pattern), '=>', field('right', $.token_tree), ), macro_definition: $ => { const rules = seq( repeat(seq($.macro_rule, ';')), optional($.macro_rule), ); return seq( optional(field('attributes', $.attributes)), 'macro_rules', '!', field('name', choice( $.identifier, $._reserved_identifier, )), choice( seq('(', rules, ')', ';'), seq('[', rules, ']', ';'), seq('{', rules, '}'), ), ); }, macro_rule: $ => seq( field('left', $.token_tree_pattern), '=>', field('right', $.token_tree), ), _token_pattern: $ => choice( $.token_tree_pattern, $.token_repetition_pattern, $.token_binding_pattern, $.metavariable, $._non_special_token, ), token_tree_pattern: $ => choice( seq('(', repeat($._token_pattern), ')'), seq('[', repeat($._token_pattern), ']'), seq('{', repeat($._token_pattern), '}'), ), token_binding_pattern: $ => prec(1, seq( field('name', $.metavariable), ':', field('type', $.fragment_specifier), )), token_repetition_pattern: $ => seq( '$', '(', repeat($._token_pattern), ')', optional(/[^+*?]+/), choice('+', '*', '?'), ), fragment_specifier: _ => choice( 'block', 'expr', 'expr_2021', 'ident', 'item', 'lifetime', 'literal', 'meta', 'pat', 'pat_param', 'path', 'stmt', 'tt', 'ty', 'vis', ), _tokens: $ => choice( $.token_tree, $.token_repetition, $.metavariable, $._non_special_token, prec(-1, '$'), ), token_tree: $ => choice( seq('(', repeat($._tokens), ')'), seq('[', repeat($._tokens), ']'), seq('{', repeat($._tokens), '}'), ), token_repetition: $ => seq( '$', '(', repeat($._tokens), ')', optional(/[^+*?]+/), choice('+', '*', '?'), ), primitive_type: $ => choice(...primitiveTypes), // Matches non-delimiter tokens common to both macro invocations and // definitions. This is everything except $ and metavariables (which begin // with $). _non_special_token: $ => choice( $._literal, $.identifier, $.mutable_specifier, $.self, $.super, $.crate, $.primitive_type, prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))), '\'', 'as', 'async', 'auto', 'await', 'become', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'gen', 'if', 'impl', 'let', 'loop', 'match', 'mod', 'pub', 'return', 'raw', 'static', 'struct', 'trait', 'type', 'union', 'unsafe', 'use', 'where', 'while', ), // Section - Declarations attribute_item: $ => seq( '#', '[', $.attribute, ']', ), attributes: $ => prec.left(-3, repeat1(choice( $.attribute_item, $.line_outer_doc_comment, $.block_outer_doc_comment, )) ), inner_attribute_item: $ => seq( optional(field('attributes', $.attributes)), '#', '!', '[', $.attribute, ']', ), attribute: $ => seq( $._path, optional(choice( seq('=', field('value', $._expression)), field('arguments', alias($.delim_token_tree, $.token_tree)), )), ), mod_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'mod', field('name', $.identifier), choice( ';', field('body', $.declaration_list), ), ), foreign_mod_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), optional($._item_modifiers), $.extern_modifier, choice( ';', field('body', $.declaration_list), ), ), declaration_list: $ => seq( '{', repeat($._declaration_statement), '}', ), struct_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'struct', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), choice( seq( optional($.where_clause), field('body', $.field_declaration_list), ), seq( field('body', $.ordered_field_declaration_list), optional($.where_clause), ';', ), seq( optional($.where_clause), ';', ), ), ), union_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'union', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), optional($.where_clause), field('body', $.field_declaration_list), ), enum_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'enum', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), optional($.where_clause), field('body', $.enum_variant_list), ), enum_variant_list: $ => seq( '{', sepBy(',', seq($.enum_variant)), optional(','), '}', ), enum_variant: $ => seq( optional($.attributes), optional($.visibility_modifier), field('name', $.identifier), field('body', optional(choice( $.field_declaration_list, $.ordered_field_declaration_list, ))), optional(seq( '=', field('value', $._expression), )), ), field_declaration_list: $ => seq( '{', sepBy(',', seq(optional($.attributes), $.field_declaration)), optional(','), '}', ), field_declaration: $ => seq( optional($.visibility_modifier), field('name', $._field_identifier), ':', field('type', $._type), ), ordered_field_declaration_list: $ => seq( '(', sepBy(',', seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), field('type', $._type), )), optional(','), ')', ), extern_crate_declaration: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'extern', $.crate, field('name', $.identifier), optional(seq( 'as', field('alias', $.identifier), )), ';', ), const_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'const', field('name', $.identifier), ':', field('type', $._type), optional( seq( '=', field('value', $._expression), ), ), ';', ), static_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), optional(choice('unsafe', 'safe')), 'static', // Not actual rust syntax, but made popular by the lazy_static crate. optional('ref'), optional($.mutable_specifier), field('name', $.identifier), ':', field('type', $._type), optional(seq( '=', field('value', $._expression), )), ';', ), type_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'type', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), field('bounds', optional($.trait_bounds)), optional($.where_clause), optional(seq( '=', field('type', $._type), )), optional($.where_clause), ';', ), function_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), optional($.function_modifiers), 'fn', field('name', choice($.identifier, $.metavariable)), field('type_parameters', optional($.type_parameters)), field('parameters', $.parameters), optional(seq('->', field('return_type', $._type))), optional($.where_clause), field('body', $.block), ), function_signature_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), optional($.function_modifiers), 'fn', field('name', choice($.identifier, $.metavariable)), field('type_parameters', optional($.type_parameters)), field('parameters', $.parameters), optional(seq('->', field('return_type', $._type))), optional($.where_clause), ';', ), function_modifiers: $ => choice( $._item_modifiers, $.extern_modifier, seq( $._item_modifiers, $.extern_modifier, ), ), _item_modifiers: _ => repeat1(choice( 'async', 'default', 'const', 'unsafe', 'gen', 'safe', )), where_clause: $ => prec.right(seq( 'where', optional(seq( sepBy1(',', $.where_predicate), optional(','), )), )), where_predicate: $ => seq( field('left', choice( $.lifetime, // TODO: should we just include `_type` here instead of listing all those variants? // quite some parse failures come from some particular kind of type needing to be added here… $._type_identifier, $.scoped_type_identifier, $.generic_type, $.reference_type, $.pointer_type, $.tuple_type, $.array_type, $.higher_ranked_trait_bound, $.dynamic_type, $.function_type, $.unit_type, $.primitive_type, )), field('bounds', $.trait_bounds), ), impl_item: $ => prec(1, seq( optional(field('attributes', $.attributes)), optional('unsafe'), 'impl', field('type_parameters', optional($.type_parameters)), optional(seq( optional('const'), optional('!'), field('trait', choice( $._type_identifier, $.scoped_type_identifier, $.generic_type, )), 'for', )), field('type', $._type), optional($.where_clause), choice(field('body', $.declaration_list), ';'), )), trait_item: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), optional('unsafe'), optional('auto'), 'trait', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), field('bounds', optional($.trait_bounds)), optional($.where_clause), choice( field('body', $.declaration_list), seq('=', field('alias_body', $._type), ';'), ), ), trait_bounds: $ => seq( ':', sepBy('+', choice( prec(1, seq( optional("~const"), optional("async"), optional("!"), $._type )), $.lifetime, )), ), higher_ranked_trait_bound: $ => seq( 'for', field('type_parameters', $.type_parameters), field('type', $._type), ), removed_trait_bound: $ => seq( '?', $._type, ), type_parameters: $ => prec(1, seq( '<', sepBy(',', seq( optional(field('attributes', $.attributes)), choice( $.metavariable, $.type_parameter, $.lifetime_parameter, $.const_parameter, ), )), optional(','), '>', )), const_parameter: $ => seq( 'const', field('name', $.identifier), ':', field('type', $._type), optional( seq( '=', field('value', choice( $.block, $.identifier, $._literal, $.negative_literal, ), ), ), ), ), type_parameter: $ => prec(1, seq( field('name', $._type_identifier), optional(field('bounds', $.trait_bounds)), optional( seq( '=', field('default_type', $._type), ), ), )), lifetime_parameter: $ => prec(1, seq( field('name', $.lifetime), optional(field('bounds', $.trait_bounds)), )), let_declaration: $ => seq( optional(field('attributes', $.attributes)), 'let', optional($.mutable_specifier), field('pattern', $._pattern), optional(seq( ':', field('type', $._type), )), optional(seq( '=', field('value', $._expression), )), optional(seq( 'else', field('alternative', $.block), )), ';', ), use_declaration: $ => seq( optional(field('attributes', $.attributes)), optional($.visibility_modifier), 'use', field('argument', $._use_clause), ';', ), _use_clause: $ => choice( $._path, $.use_as_clause, $.use_list, $.scoped_use_list, $.use_wildcard, ), scoped_use_list: $ => seq( field('path', optional($._path)), '::', field('list', $.use_list), ), use_list: $ => seq( '{', sepBy(',', choice( $._use_clause, )), optional(','), '}', ), use_as_clause: $ => seq( field('path', $._path), 'as', field('alias', $.identifier), ), use_wildcard: $ => seq( optional(seq(optional($._path), '::')), '*', ), parameters: $ => seq( '(', sepBy(',', seq( choice( $.parameter, $.self_parameter, $.variadic_parameter, '_', $._type, ))), optional(','), ')', ), self_parameter: $ => seq( optional(field('attributes', $.attributes)), optional('&'), optional($.lifetime), optional($.mutable_specifier), $.self, ), variadic_parameter: $ => seq( optional(field('attributes', $.attributes)), optional($.mutable_specifier), optional(seq( field('pattern', $._pattern), ':', )), '...', ), parameter: $ => seq( optional(field('attributes', $.attributes)), optional($.mutable_specifier), field('pattern', choice( $._pattern, $.self, )), ':', field('type', $._type), ), extern_modifier: $ => seq( 'extern', optional($._any_string_literal), ), visibility_modifier: $ => choice( $.crate, seq( 'pub', optional(seq( '(', choice( $.self, $.super, $.crate, seq('in', $._path), ), ')', )), ), ), // Section - Types _type: $ => choice( $.abstract_type, $.reference_type, $.metavariable, $.pointer_type, $.generic_type, $.generic_type_with_turbofish, $.scoped_type_identifier, $.tuple_type, $.unit_type, $.array_type, $.function_type, $.unsafe_bound_type, $._type_identifier, $.macro_invocation, $.never_type, $.dynamic_type, $.bounded_type, $.removed_trait_bound, $.higher_ranked_trait_bound, alias(choice(...primitiveTypes), $.primitive_type), ), bracketed_type: $ => seq( '<', choice( $._type, $.qualified_type, ), '>', ), qualified_type: $ => seq( field('type', $._type), 'as', field('alias', $._type), ), lifetime: $ => prec(1, seq('\'', $.identifier)), array_type: $ => seq( '[', field('element', $._type), optional(seq( ';', field('length', $._expression), )), ']', ), for_lifetimes: $ => seq( 'for', '<', sepBy1(',', $.lifetime), optional(','), '>', ), function_type: $ => seq( prec(PREC.call, seq( choice( field('trait', choice( $._type_identifier, $.scoped_type_identifier, )), seq( optional($.function_modifiers), 'fn', ), ), field('parameters', $.parameters), )), optional(seq('->', field('return_type', $._type))), ), unsafe_bound_type: $ => seq( 'unsafe', '<', sepBy1(',', $.lifetime), optional(','), '>', field('type', $._type) ), tuple_type: $ => seq( '(', sepBy1(',', $._type), optional(','), ')', ), unit_type: _ => seq('(', ')'), generic_function: $ => prec(1, seq( field('function', choice( $.identifier, $.scoped_identifier, $.field_expression, )), '::', field('type_arguments', $.type_arguments), )), generic_type: $ => prec(1, seq( field('type', choice( $._type_identifier, $._reserved_identifier, $.scoped_type_identifier, $.primitive_type, )), field('type_arguments', $.type_arguments), )), generic_type_with_turbofish: $ => seq( field('type', choice( $._type_identifier, $.scoped_identifier, )), '::', field('type_arguments', $.type_arguments), ), bounded_type: $ => prec.left(-1, seq( choice($.lifetime, $._type, $.use_bounds), '+', choice($.lifetime, $._type, $.use_bounds), )), use_bounds: $ => seq( 'use', token(prec(1, '<')), sepBy( ',', choice( $.lifetime, $._type_identifier, ), ), optional(','), '>', ), type_arguments: $ => seq( token(prec(1, '<')), sepBy(',', seq( choice( $._type, $.type_binding, $.lifetime, $._literal, $.negative_literal, $.block, ), optional($.trait_bounds), )), optional(','), '>', ), type_binding: $ => seq( field('name', $._type_identifier), field('type_arguments', optional($.type_arguments)), '=', field('type', $._type), ), reference_type: $ => seq( '&', optional($.lifetime), optional($.mutable_specifier), field('type', $._type), ), pointer_type: $ => seq( '*', choice('const', $.mutable_specifier), field('type', $._type), ), never_type: _ => '!', abstract_type: $ => seq( 'impl', optional(seq('for', $.type_parameters)), field('trait', prec(1, choice( $._type_identifier, $.scoped_type_identifier, $.removed_trait_bound, $.generic_type, $.function_type, $.unsafe_bound_type, $.tuple_type, $.bounded_type, ))), ), dynamic_type: $ => seq( 'dyn', field('trait', choice( $.higher_ranked_trait_bound, $._type_identifier, $.scoped_type_identifier, $.generic_type, $.function_type, $.unsafe_bound_type, $.tuple_type, $.lifetime, )), ), mutable_specifier: _ => 'mut', // Section - Expressions _expression_except_range: $ => choice( $.unary_expression, $.reference_expression, $.try_expression, $.binary_expression, $.assignment_expression, $.compound_assignment_expr, $.type_cast_expression, $.call_expression, $.return_expression, $.become_expression, $.yield_expression, $._literal, prec.left($.identifier), alias(choice(...primitiveTypes), $.identifier), prec.left($._reserved_identifier), $.self, $.scoped_identifier, $.generic_function, $.await_expression, $.field_expression, $.array_expression, $.tuple_expression, prec(1, $.macro_invocation), $.unit_expression, $.break_expression, $.continue_expression, $.index_expression, $.metavariable, $.closure_expression, $.parenthesized_expression, $.struct_expression, $._expression_ending_with_block_without_attribute, ), _expression: $ => choice( $._expression_without_attribute, $.expression_with_attribute, ), expression_with_attribute: $ => prec(PREC.attribute, seq( field('attributes', $.attributes), field('expression', $._expression_without_attribute), ) ), _expression_without_attribute: $ => choice( $._expression_except_range, $.range_expression, ), _expression_ending_with_block_without_attribute: $ => choice( $.unsafe_block, $.async_block, $.gen_block, $.try_block, $.block, $.if_expression, $.match_expression, $.while_expression, $.loop_expression, $.for_expression, $.const_block, ), block_expression_with_attribute: $ => prec(PREC.attribute, seq( field('attributes', $.attributes), field('expression', $._expression_ending_with_block_without_attribute), ) ), _expression_ending_with_block: $ => choice( $._expression_ending_with_block_without_attribute, $.block_expression_with_attribute, ), macro_invocation_item: $ => seq( optional(field('attributes', $.attributes)), field('invocation', $.macro_invocation) ), macro_invocation: $ => seq( field('macro', choice( $.scoped_identifier, $.identifier, $._reserved_identifier, )), '!', alias($.delim_token_tree, $.token_tree), ), delim_token_tree: $ => choice( seq('(', repeat($._delim_tokens), ')'), seq('[', repeat($._delim_tokens), ']'), seq('{', repeat($._delim_tokens), '}'), ), _delim_tokens: $ => choice( $._non_delim_token, alias($.delim_token_tree, $.token_tree), ), // Should match any token other than a delimiter. _non_delim_token: $ => choice( $._non_special_token, '$', ), scoped_identifier: $ => seq( field('path', optional(choice( $._path, $.bracketed_type, alias($.generic_type_with_turbofish, $.generic_type), ))), '::', field('name', choice($.identifier, $.super)), ), scoped_type_identifier_in_expression_position: $ => prec(-2, seq( field('path', optional(choice( $._path, alias($.generic_type_with_turbofish, $.generic_type), ))), '::', field('name', $._type_identifier), )), scoped_type_identifier: $ => seq( field('path', optional(choice( $._path, alias($.generic_type_with_turbofish, $.generic_type), $.bracketed_type, $.generic_type, ))), '::', field('name', $._type_identifier), ), range_expression: $ => choice( prec.left(PREC.range, seq($._expression, choice('..', '...', '..='), $._expression)), prec.left(PREC.range, seq($._expression, '..')), prec.right(PREC.range + 1, seq('..', $._expression)), prec.left(PREC.range, '..'), ), unary_expression: $ => prec(PREC.unary, seq( choice('-', '*', '!'), $._expression, )), try_expression: $ => prec(PREC.try, seq( $._expression, '?', )), reference_expression: $ => prec(PREC.unary, seq( '&', choice( seq('raw', choice('const', $.mutable_specifier)), optional($.mutable_specifier), ), field('value', $._expression), )), binary_expression: $ => { const table = [ [PREC.and, '&&'], [PREC.or, '||'], [PREC.bitand, '&'], [PREC.bitor, '|'], [PREC.bitxor, '^'], [PREC.comparative, choice('==', '!=', '<', '<=', '>', '>=')], [PREC.shift, choice('<<', '>>')], [PREC.additive, choice('+', '-')], [PREC.multiplicative, choice('*', '/', '%')], ]; // @ts-ignore return choice(...table.map(([precedence, operator]) => prec.left(precedence, seq( field('left', $._expression), // @ts-ignore field('operator', operator), field('right', $._expression), )))); }, assignment_expression: $ => prec.left(PREC.assign, seq( field('left', $._expression), '=', field('right', $._expression), )), compound_assignment_expr: $ => prec.left(PREC.assign, seq( field('left', $._expression), field('operator', choice('+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=')), field('right', $._expression), )), type_cast_expression: $ => prec.left(PREC.cast, seq( field('value', $._expression), 'as', field('type', $._type), )), return_expression: $ => choice( prec.left(seq('return', $._expression)), prec(-1, 'return'), ), become_expression: $ => prec.left(seq('become', $._expression)), yield_expression: $ => choice( prec.left(seq('yield', $._expression)), prec(-1, 'yield'), ), call_expression: $ => prec(PREC.call, seq( field('function', $._expression_except_range), field('arguments', $.arguments), )), arguments: $ => seq( '(', sepBy(',', $._expression), optional(','), ')', ), array_expression: $ => seq( '[', optional($.attributes), choice( seq( $._expression, ';', field('length', $._expression), ), seq( sepBy(',', seq(optional($.attributes), $._expression)), optional(','), ), ), ']', ), parenthesized_expression: $ => seq( '(', $._expression, ')', ), tuple_expression: $ => seq( '(', optional($.attributes), seq($._expression, ','), repeat(seq($._expression, ',')), optional($._expression), ')', ), unit_expression: _ => seq('(', ')'), struct_expression: $ => seq( field('name', choice( $._type_identifier, alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier), $.generic_type_with_turbofish, )), field('body', $.field_initializer_list), ), field_initializer_list: $ => seq( '{', sepBy(',', choice( $.shorthand_field_initializer, $.field_initializer, $.base_field_initializer, alias('..', $.field_ellipsis), )), optional(','), '}', ), shorthand_field_initializer: $ => seq( optional($.attributes), $.identifier, ), field_initializer: $ => seq( optional($.attributes), field('field', $._field_identifier_or_index), ':', field('value', $._expression), ), base_field_initializer: $ => seq( '..', $._expression, ), if_expression: $ => prec.right(seq( 'if', field('condition', $._condition), field('consequence', $.block), optional(field('alternative', $.else_clause)), )), let_condition: $ => seq( 'let', field('pattern', $._pattern), '=', field('value', prec.left(PREC.and, $._expression)), ), _let_chain: $ => prec.left(PREC.and, choice( seq($._let_chain, '&&', $.let_condition), seq($._let_chain, '&&', $._expression), seq($.let_condition, '&&', $._expression), seq($.let_condition, '&&', $.let_condition), seq($._expression, '&&', $.let_condition), )), _condition: $ => choice( $._expression, $.let_condition, alias($._let_chain, $.let_chain), ), else_clause: $ => seq( 'else', choice( $.block, $.if_expression, ), ), match_expression: $ => seq( 'match', field('value', $._expression), field('body', $.match_block), ), match_block: $ => seq( '{', repeat($.inner_attribute_item), optional(seq( repeat($.match_arm), alias($.last_match_arm, $.match_arm), )), '}', ), match_arm: $ => prec.right(seq( optional($.attributes), field('pattern', $.match_pattern), '=>', choice( seq(field('value', $._expression), ','), field('value', prec(1, $._expression_ending_with_block)), ), )), last_match_arm: $ => seq( optional($.attributes), field('pattern', $.match_pattern), '=>', field('value', $._expression), optional(','), ), match_pattern: $ => seq( $._pattern, optional(seq('if', field('condition', $._condition))), ), while_expression: $ => seq( optional(seq($.label, ':')), 'while', field('condition', $._condition), field('body', $.block), ), loop_expression: $ => seq( optional(seq($.label, ':')), 'loop', field('body', $.block), ), for_expression: $ => seq( optional(seq($.label, ':')), 'for', field('pattern', $._pattern), 'in', field('value', $._expression), field('body', $.block), ), const_block: $ => seq( 'const', field('body', $.block), ), closure_expression: $ => prec(PREC.closure, seq( optional('static'), optional('async'), optional('move'), field('parameters', $.closure_parameters), choice( seq( optional(seq('->', field('return_type', $._type))), field('body', $.block), ), field('body', choice($._expression, '_')), ), )), closure_parameters: $ => seq( '|', sepBy(',', choice( $._pattern, $.parameter, )), optional(','), '|', ), label: $ => seq('\'', $.identifier), break_expression: $ => prec.left(seq('break', optional($.label), optional($._expression))), continue_expression: $ => prec.left(seq('continue', optional($.label))), index_expression: $ => prec(PREC.call, seq($._expression, '[', $._expression, ']')), await_expression: $ => prec(PREC.field, seq( $._expression, '.', 'await', )), field_expression: $ => prec(PREC.field, seq( field('value', $._expression), '.', field('field', $._field_identifier_or_index), )), unsafe_block: $ => seq( 'unsafe', $.block, ), async_block: $ => seq( 'async', optional('move'), $.block, ), gen_block: $ => seq( 'gen', optional('move'), $.block, ), try_block: $ => seq( 'try', $.block, ), block: $ => prec.right(3, seq( optional(seq($.label, ':')), '{', repeat($._statement), optional($._expression), '}', )), // Section - Patterns _pattern: $ => choice( $._literal_pattern, alias(choice(...primitiveTypes), $.identifier), $.identifier, $.scoped_identifier, $.generic_pattern, $.tuple_pattern, $.tuple_struct_pattern, $.struct_pattern, $._reserved_identifier, $.ref_pattern, $.slice_pattern, $.captured_pattern, $.reference_pattern, $.remaining_field_pattern, $.mut_pattern, $.range_pattern, $.or_pattern, $.const_block, $.macro_invocation, $.box_pattern, '_', ), generic_pattern: $ => seq( choice( $.identifier, $.scoped_identifier, ), '::', field('type_arguments', $.type_arguments), ), tuple_pattern: $ => seq( '(', sepBy(',', choice($._pattern, $.closure_expression)), optional(','), ')', ), slice_pattern: $ => seq( '[', sepBy(',', $._pattern), optional(','), ']', ), tuple_struct_pattern: $ => seq( field('type', choice( $.identifier, $.scoped_identifier, alias($.generic_type_with_turbofish, $.generic_type), )), '(', sepBy(',', $._pattern), optional(','), ')', ), struct_pattern: $ => seq( field('type', choice( $._type_identifier, $.scoped_type_identifier, $.generic_type_with_turbofish, )), '{', sepBy(',', choice( seq(optional($.attributes), $.field_pattern), $.remaining_field_pattern) ), optional(','), '}', ), field_pattern: $ => seq( optional('ref'), optional($.mutable_specifier), choice( field('name', alias($.identifier, $.shorthand_field_identifier)), seq( field('name', $._field_identifier_or_index), ':', field('pattern', $._pattern), ), ), ), remaining_field_pattern: _ => '..', mut_pattern: $ => prec(-1, seq( $.mutable_specifier, $._pattern, )), range_pattern: $ => choice( seq( field('left', choice( $._literal_pattern, $._path, )), choice( seq( choice('...', '..=', '..'), field('right', choice( $._literal_pattern, $._path, )), ), '..', ), ), seq( choice('..=', '..'), field('right', choice( $._literal_pattern, $._path, )), ), ), ref_pattern: $ => seq( 'ref', $._pattern, ), box_pattern: $ => seq( 'box', $._pattern, ), captured_pattern: $ => seq( $.identifier, '@', $._pattern, ), reference_pattern: $ => seq( '&', optional($.mutable_specifier), $._pattern, ), or_pattern: $ => prec.left(-2, choice( seq($._pattern, '|', $._pattern), seq('|', $._pattern), )), // Section - Literals _literal: $ => choice( $._any_string_literal, $.char_literal, $.boolean_literal, $.integer_literal, $.float_literal, ), _literal_pattern: $ => choice( $._any_string_literal, $.char_literal, $.boolean_literal, $.integer_literal, $.float_literal, $.negative_literal, ), negative_literal: $ => seq('-', choice($.integer_literal, $.float_literal)), integer_literal: _ => token(seq( choice( /[0-9][0-9_]*/, /0x[0-9a-fA-F_]+/, /0b[01_]+/, /0o[0-7_]+/, ), optional(choice(...numericTypes, /[a-zA-Z_]\w*/)), )), string_literal: $ => seq( choice( '"', alias(/[bc]"/, '"'), ), repeat(choice( $.escape_sequence, $.string_content, )), '"', ), raw_string_literal: $ => seq( $._raw_string_literal_start, alias($.raw_string_literal_content, $.string_content), $._raw_string_literal_end, ), _any_string_literal: $ => choice( $.string_literal, $.raw_string_literal, ), char_literal: _ => token(seq( optional('b'), '\'', optional(choice( seq('\\', choice( /[^xu]/, /u[0-9a-fA-F]{4}/, /u\{[0-9a-fA-F_]+\}/, /x[0-9a-fA-F]{2}/, )), /[^\\']/, )), '\'', )), escape_sequence: _ => token.immediate( seq('\\', choice( /[^xu]/, /u[0-9a-fA-F]{4}/, /u\{[0-9a-fA-F_]+\}/, /x[0-9a-fA-F]{2}/, ), )), boolean_literal: _ => choice('true', 'false'), line_comment: $ => seq( // All line comments start with either two slashes or four slashes or more. // The case of three slashes (outer doc comments) is handled as a special case // by the lexer, which then emits the _outer_line_doc_comment_start token. '//', choice( // An inner doc comment seq( field('inner', alias($._inner_line_doc_comment_marker, $.inner_doc_comment_marker)), field('doc', alias($._line_doc_content, $.doc_comment))), // A normal comment token.immediate(prec(1, /.*/)), ), ), _inner_line_doc_comment_marker: _ => token.immediate(prec(2, '!')), // An outer line doc comment applies to the element that it is outside of line_outer_doc_comment: $ => seq( $._outer_line_doc_comment_start, field('doc', alias($._line_doc_content, $.doc_comment)), ), // Documentation block comments: /** docs */ block_outer_doc_comment: $ => seq( $._outer_block_doc_comment_start, optional(field('doc', alias($._block_comment_content, $.doc_comment))), '*/', ), block_comment: $ => seq( '/*', optional( choice( // Inner documentation block comments: /*! docs */ seq( field('inner', alias($._inner_block_doc_comment_marker, $.inner_doc_comment_marker)), optional(field('doc', alias($._block_comment_content, $.doc_comment))), ), // Non-doc block comments $._block_comment_content, ), ), '*/', ), _path: $ => choice( $.self, alias(choice(...primitiveTypes), $.identifier), $.metavariable, $.super, $.crate, $.identifier, $.scoped_identifier, $._reserved_identifier, ), identifier: _ => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/, shebang: _ => /#![\r\f\t\v ]*([^\[\n].*)?\n/, frontmatter: $ => seq( $._frontmatter_start, $.frontmatter_content, $._frontmatter_end, ), _reserved_identifier: $ => alias(choice( // 'async', // TODO: this should be enabled but it creates a conflict with trait bounds 'auto', 'await', 'default', // 'dyn', // TODO: this should be enabled but it creates a conflict with scoped type identifiers 'gen', 'macro_rules', 'raw', 'safe', 'try', 'union', ), $.identifier), _type_identifier: $ => alias($.identifier, $.type_identifier), _field_identifier: $ => alias($.identifier, $.field_identifier), _field_identifier_or_index: $ => choice($._field_identifier, $.integer_literal), self: _ => 'self', super: _ => 'super', crate: _ => 'crate', metavariable: _ => /\$\s*[_\p{XID_Start}][_\p{XID_Continue}]*/ }, }); /** * Creates a rule to match one or more of the rules separated by the separator. * * @param {RuleOrLiteral} sep - The separator to use. * @param {RuleOrLiteral} rule * * @returns {SeqRule} */ function sepBy1(sep, rule) { return seq(rule, repeat(seq(sep, rule))); } /** * Creates a rule to optionally match one or more of the rules separated by the separator. * * @param {RuleOrLiteral} sep - The separator to use. * @param {RuleOrLiteral} rule * * @returns {ChoiceRule} */ function sepBy(sep, rule) { return optional(sepBy1(sep, rule)); } tree-sitter-rust-orchard-0.16.3+ds/identify_features.sh000077500000000000000000000003241516074642400231450ustar00rootroot00000000000000#!/usr/bin/env bash while read line; do path=$(echo $line | sed -e 's:^FAIL ::') contents=`cat $path | grep "#!\[feature" | sed -e 's/#!\[feature(\(.*\))\].*/\1/'` echo -e "$path\t$contents" done < $1 tree-sitter-rust-orchard-0.16.3+ds/package-lock.json000066400000000000000000000276421516074642400223250ustar00rootroot00000000000000{ "name": "tree-sitter-rust-orchard", "version": "0.16.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tree-sitter-rust-orchard", "version": "0.16.3", "hasInstallScript": true, "license": "MIT", "dependencies": { "node-addon-api": "^8.2.1", "node-gyp-build": "^4.8.2" }, "devDependencies": { "prebuildify": "^6.0.1", "tree-sitter": "^0.25.0", "tree-sitter-cli": "^0.25.5" }, "peerDependencies": { "tree-sitter": "^0.25.0" }, "peerDependenciesMeta": { "tree-sitter": { "optional": true } } }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", "dev": true, "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ], "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "node_modules/chownr": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", "dev": true }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", "dev": true, "dependencies": { "once": "^1.4.0" } }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", "dev": true }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "node_modules/minimist": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/mkdirp-classic": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "dev": true }, "node_modules/node-abi": { "version": "3.67.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.67.0.tgz", "integrity": "sha512-bLn/fU/ALVBE9wj+p4Y21ZJWYFjUXLXPi/IewyLZkx3ApxKDNBWCKdReeKOtD8dWpOdDCeMyLh6ZewzcLsG2Nw==", "dev": true, "dependencies": { "semver": "^7.3.5" }, "engines": { "node": ">=10" } }, "node_modules/node-addon-api": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz", "integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==", "engines": { "node": "^18 || ^20 || >= 21" } }, "node_modules/node-gyp-build": { "version": "4.8.4", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "node_modules/npm-run-path": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-3.1.0.tgz", "integrity": "sha512-Dbl4A/VfiVGLgQv29URL9xshU8XDY1GeLy+fsaZ1AA8JDSfjvr5P5+pzRbWqRSBxk6/DW7MIh8lTM/PaGnP2kg==", "dev": true, "dependencies": { "path-key": "^3.0.0" }, "engines": { "node": ">=8" } }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, "dependencies": { "wrappy": "1" } }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/prebuildify": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-6.0.1.tgz", "integrity": "sha512-8Y2oOOateom/s8dNBsGIcnm6AxPmLH4/nanQzL5lQMU+sC0CMhzARZHizwr36pUPLdvBnOkCNQzxg4djuFSgIw==", "dev": true, "dependencies": { "minimist": "^1.2.5", "mkdirp-classic": "^0.5.3", "node-abi": "^3.3.0", "npm-run-path": "^3.1.0", "pump": "^3.0.0", "tar-fs": "^2.1.0" }, "bin": { "prebuildify": "bin.js" } }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", "dev": true, "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dev": true, "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", "util-deprecate": "^1.0.1" }, "engines": { "node": ">= 6" } }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "dev": true, "bin": { "semver": "bin/semver.js" }, "engines": { "node": ">=10" } }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "dev": true, "dependencies": { "safe-buffer": "~5.2.0" } }, "node_modules/tar-fs": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", "dev": true, "dependencies": { "chownr": "^1.1.1", "mkdirp-classic": "^0.5.2", "pump": "^3.0.0", "tar-stream": "^2.1.4" } }, "node_modules/tar-stream": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", "dev": true, "dependencies": { "bl": "^4.0.3", "end-of-stream": "^1.4.1", "fs-constants": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^3.1.1" }, "engines": { "node": ">=6" } }, "node_modules/tree-sitter": { "version": "0.25.0", "resolved": "https://registry.npmjs.org/tree-sitter/-/tree-sitter-0.25.0.tgz", "integrity": "sha512-PGZZzFW63eElZJDe/b/R/LbsjDDYJa5UEjLZJB59RQsMX+fo0j54fqBPn1MGKav/QNa0JR0zBiVaikYDWCj5KQ==", "dev": true, "hasInstallScript": true, "dependencies": { "node-addon-api": "^8.3.0", "node-gyp-build": "^4.8.4" } }, "node_modules/tree-sitter-cli": { "version": "0.25.5", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.25.5.tgz", "integrity": "sha512-aLAyf+T3Y5psFZPgd7bUovhhJtplD1hk1mIwMsSZGwoEa6iGgqeGYmV9zgjatT5bMPUfcKX9x1xZfYim7aItjQ==", "dev": true, "hasInstallScript": true, "bin": { "tree-sitter": "cli.js" }, "engines": { "node": ">=12.0.0" } }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true } } } tree-sitter-rust-orchard-0.16.3+ds/package.json000066400000000000000000000025131516074642400213650ustar00rootroot00000000000000{ "name": "tree-sitter-rust-orchard", "version": "0.16.3", "description": "Grammar for Rust that aims to be closer to the actual AST", "repository": "https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard", "license": "MIT", "author": { "name": "Maxim Sokolov", "email": "maxim0xff@gmail.com" }, "contributors": [ { "name": "Max Brunsfeld", "email": "maxbrunsfeld@gmail.com" }, { "name": "Amaan Qureshi", "email": "amaanq12@gmail.com" } ], "main": "bindings/node", "types": "bindings/node", "keywords": [ "incremental", "parsing", "tree-sitter", "rust" ], "files": [ "grammar.js", "tree-sitter.json", "binding.gyp", "prebuilds/**", "bindings/node/*", "queries/*", "src/**", "*.wasm" ], "dependencies": { "node-addon-api": "^8.2.1", "node-gyp-build": "^4.8.2" }, "devDependencies": { "prebuildify": "^6.0.1", "tree-sitter": "^0.25.0", "tree-sitter-cli": "^0.25.5" }, "peerDependencies": { "tree-sitter": "^0.25.0" }, "peerDependenciesMeta": { "tree-sitter": { "optional": true } }, "scripts": { "install": "node-gyp-build", "prestart": "tree-sitter build --wasm", "start": "tree-sitter playground", "test": "node --test bindings/node/*_test.js" } } tree-sitter-rust-orchard-0.16.3+ds/pyproject.toml000066400000000000000000000016371516074642400220210ustar00rootroot00000000000000[build-system] requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" [project] name = "tree-sitter-rust-orchard" description = "Grammar for Rust that aims to be closer to the actual AST" version = "0.16.3" keywords = ["incremental", "parsing", "tree-sitter", "rut"] classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Compilers", "Topic :: Text Processing :: Linguistic", "Typing :: Typed", ] authors = [ { name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" }, { name = "Amaan Qureshi", email = "amaanq12@gmail.com" }, ] requires-python = ">=3.9" license.text = "MIT" readme = "README.md" [project.urls] Homepage = "https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard" [project.optional-dependencies] core = ["tree-sitter~=0.24"] [tool.cibuildwheel] build = "cp310-*" build-frontend = "build" tree-sitter-rust-orchard-0.16.3+ds/queries/000077500000000000000000000000001516074642400205535ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/queries/highlights.scm000066400000000000000000000071741516074642400234220ustar00rootroot00000000000000; Identifiers (type_identifier) @type (primitive_type) @type.builtin (field_identifier) @property ; Identifier conventions ; Assume all-caps names are constants ((identifier) @constant (#match? @constant "^[A-Z][A-Z\\d_]+$'")) ; Assume uppercase names are enum constructors ((identifier) @constructor (#match? @constructor "^[A-Z]")) ; Assume that uppercase names in paths are types ((scoped_identifier path: (identifier) @type) (#match? @type "^[A-Z]")) ((scoped_identifier path: (scoped_identifier name: (identifier) @type)) (#match? @type "^[A-Z]")) ((scoped_type_identifier path: (identifier) @type) (#match? @type "^[A-Z]")) ((scoped_type_identifier path: (scoped_identifier name: (identifier) @type)) (#match? @type "^[A-Z]")) ; Assume all qualified names in struct patterns are enum constructors. (They're ; either that, or struct names; highlighting both as constructors seems to be ; the less glaring choice of error, visually.) (struct_pattern type: (scoped_type_identifier name: (type_identifier) @constructor)) ; Function calls (call_expression function: (identifier) @function) (call_expression function: (field_expression field: (field_identifier) @function.method)) (call_expression function: (scoped_identifier "::" name: (identifier) @function)) (generic_function function: (identifier) @function) (generic_function function: (scoped_identifier name: (identifier) @function)) (generic_function function: (field_expression field: (field_identifier) @function.method)) (macro_invocation macro: (identifier) @function.macro "!" @function.macro) ; Function definitions (function_item (identifier) @function) (function_signature_item (identifier) @function) (line_comment) @comment (block_comment) @comment (line_outer_doc_comment) @comment.documentation (block_outer_doc_comment) @comment.documentation (line_comment (doc_comment)) @comment.documentation (block_comment (doc_comment)) @comment.documentation "(" @punctuation.bracket ")" @punctuation.bracket "[" @punctuation.bracket "]" @punctuation.bracket "{" @punctuation.bracket "}" @punctuation.bracket (type_arguments "<" @punctuation.bracket ">" @punctuation.bracket) (type_parameters "<" @punctuation.bracket ">" @punctuation.bracket) "::" @punctuation.delimiter ":" @punctuation.delimiter "." @punctuation.delimiter "," @punctuation.delimiter ";" @punctuation.delimiter (parameter (identifier) @variable.parameter) (lifetime (identifier) @label) "auto" @keyword "as" @keyword "async" @keyword "await" @keyword "become" @keyword "break" @keyword "const" @keyword "~const" @keyword "continue" @keyword "default" @keyword "dyn" @keyword "else" @keyword "enum" @keyword "extern" @keyword "fn" @keyword "for" @keyword "gen" @keyword "if" @keyword "impl" @keyword "in" @keyword "let" @keyword "loop" @keyword "macro_rules" @keyword "macro" @keyword "match" @keyword "mod" @keyword "move" @keyword "pub" @keyword "raw" @keyword "ref" @keyword "return" @keyword "safe" @keyword "static" @keyword "struct" @keyword "trait" @keyword "type" @keyword "union" @keyword "unsafe" @keyword "use" @keyword "where" @keyword "while" @keyword "yield" @keyword (crate) @keyword (mutable_specifier) @keyword (use_list (self) @keyword) (scoped_use_list (self) @keyword) (scoped_identifier (self) @keyword) (super) @keyword (self) @variable.builtin (char_literal) @string (string_literal) @string (raw_string_literal) @string (boolean_literal) @constant.builtin (integer_literal) @constant.builtin (float_literal) @constant.builtin (escape_sequence) @escape (attribute_item) @attribute (inner_attribute_item) @attribute "*" @operator "&" @operator "'" @operator tree-sitter-rust-orchard-0.16.3+ds/queries/injections.scm000066400000000000000000000003671516074642400234320ustar00rootroot00000000000000((macro_invocation (token_tree) @injection.content) (#set! injection.language "rust") (#set! injection.include-children)) ((macro_rule (token_tree) @injection.content) (#set! injection.language "rust") (#set! injection.include-children)) tree-sitter-rust-orchard-0.16.3+ds/queries/tags.scm000066400000000000000000000022521516074642400222160ustar00rootroot00000000000000; ADT definitions (struct_item name: (type_identifier) @name) @definition.class (enum_item name: (type_identifier) @name) @definition.class (union_item name: (type_identifier) @name) @definition.class ; type aliases (type_item name: (type_identifier) @name) @definition.class ; method definitions (declaration_list (function_item name: (identifier) @name) @definition.method) ; function definitions (function_item name: (identifier) @name) @definition.function ; trait definitions (trait_item name: (type_identifier) @name) @definition.interface ; module definitions (mod_item name: (identifier) @name) @definition.module ; macro definitions (macro_definition name: (identifier) @name) @definition.macro ; references (call_expression function: (identifier) @name) @reference.call (call_expression function: (field_expression field: (field_identifier) @name)) @reference.call (macro_invocation macro: (identifier) @name) @reference.call ; implementations (impl_item trait: (type_identifier) @name) @reference.implementation (impl_item type: (type_identifier) @name !trait) @reference.implementation tree-sitter-rust-orchard-0.16.3+ds/setup.py000066400000000000000000000040601516074642400206100ustar00rootroot00000000000000from os import path from platform import system from sysconfig import get_config_var from setuptools import Extension, find_packages, setup from setuptools.command.build import build from setuptools.command.egg_info import egg_info from wheel.bdist_wheel import bdist_wheel sources = [ "bindings/python/tree_sitter_rust_orchard/binding.c", "src/parser.c", ] if path.exists("src/scanner.c"): sources.append("src/scanner.c") macros: list[tuple[str, str | None]] = [ ("PY_SSIZE_T_CLEAN", None), ("TREE_SITTER_HIDE_SYMBOLS", None), ] if limited_api := not get_config_var("Py_GIL_DISABLED"): macros.append(("Py_LIMITED_API", "0x030A0000")) if system() != "Windows": cflags = ["-std=c11", "-fvisibility=hidden"] else: cflags = ["/std:c11", "/utf-8"] class Build(build): def run(self): if path.isdir("queries"): dest = path.join(self.build_lib, "tree_sitter_rust_orchard", "queries") self.copy_tree("queries", dest) super().run() class BdistWheel(bdist_wheel): def get_tag(self): python, abi, platform = super().get_tag() if python.startswith("cp"): python, abi = "cp310", "abi3" return python, abi, platform class EggInfo(egg_info): def find_sources(self): super().find_sources() self.filelist.recursive_include("queries", "*.scm") self.filelist.include("src/tree_sitter/*.h") setup( packages=find_packages("bindings/python"), package_dir={"": "bindings/python"}, package_data={ "tree_sitter_rust_orchard": ["*.pyi", "py.typed"], "tree_sitter_rust_orchard.queries": ["*.scm"], }, ext_package="tree_sitter_rust_orchard", ext_modules=[ Extension( name="_binding", sources=sources, extra_compile_args=cflags, define_macros=macros, include_dirs=["src"], py_limited_api=limited_api, ) ], cmdclass={ "build": Build, "bdist_wheel": BdistWheel, "egg_info": EggInfo, }, zip_safe=False ) tree-sitter-rust-orchard-0.16.3+ds/split.sh000077500000000000000000000011301516074642400205630ustar00rootroot00000000000000#!/bin/bash set -e rustc_test_dir="$1" target_dir="$2" echo $target_dir mkdir -p $target_dir/valid mkdir -p $target_dir/invalid tmp_dir="/tmp/tmp$$" mkdir -p $tmp_dir find $rustc_test_dir -type f | grep -P "\.rs$" | while read -r f; do echo $f d=`dirname $f` if rustc --edition 2024 --crate-type=lib $f -Zwrite-long-types-to-disk=no -o "${tmp_dir}/output" > /dev/null 2>&1; then echo valid mkdir -p "$target_dir/valid/$d" cp "$f" "$target_dir/valid/$d" else echo invalid mkdir -p "$target_dir/invalid/$d" cp "$f" "$target_dir/invalid/$d" fi done tree-sitter-rust-orchard-0.16.3+ds/src/000077500000000000000000000000001516074642400176655ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/src/scanner.c000066400000000000000000000354771516074642400215020ustar00rootroot00000000000000#include "tree_sitter/alloc.h" #include "tree_sitter/parser.h" #include enum TokenType { STRING_CONTENT, RAW_STRING_LITERAL_START, RAW_STRING_LITERAL_CONTENT, RAW_STRING_LITERAL_END, FLOAT_LITERAL, BLOCK_OUTER_DOC_START, LINE_OUTER_DOC_START, BLOCK_INNER_DOC_MARKER, BLOCK_COMMENT_CONTENT, LINE_DOC_CONTENT, FRONTMATTER_START, FRONTMATTER_CONTENT, FRONTMATTER_END, ERROR_SENTINEL }; typedef struct { uint8_t opening_hash_count; uint8_t frontmatter_dashes; } Scanner; void *tree_sitter_rust_orchard_external_scanner_create() { return ts_calloc(1, sizeof(Scanner)); } void tree_sitter_rust_orchard_external_scanner_destroy(void *payload) { ts_free((Scanner *)payload); } unsigned tree_sitter_rust_orchard_external_scanner_serialize(void *payload, char *buffer) { Scanner *scanner = (Scanner *)payload; buffer[0] = (char)scanner->opening_hash_count; buffer[1] = (char)scanner->frontmatter_dashes; return 2; } void tree_sitter_rust_orchard_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { Scanner *scanner = (Scanner *)payload; scanner->opening_hash_count = 0; if (length == 2) { scanner->opening_hash_count = buffer[0]; scanner->frontmatter_dashes = buffer[1]; } } static inline bool is_num_char(int32_t c) { return c == '_' || iswdigit(c); } static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); } static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); } static inline bool process_string(TSLexer *lexer) { bool has_content = false; for (;;) { if (lexer->lookahead == '\"' || lexer->lookahead == '\\') { break; } if (lexer->eof(lexer)) { return false; } has_content = true; advance(lexer); } lexer->result_symbol = STRING_CONTENT; lexer->mark_end(lexer); return has_content; } static inline bool scan_raw_string_start(Scanner *scanner, TSLexer *lexer) { if (lexer->lookahead == 'b' || lexer->lookahead == 'c') { advance(lexer); } if (lexer->lookahead != 'r') { return false; } advance(lexer); uint8_t opening_hash_count = 0; while (lexer->lookahead == '#') { advance(lexer); opening_hash_count++; } if (lexer->lookahead != '"') { return false; } advance(lexer); scanner->opening_hash_count = opening_hash_count; lexer->result_symbol = RAW_STRING_LITERAL_START; return true; } static inline bool scan_raw_string_content(Scanner *scanner, TSLexer *lexer) { for (;;) { if (lexer->eof(lexer)) { return false; } if (lexer->lookahead == '"') { lexer->mark_end(lexer); advance(lexer); unsigned hash_count = 0; while (lexer->lookahead == '#' && hash_count < scanner->opening_hash_count) { advance(lexer); hash_count++; } if (hash_count == scanner->opening_hash_count) { lexer->result_symbol = RAW_STRING_LITERAL_CONTENT; return true; } } else { advance(lexer); } } } static inline bool scan_raw_string_end(Scanner *scanner, TSLexer *lexer) { advance(lexer); for (unsigned i = 0; i < scanner->opening_hash_count; i++) { advance(lexer); } lexer->result_symbol = RAW_STRING_LITERAL_END; return true; } static inline bool process_float_literal(TSLexer *lexer) { lexer->result_symbol = FLOAT_LITERAL; advance(lexer); while (is_num_char(lexer->lookahead)) { advance(lexer); } bool has_fraction = false, has_exponent = false; if (lexer->lookahead == '.') { has_fraction = true; advance(lexer); if (iswalpha(lexer->lookahead) || lexer->lookahead == '_') { // The dot is followed by a letter or _: 1.max(2) => not a float but an integer return false; } if (lexer->lookahead == '.') { return false; } while (is_num_char(lexer->lookahead)) { advance(lexer); } } lexer->mark_end(lexer); if (lexer->lookahead == 'e' || lexer->lookahead == 'E') { has_exponent = true; advance(lexer); if (lexer->lookahead == '+' || lexer->lookahead == '-') { advance(lexer); } if (!is_num_char(lexer->lookahead)) { return true; } advance(lexer); while (is_num_char(lexer->lookahead)) { advance(lexer); } lexer->mark_end(lexer); } if (!has_exponent && !has_fraction) { return false; } if (lexer->lookahead != 'u' && lexer->lookahead != 'i' && lexer->lookahead != 'f') { return true; } advance(lexer); if (!iswdigit(lexer->lookahead)) { return true; } while (iswdigit(lexer->lookahead)) { advance(lexer); } lexer->mark_end(lexer); return true; } static inline bool process_doc_comment_start(TSLexer *lexer) { int count = 0; advance(lexer); if (lexer->lookahead == '/') { for(; count < 2 && lexer->lookahead == '/'; count++) { advance(lexer); } if (count == 2 && lexer->lookahead != '/') { lexer->result_symbol = LINE_OUTER_DOC_START; return true; } } else if (lexer->lookahead == '*') { for(; count < 2 && lexer->lookahead == '*'; count++) { advance(lexer); } if (count == 2 && lexer->lookahead != '/' && lexer->lookahead != '*') { lexer->result_symbol = BLOCK_OUTER_DOC_START; return true; } } return false; } static inline bool process_line_doc_content(TSLexer *lexer) { lexer->result_symbol = LINE_DOC_CONTENT; for (;;) { if (lexer->eof(lexer)) { return true; } if (lexer->lookahead == '\n') { // Include the newline in the doc content node. // Line endings are useful for markdown injection. advance(lexer); return true; } advance(lexer); } } typedef enum { LeftForwardSlash, LeftAsterisk, Continuing, } BlockCommentState; typedef struct { BlockCommentState state; unsigned nestingDepth; } BlockCommentProcessing; static inline void process_left_forward_slash(BlockCommentProcessing *processing, char current) { if (current == '*') { processing->nestingDepth += 1; } else if (current == '/') { processing->state = LeftForwardSlash; return; } processing->state = Continuing; }; static inline void process_left_asterisk(BlockCommentProcessing *processing, char current, TSLexer *lexer) { if (current == '*') { lexer->mark_end(lexer); processing->state = LeftAsterisk; return; } if (current == '/') { processing->nestingDepth -= 1; } processing->state = Continuing; } static inline void process_continuing(BlockCommentProcessing *processing, char current) { switch (current) { case '/': processing->state = LeftForwardSlash; break; case '*': processing->state = LeftAsterisk; break; } } static inline bool process_block_comment(TSLexer *lexer, const bool *valid_symbols) { char first = (char)lexer->lookahead; // The first character is stored so we can safely advance inside // these if blocks. However, because we only store one, we can only // safely advance 1 time. Since there's a chance that an advance could // happen in one state, we must advance in all states to ensure that // the program ends up in a sane state prior to processing the block // comment if need be. if (valid_symbols[BLOCK_INNER_DOC_MARKER] && first == '!') { lexer->result_symbol = BLOCK_INNER_DOC_MARKER; advance(lexer); return true; } advance(lexer); if (valid_symbols[BLOCK_COMMENT_CONTENT]) { BlockCommentProcessing processing = {Continuing, 1}; // Manually set the current state based on the first character switch (first) { case '*': processing.state = LeftAsterisk; if (lexer->lookahead == '/') { // This case can happen in an empty doc block comment // like /*!*/. The comment has no contents, so bail. return false; } break; case '/': processing.state = LeftForwardSlash; break; default: processing.state = Continuing; break; } // For the purposes of actually parsing rust code, this // is incorrect as it considers an unterminated block comment // to be an error. However, for the purposes of syntax highlighting // this should be considered successful as otherwise you are not able // to syntax highlight a block of code prior to closing the // block comment while (!lexer->eof(lexer) && processing.nestingDepth != 0) { // Set first to the current lookahead as that is the second character // as we force an advance in the above code when we are checking if we // need to handle a block comment inner or outer doc comment signifier // node first = (char)lexer->lookahead; switch (processing.state) { case LeftForwardSlash: process_left_forward_slash(&processing, first); break; case LeftAsterisk: process_left_asterisk(&processing, first, lexer); break; case Continuing: lexer->mark_end(lexer); process_continuing(&processing, first); break; default: break; } advance(lexer); if (first == '/' && processing.nestingDepth != 0) { lexer->mark_end(lexer); } } lexer->result_symbol = BLOCK_COMMENT_CONTENT; return true; } return false; } static inline bool process_frontmatter_start(TSLexer *lexer, Scanner *scanner) { uint8_t amount = 0; while (lexer->lookahead == '-') { amount++; advance(lexer); } if (amount < 3) { return false; } else { scanner->frontmatter_dashes = amount; lexer->result_symbol = FRONTMATTER_START; // parse optional info string after the initial fence while (lexer->lookahead != '\n' && !lexer->eof(lexer)) { advance(lexer); } advance(lexer); return true; } } static inline bool process_frontmatter(TSLexer *lexer, Scanner *scanner) { // seperately parse empty frontmatter, as tree-sitter strips all whitespace, // including newlines, so i can't rely on parsing only after a newline in this case. lexer->mark_end(lexer); uint8_t amount = 0; while (lexer->lookahead == '-' && amount < scanner->frontmatter_dashes) { amount++; advance(lexer); } if (amount == scanner->frontmatter_dashes) { lexer->result_symbol = FRONTMATTER_CONTENT; return true; } for (;;) { if (lexer->eof(lexer)) { return false; } if (lexer->lookahead == '\n') { lexer->mark_end(lexer); advance(lexer); uint8_t amount = 0; while (lexer->lookahead == '-' && amount < scanner->frontmatter_dashes) { amount++; advance(lexer); } if (amount == scanner->frontmatter_dashes) { lexer->result_symbol = FRONTMATTER_CONTENT; return true; } } else { advance(lexer); } } } static inline bool process_frontmatter_end(TSLexer *lexer, Scanner *scanner) { advance(lexer); for (unsigned int amount = 0; amount < scanner->frontmatter_dashes; amount++) { advance(lexer); } lexer->result_symbol = FRONTMATTER_END; return true; } bool tree_sitter_rust_orchard_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { // The documentation states that if the lexical analysis fails for some reason // they will mark every state as valid and pass it to the external scanner // However, we can't do anything to help them recover in that case so we // should just fail. /* link: https://tree-sitter.github.io/tree-sitter/creating-parsers#external-scanners If a syntax error is encountered during regular parsing, Tree-sitter’s first action during error recovery will be to call the external scanner’s scan function with all tokens marked valid. The scanner should detect this case and handle it appropriately. One simple method of detection is to add an unused token to the end of the externals array, for example externals: $ => [$.token1, $.token2, $.error_sentinel], then check whether that token is marked valid to determine whether Tree-sitter is in error correction mode. */ if (valid_symbols[ERROR_SENTINEL]) { return false; } Scanner *scanner = (Scanner *)payload; if (valid_symbols[BLOCK_COMMENT_CONTENT] || valid_symbols[BLOCK_INNER_DOC_MARKER]) { return process_block_comment(lexer, valid_symbols); } if (valid_symbols[STRING_CONTENT] && !valid_symbols[FLOAT_LITERAL]) { return process_string(lexer); } if (valid_symbols[LINE_DOC_CONTENT]) { return process_line_doc_content(lexer); } while (iswspace(lexer->lookahead)) { skip(lexer); } if (valid_symbols[RAW_STRING_LITERAL_START] && (lexer->lookahead == 'r' || lexer->lookahead == 'b' || lexer->lookahead == 'c')) { return scan_raw_string_start(scanner, lexer); } if (valid_symbols[RAW_STRING_LITERAL_CONTENT]) { return scan_raw_string_content(scanner, lexer); } if (valid_symbols[RAW_STRING_LITERAL_END] && lexer->lookahead == '"') { return scan_raw_string_end(scanner, lexer); } if (valid_symbols[FLOAT_LITERAL] && iswdigit(lexer->lookahead)) { return process_float_literal(lexer); } if (valid_symbols[FRONTMATTER_START] && lexer->lookahead == '-') { return process_frontmatter_start(lexer, scanner); } if (valid_symbols[FRONTMATTER_CONTENT]) { return process_frontmatter(lexer, scanner); } if (valid_symbols[FRONTMATTER_END]) { return process_frontmatter_end(lexer, scanner); } if ((valid_symbols[LINE_OUTER_DOC_START] || valid_symbols[BLOCK_OUTER_DOC_START]) && lexer->lookahead == '/') { return process_doc_comment_start(lexer); } return false; } tree-sitter-rust-orchard-0.16.3+ds/test.sh000077500000000000000000000004061516074642400204140ustar00rootroot00000000000000#!/bin/bash rustc_comparison_path=$1 for testcase in `find $rustc_comparison_path -type f`; do tree-sitter parse $testcase > /dev/null 2>&1 stat=$? if [ ! $stat == 0 ]; then echo "FAIL $testcase" else echo "PASS $testcase" fi done tree-sitter-rust-orchard-0.16.3+ds/test/000077500000000000000000000000001516074642400200555ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/test/corpus/000077500000000000000000000000001516074642400213705ustar00rootroot00000000000000tree-sitter-rust-orchard-0.16.3+ds/test/corpus/async.txt000066400000000000000000000110051516074642400232430ustar00rootroot00000000000000================================================================================ Async function ================================================================================ async fn abc() {} async fn main() { let x = futures.await?; } -------------------------------------------------------------------------------- (source_file (function_item (function_modifiers) (identifier) (parameters) (block)) (function_item (function_modifiers) (identifier) (parameters) (block (let_declaration (identifier) (try_expression (await_expression (identifier))))))) ================================================================================ Await expression ================================================================================ futures.await; futures.await?; futures.await?.await?; futures.await?.function().await?; -------------------------------------------------------------------------------- (source_file (expression_statement (await_expression (identifier))) (expression_statement (try_expression (await_expression (identifier)))) (expression_statement (try_expression (await_expression (try_expression (await_expression (identifier)))))) (expression_statement (try_expression (await_expression (call_expression (field_expression (try_expression (await_expression (identifier))) (field_identifier)) (arguments)))))) ================================================================================ Async Block ================================================================================ async {} async { let x = 10; } async move {} -------------------------------------------------------------------------------- (source_file (expression_statement (async_block (block))) (expression_statement (async_block (block (let_declaration (identifier) (integer_literal))))) (expression_statement (async_block (block)))) ================================================================================ Async closure ================================================================================ let _ = async || (); -------------------------------------------------------------------------------- (source_file (let_declaration (closure_expression (closure_parameters) (unit_expression)))) ================================================================================ Async move async move closure ================================================================================ let a = async move || async move {}; -------------------------------------------------------------------------------- (source_file (let_declaration (identifier) (closure_expression (closure_parameters) (async_block (block))))) ================================================================================ Try Block ================================================================================ try {} -------------------------------------------------------------------------------- (source_file (expression_statement (try_block (block)))) ================================================================================ Gen Block ================================================================================ gen {} gen { let x = 10; } gen { yield (); } gen move {} -------------------------------------------------------------------------------- (source_file (expression_statement (gen_block (block))) (expression_statement (gen_block (block (let_declaration (identifier) (integer_literal))))) (expression_statement (gen_block (block (expression_statement (yield_expression (unit_expression)))))) (expression_statement (gen_block (block)))) ================================================================================ gen fn ================================================================================ gen fn f() -> u8 { yield 42; yield; } -------------------------------------------------------------------------------- (source_file (function_item (function_modifiers) (identifier) (parameters) (primitive_type) (block (expression_statement (yield_expression (integer_literal))) (expression_statement (yield_expression))))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/declarations.txt000066400000000000000000002357071516074642400246170ustar00rootroot00000000000000================================================================================ Modules ================================================================================ mod english; mod english {} mod english { mod greetings {} mod farewells {} } pub mod english; -------------------------------------------------------------------------------- (source_file (mod_item (identifier)) (mod_item (identifier) (declaration_list)) (mod_item (identifier) (declaration_list (mod_item (identifier) (declaration_list)) (mod_item (identifier) (declaration_list)))) (mod_item (visibility_modifier) (identifier))) ================================================================================ Extern crate declarations ================================================================================ extern crate std; extern crate std as ruststd; pub extern crate futures; -------------------------------------------------------------------------------- (source_file (extern_crate_declaration (crate) (identifier)) (extern_crate_declaration (crate) (identifier) (identifier)) (extern_crate_declaration (visibility_modifier) (crate) (identifier))) ================================================================================ Function declarations ================================================================================ fn main() {} fn add(x: i32, y: i32) -> i32 { return x + y; } fn takes_slice(slice: &str) { println!("Got: {}", slice); } fn foo() -> [u32; 2] { return [1, 2]; } fn foo() -> (u32, u16) { return (1, 2); } fn foo() { return } fn foo(x: impl FnOnce() -> result::Result) {} fn foo(#[attr] x: i32, #[attr] x: i64) {} fn accumulate(self) -> Machine<{State::Accumulate}> {} fn foo(bar: impl for<'a> Baz>) {} -------------------------------------------------------------------------------- (source_file (function_item name: (identifier) parameters: (parameters) body: (block)) (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (primitive_type)) (parameter pattern: (identifier) type: (primitive_type))) return_type: (primitive_type) body: (block (expression_statement (return_expression (binary_expression left: (identifier) right: (identifier)))))) (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (reference_type type: (primitive_type)))) body: (block (expression_statement (macro_invocation macro: (identifier) (token_tree (string_literal (string_content)) (identifier)))))) (function_item name: (identifier) parameters: (parameters) return_type: (array_type element: (primitive_type) length: (integer_literal)) body: (block (expression_statement (return_expression (array_expression (integer_literal) (integer_literal)))))) (function_item name: (identifier) parameters: (parameters) return_type: (tuple_type (primitive_type) (primitive_type)) body: (block (expression_statement (return_expression (tuple_expression (integer_literal) (integer_literal)))))) (function_item name: (identifier) parameters: (parameters) body: (block (return_expression))) (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (abstract_type trait: (function_type trait: (type_identifier) parameters: (parameters) return_type: (generic_type type: (scoped_type_identifier path: (identifier) name: (type_identifier)) type_arguments: (type_arguments (type_identifier) (type_identifier))))))) body: (block)) (function_item name: (identifier) parameters: (parameters (parameter attributes: (attributes (attribute_item (attribute (identifier)))) pattern: (identifier) type: (primitive_type)) (parameter attributes: (attributes (attribute_item (attribute (identifier)))) pattern: (identifier) type: (primitive_type))) body: (block)) (function_item name: (identifier) parameters: (parameters (self_parameter (self))) return_type: (generic_type type: (type_identifier) type_arguments: (type_arguments (block (scoped_identifier path: (identifier) name: (identifier))))) body: (block)) (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (abstract_type (type_parameters (lifetime_parameter name: (lifetime (identifier)))) trait: (generic_type type: (type_identifier) type_arguments: (type_arguments (generic_type type: (type_identifier) type_arguments: (type_arguments (lifetime (identifier))))))))) body: (block))) ================================================================================ Const function declarations ================================================================================ const fn main() {} -------------------------------------------------------------------------------- (source_file (function_item (function_modifiers) (identifier) (parameters) (block))) ================================================================================ Functions with abstract return types ================================================================================ fn triples(a: impl B) -> impl Iterator { } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (parameter (identifier) (abstract_type (type_identifier)))) (abstract_type (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (tuple_type (primitive_type)))))) (block))) ================================================================================ Impl with lifetimes first ================================================================================ fn foo<'a>(x: impl 'a + Clone) {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (type_parameters (lifetime_parameter (lifetime (identifier)))) (parameters (parameter (identifier) (abstract_type (bounded_type (lifetime (identifier)) (type_identifier))))) (block))) ================================================================================ Functions with precise capture syntax ================================================================================ fn capture(&self) -> impl Iterator + use<'_, T> { } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (type_parameters (type_parameter (type_identifier))) (parameters (self_parameter (self))) (bounded_type (abstract_type (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (primitive_type))))) (use_bounds (lifetime (identifier)) (type_identifier))) (block))) ================================================================================ Functions with empty precise capture syntax ================================================================================ fn capture(&self) -> impl Iterator + use<> { } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (self_parameter (self))) (bounded_type (abstract_type (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (primitive_type))))) (use_bounds)) (block))) ================================================================================ Diverging functions ================================================================================ fn aborts() -> ! {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (never_type) (block))) ================================================================================ Extern function declarations ================================================================================ extern "C" fn foo() {} extern "C" fn printf( *const c_char, ..., ) {} pub unsafe extern "C" fn c_variadic_no_use(fmt: *const i8, mut ap: ...) -> i32 { // CHECK: call void @llvm.va_start vprintf(fmt, ap.as_va_list()) // CHECK: call void @llvm.va_end } -------------------------------------------------------------------------------- (source_file (function_item (function_modifiers (extern_modifier (string_literal (string_content)))) (identifier) (parameters) (block)) (function_item (function_modifiers (extern_modifier (string_literal (string_content)))) (identifier) (parameters (pointer_type (type_identifier)) (variadic_parameter)) (block)) (function_item (visibility_modifier) (function_modifiers (extern_modifier (string_literal (string_content)))) (identifier) (parameters (parameter (identifier) (pointer_type (primitive_type))) (variadic_parameter (mutable_specifier) (identifier))) (primitive_type) (block (line_comment) (call_expression (identifier) (arguments (identifier) (call_expression (field_expression (identifier) (field_identifier)) (arguments)))) (line_comment)))) ================================================================================ Use declarations ================================================================================ use abc; use phrases::japanese; use sayings::english::greetings; use sayings::english::greetings as en_greetings ; use phrases::english::{greetings,farewells}; use sayings::japanese::farewells::*; pub use self::greetings::hello; use sayings::english::{self, greetings as en_greetings, farewells as en_farewells}; use three::{ dot::{one, four} }; use my::{ some::* }; use my::{*}; use ::*; -------------------------------------------------------------------------------- (source_file (use_declaration argument: (identifier)) (use_declaration argument: (scoped_identifier path: (identifier) name: (identifier))) (use_declaration argument: (scoped_identifier path: (scoped_identifier path: (identifier) name: (identifier)) name: (identifier))) (use_declaration argument: (use_as_clause path: (scoped_identifier path: (scoped_identifier path: (identifier) name: (identifier)) name: (identifier)) alias: (identifier))) (use_declaration argument: (scoped_use_list path: (scoped_identifier path: (identifier) name: (identifier)) list: (use_list (identifier) (identifier)))) (use_declaration argument: (use_wildcard (scoped_identifier path: (scoped_identifier path: (identifier) name: (identifier)) name: (identifier)))) (use_declaration (visibility_modifier) argument: (scoped_identifier path: (scoped_identifier path: (self) name: (identifier)) name: (identifier))) (use_declaration argument: (scoped_use_list path: (scoped_identifier path: (identifier) name: (identifier)) list: (use_list (self) (use_as_clause path: (identifier) alias: (identifier)) (use_as_clause path: (identifier) alias: (identifier))))) (use_declaration argument: (scoped_use_list path: (identifier) list: (use_list (scoped_use_list path: (identifier) list: (use_list (identifier) (identifier)))))) (use_declaration argument: (scoped_use_list path: (identifier) list: (use_list (use_wildcard (identifier))))) (use_declaration argument: (scoped_use_list path: (identifier) list: (use_list (use_wildcard)))) (use_declaration argument: (use_wildcard))) ================================================================================ Variable bindings ================================================================================ let x; let x = 42; let x: i32; let x: i8 = 42; let mut x = 5; let y: bool = false; let bool: bool = false; let u32: str = ""; -------------------------------------------------------------------------------- (source_file (let_declaration (identifier)) (let_declaration (identifier) (integer_literal)) (let_declaration (identifier) (primitive_type)) (let_declaration (identifier) (primitive_type) (integer_literal)) (let_declaration (mutable_specifier) (identifier) (integer_literal)) (let_declaration (identifier) (primitive_type) (boolean_literal)) (let_declaration (identifier) (primitive_type) (boolean_literal)) (let_declaration (identifier) (primitive_type) (string_literal))) ================================================================================ Let-else Statements ================================================================================ let Foo::Bar { texts, values, } = foo().bar().await? else { return Err(index) }; let Some(x) = y else { let None = z else { foo(); break; }; continue; }; -------------------------------------------------------------------------------- (source_file (let_declaration pattern: (struct_pattern type: (scoped_type_identifier path: (identifier) name: (type_identifier)) (field_pattern name: (shorthand_field_identifier)) (field_pattern name: (shorthand_field_identifier))) value: (try_expression (await_expression (call_expression function: (field_expression value: (call_expression function: (identifier) arguments: (arguments)) field: (field_identifier)) arguments: (arguments)))) alternative: (block (return_expression (call_expression function: (identifier) arguments: (arguments (identifier)))))) (let_declaration pattern: (tuple_struct_pattern type: (identifier) (identifier)) value: (identifier) alternative: (block (let_declaration pattern: (identifier) value: (identifier) alternative: (block (expression_statement (call_expression function: (identifier) arguments: (arguments))) (expression_statement (break_expression)))) (expression_statement (continue_expression))))) ================================================================================ Let declarations with if expressions as the value ================================================================================ let a = if b { c } else { d }; -------------------------------------------------------------------------------- (source_file (let_declaration (identifier) (if_expression (identifier) (block (identifier)) (else_clause (block (identifier)))))) ================================================================================ Let declarations with contextual keywords as names ================================================================================ let default = 1; let union = 2; -------------------------------------------------------------------------------- (source_file (let_declaration (identifier) (integer_literal)) (let_declaration (identifier) (integer_literal))) ================================================================================ Structs ================================================================================ struct Proton; struct Electron {} struct Person {pub name: String, pub age: u32} struct Point { x: i32, #[attribute1] y: i32, } struct Color(pub i32, i32, i32); struct Inches(i32); struct Empty(pub ()); -------------------------------------------------------------------------------- (source_file (struct_item (type_identifier)) (struct_item (type_identifier) (field_declaration_list)) (struct_item (type_identifier) (field_declaration_list (field_declaration (visibility_modifier) (field_identifier) (type_identifier)) (field_declaration (visibility_modifier) (field_identifier) (primitive_type)))) (struct_item (type_identifier) (field_declaration_list (field_declaration (field_identifier) (primitive_type)) (attributes (attribute_item (attribute (identifier)))) (field_declaration (field_identifier) (primitive_type)))) (struct_item (type_identifier) (ordered_field_declaration_list (visibility_modifier) (primitive_type) (primitive_type) (primitive_type))) (struct_item (type_identifier) (ordered_field_declaration_list (primitive_type))) (struct_item (type_identifier) (ordered_field_declaration_list (visibility_modifier) (unit_type)))) ================================================================================ Unions ================================================================================ pub union in6_addr__bindgen_ty_1 { pub __u6_addr8: [__uint8_t; 16usize], pub __u6_addr16: [__uint16_t; 8usize], pub __u6_addr32: [__uint32_t; 4usize], _bindgen_union_align: [u32; 4usize], } -------------------------------------------------------------------------------- (source_file (union_item (visibility_modifier) (type_identifier) (field_declaration_list (field_declaration (visibility_modifier) (field_identifier) (array_type (type_identifier) (integer_literal))) (field_declaration (visibility_modifier) (field_identifier) (array_type (type_identifier) (integer_literal))) (field_declaration (visibility_modifier) (field_identifier) (array_type (type_identifier) (integer_literal))) (field_declaration (field_identifier) (array_type (primitive_type) (integer_literal)))))) ================================================================================ Generic structs ================================================================================ struct A {} struct C<'a, 'b> {} struct C<'a,> {} struct D {} struct E<#[attr] T> {} -------------------------------------------------------------------------------- (source_file (struct_item name: (type_identifier) type_parameters: (type_parameters (type_parameter name: (type_identifier))) body: (field_declaration_list)) (struct_item name: (type_identifier) type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier))) (lifetime_parameter name: (lifetime (identifier)))) body: (field_declaration_list)) (struct_item name: (type_identifier) type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier)))) body: (field_declaration_list)) (struct_item name: (type_identifier) type_parameters: (type_parameters (const_parameter name: (identifier) type: (primitive_type))) body: (field_declaration_list)) (struct_item name: (type_identifier) type_parameters: (type_parameters attributes: (attributes (attribute_item (attribute (identifier)))) (type_parameter name: (type_identifier))) body: (field_declaration_list))) ================================================================================ Enums ================================================================================ pub enum Option { None, Some(T), } pub enum Node { Internal { children: Vec>, height: u16 }, #[attribute1] #[attribute2] Leaf { value: T } } -------------------------------------------------------------------------------- (source_file (enum_item (visibility_modifier) (type_identifier) (type_parameters (type_parameter (type_identifier))) (enum_variant_list (enum_variant (identifier)) (enum_variant (identifier) (ordered_field_declaration_list (type_identifier))))) (enum_item (visibility_modifier) (type_identifier) (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier)))) (enum_variant_list (enum_variant (identifier) (field_declaration_list (field_declaration (field_identifier) (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier)))))) (field_declaration (field_identifier) (primitive_type)))) (enum_variant (attributes (attribute_item (attribute (identifier))) (attribute_item (attribute (identifier)))) (identifier) (field_declaration_list (field_declaration (field_identifier) (type_identifier))))))) ================================================================================ Enums with values specified ================================================================================ pub enum c_style_enum { val1 = 1, val2 = 2 } -------------------------------------------------------------------------------- (source_file (enum_item (visibility_modifier) (type_identifier) (enum_variant_list (enum_variant (identifier) (integer_literal)) (enum_variant (identifier) (integer_literal))))) ================================================================================ Generic functions ================================================================================ pub fn splice>(&mut self, old_range: Range, new_text: T) { } pub fn uninit_array() -> [Self; LEN] {} -------------------------------------------------------------------------------- (source_file (function_item (visibility_modifier) name: (identifier) type_parameters: (type_parameters (type_parameter name: (type_identifier) bounds: (trait_bounds (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier)))))) parameters: (parameters (self_parameter (mutable_specifier) (self)) (parameter pattern: (identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (primitive_type)))) (parameter pattern: (identifier) type: (type_identifier))) body: (block)) (function_item (visibility_modifier) name: (identifier) type_parameters: (type_parameters (const_parameter name: (identifier) type: (primitive_type))) parameters: (parameters) return_type: (array_type element: (type_identifier) length: (identifier)) body: (block))) ================================================================================ Functions with mutable parameters ================================================================================ fn foo(mut x : u32) { } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (parameter (mutable_specifier) (identifier) (primitive_type))) (block))) ================================================================================ Functions with destructured parameters ================================================================================ fn f1([x, y]: [u32; 2]) {} fn f2(&x: &Y) {} fn f3((x, y): (T, U)) {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (parameter (slice_pattern (identifier) (identifier)) (array_type (primitive_type) (integer_literal)))) (block)) (function_item (identifier) (parameters (parameter (reference_pattern (identifier)) (reference_type (type_identifier)))) (block)) (function_item (identifier) (parameters (parameter (tuple_pattern (identifier) (identifier)) (tuple_type (type_identifier) (type_identifier)))) (block))) ================================================================================ Functions with custom types for self ================================================================================ trait Callback { fn call(self: Box); } -------------------------------------------------------------------------------- (source_file (trait_item (type_identifier) (declaration_list (function_signature_item (identifier) (parameters (parameter (self) (generic_type (type_identifier) (type_arguments (type_identifier))))))))) ================================================================================ Constant items ================================================================================ const N: i32 = 5; trait Foo { const X: u8; } -------------------------------------------------------------------------------- (source_file (const_item (identifier) (primitive_type) (integer_literal)) (trait_item (type_identifier) (declaration_list (const_item (identifier) (primitive_type))))) ================================================================================ Static items ================================================================================ static N: i32 = 5; static mut __progname: *mut ::c_char; -------------------------------------------------------------------------------- (source_file (static_item (identifier) (primitive_type) (integer_literal)) (static_item (mutable_specifier) (identifier) (pointer_type (mutable_specifier) (scoped_type_identifier (type_identifier))))) ================================================================================ Static 'ref' items using lazy_static ================================================================================ static ref ONE: usize = 0; -------------------------------------------------------------------------------- (source_file (static_item (identifier) (primitive_type) (integer_literal))) ================================================================================ Type aliases ================================================================================ type Inch = u64; type Name = Vec; type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; type Bike = Vehicle<>; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (primitive_type)) (type_item (type_identifier) (type_parameters (type_parameter (type_identifier))) (generic_type (type_identifier) (type_arguments (type_identifier)))) (type_item (type_identifier) (bounded_type (bounded_type (bounded_type (abstract_type (tuple_type (function_type (type_identifier) (parameters) (type_identifier)))) (type_identifier)) (type_identifier)) (type_identifier))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments)))) ================================================================================ Type alias where clauses ================================================================================ type Foo where T: Copy = Box; type Assoc3 where = () where; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (type_parameters (type_parameter (type_identifier))) (where_clause (where_predicate (type_identifier) (trait_bounds (type_identifier)))) (generic_type (type_identifier) (type_arguments (type_identifier)))) (type_item (type_identifier) (where_clause) (unit_type) (where_clause))) ================================================================================ Empty statements ================================================================================ fn main() { ; } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (empty_statement)))) ================================================================================ Attributes ================================================================================ #[test] fn test_foo() {} #[derive(Debug)] struct Baz; #[derive(Debug, Eq,)] struct Foo; #[cfg(target_os = "macos")] mod macos_only {} enum Foo { #[cfg(foo)] Variant } #![allow(clippy::useless_transmute)] fn expressions_with_attributes() { #[cfg(test)] { foo(); } #[bar] hello(#[world] 1); #[decl] let x = [ #[first] 1, #[second] #[last] 2 ]; } -------------------------------------------------------------------------------- (source_file (function_item attributes: (attributes (attribute_item (attribute (identifier)))) name: (identifier) parameters: (parameters) body: (block)) (struct_item attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier))))) name: (type_identifier)) (struct_item attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier) (identifier))))) name: (type_identifier)) (mod_item attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier) (string_literal (string_content)))))) name: (identifier) body: (declaration_list)) (enum_item name: (type_identifier) body: (enum_variant_list (enum_variant (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier))))) name: (identifier)))) (inner_attribute_item (attribute (identifier) arguments: (token_tree (identifier) (identifier)))) (function_item name: (identifier) parameters: (parameters) body: (block (expression_statement (block_expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier))))) expression: (block (expression_statement (call_expression function: (identifier) arguments: (arguments)))))) (expression_statement (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier)))) expression: (call_expression function: (identifier) arguments: (arguments (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier)))) expression: (integer_literal)))))) (let_declaration attributes: (attributes (attribute_item (attribute (identifier)))) pattern: (identifier) value: (array_expression (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier)))) expression: (integer_literal)) (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier))) (attribute_item (attribute (identifier)))) expression: (integer_literal))))))) ================================================================================ Inner attributes ================================================================================ mod macos_only { #![cfg(target_os = "macos")] } match ty { #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] syn::Type::Array(ty) => self.visit_type(&ty.elem), } -------------------------------------------------------------------------------- (source_file (mod_item name: (identifier) body: (declaration_list (inner_attribute_item (attribute (identifier) arguments: (token_tree (identifier) (string_literal (string_content))))))) (expression_statement (match_expression value: (identifier) body: (match_block (inner_attribute_item (attribute (identifier) arguments: (token_tree (identifier) (token_tree (identifier) (identifier)) (identifier) (token_tree (identifier))))) (match_arm pattern: (match_pattern (tuple_struct_pattern type: (scoped_identifier path: (scoped_identifier path: (identifier) name: (identifier)) name: (identifier)) (identifier))) value: (call_expression function: (field_expression value: (self) field: (field_identifier)) arguments: (arguments (reference_expression value: (field_expression value: (identifier) field: (field_identifier)))))))))) ================================================================================ Key-Value Attribute Expressions ================================================================================ #[doc = include_str!("foo-doc.md")] fn foo() {} #[namespace = foo::bar] fn baz() {} -------------------------------------------------------------------------------- (source_file (function_item (attributes (attribute_item (attribute (identifier) (macro_invocation (identifier) (token_tree (string_literal (string_content))))))) (identifier) (parameters) (block)) (function_item (attributes (attribute_item (attribute (identifier) (scoped_identifier (identifier) (identifier))))) (identifier) (parameters) (block))) ================================================================================ Attribute macros ================================================================================ foo(#[attr(=> arbitrary tokens <=)] x, y); foo(#[bar(some tokens are special in other contexts: $/';()*()+.)] x); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression function: (identifier) arguments: (arguments (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier) (identifier))))) expression: (identifier)) (identifier)))) (expression_statement (call_expression function: (identifier) arguments: (arguments (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier) (identifier) (identifier) (identifier) (identifier) (identifier) (identifier) (token_tree) (token_tree))))) expression: (identifier)))))) ================================================================================ Derive macro helper attributes ================================================================================ // Example from https://github.com/dtolnay/thiserror/blob/21c26903e29cb92ba1a7ff11e82ae2001646b60d/README.md use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[error("first letter must be lowercase but was {:?}", first_char(.0))] WrongCase(String), #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)] OutOfBounds { idx: usize, limits: Limits }, } -------------------------------------------------------------------------------- (source_file (line_comment) (use_declaration (scoped_identifier (identifier) (identifier))) (enum_item (attributes (attribute_item (attribute (identifier) (token_tree (identifier) (identifier))))) (visibility_modifier) (type_identifier) (enum_variant_list (enum_variant (attributes (attribute_item (attribute (identifier) (token_tree (string_literal (string_content)) (identifier) (token_tree (integer_literal)))))) (identifier) (ordered_field_declaration_list (type_identifier))) (enum_variant (attributes (attribute_item (attribute (identifier) (token_tree (string_literal (string_content)) (identifier) (identifier) (identifier) (identifier))))) (identifier) (field_declaration_list (field_declaration (field_identifier) (primitive_type)) (field_declaration (field_identifier) (type_identifier))))))) ================================================================================ Attributes and Expressions ================================================================================ fn foo() { bar(x, #[cfg(foo = "bar")] y); let z = [#[hello] 2, 7, 8]; let t = (#[hello] 2, 7, 8); } -------------------------------------------------------------------------------- (source_file (function_item name: (identifier) parameters: (parameters) body: (block (expression_statement (call_expression function: (identifier) arguments: (arguments (identifier) (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier) (string_literal (string_content)))))) expression: (identifier))))) (let_declaration pattern: (identifier) value: (array_expression (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier)))) expression: (integer_literal)) (integer_literal) (integer_literal))) (let_declaration pattern: (identifier) value: (tuple_expression (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier)))) expression: (integer_literal)) (integer_literal) (integer_literal)))))) ================================================================================ Inherent Impls ================================================================================ impl Person { const leg_count : u32 = 2; fn walk(self) {} fn walk_mut(mut self) {} fn talk(& self) {} fn talk_mut(&'a mut self) {} } impl Machine<{State::Init}> {} -------------------------------------------------------------------------------- (source_file (impl_item type: (type_identifier) body: (declaration_list (const_item name: (identifier) type: (primitive_type) value: (integer_literal)) (function_item name: (identifier) parameters: (parameters (self_parameter (self))) body: (block)) (function_item name: (identifier) parameters: (parameters (self_parameter (mutable_specifier) (self))) body: (block)) (function_item name: (identifier) parameters: (parameters (self_parameter (self))) body: (block)) (function_item name: (identifier) parameters: (parameters (self_parameter (lifetime (identifier)) (mutable_specifier) (self))) body: (block)))) (impl_item type: (generic_type type: (type_identifier) type_arguments: (type_arguments (block (scoped_identifier path: (identifier) name: (identifier))))) body: (declaration_list))) ================================================================================ Trait impls ================================================================================ impl<'a> iter::Iterator for Self::Iter<'a> { } impl ConvertTo for i32 { fn convert(&self) -> i64 { *self as i64 } } -------------------------------------------------------------------------------- (source_file (impl_item type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier)))) trait: (scoped_type_identifier path: (identifier) name: (type_identifier)) type: (generic_type type: (scoped_type_identifier path: (identifier) name: (type_identifier)) type_arguments: (type_arguments (lifetime (identifier)))) body: (declaration_list)) (impl_item trait: (generic_type type: (type_identifier) type_arguments: (type_arguments (primitive_type))) type: (primitive_type) body: (declaration_list (function_item name: (identifier) parameters: (parameters (self_parameter (self))) return_type: (primitive_type) body: (block (type_cast_expression value: (unary_expression (self)) type: (primitive_type))))))) ================================================================================ Unsafe impls ================================================================================ unsafe impl Foo { } -------------------------------------------------------------------------------- (source_file (impl_item (type_identifier) (declaration_list))) ================================================================================ Const impls ================================================================================ impl const Foo for Bar { } -------------------------------------------------------------------------------- (source_file (impl_item (type_identifier) (type_identifier) (declaration_list))) ================================================================================ Disable automatically derived trait impls ================================================================================ impl !Send for Foo {} -------------------------------------------------------------------------------- (source_file (impl_item (type_identifier) (type_identifier) (declaration_list))) ================================================================================ Impl dyn with parentheses ================================================================================ pub unsafe trait Trait {} unsafe impl Trait for dyn (::std::any::Any) + Send { } -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (declaration_list)) (impl_item (type_identifier) (bounded_type (dynamic_type (tuple_type (scoped_type_identifier (scoped_identifier (scoped_identifier (identifier)) (identifier)) (type_identifier)))) (type_identifier)) (declaration_list))) ================================================================================ Trait impl signature ================================================================================ impl Debug for OccupiedError; impl Display for OccupiedError; -------------------------------------------------------------------------------- (source_file (impl_item (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier) (type_identifier)))) (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier)))) (impl_item (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier) (type_identifier)))) (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) ================================================================================ Impls with default functions ================================================================================ impl Foo { const default fn bar() -> i32 { // Make 'default' still works as an identifier default.bar(); } } -------------------------------------------------------------------------------- (source_file (impl_item (type_identifier) (declaration_list (function_item (function_modifiers) (identifier) (parameters) (primitive_type) (block (line_comment) (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments)))))))) ================================================================================ Trait declarations ================================================================================ pub trait Item: Clone + Eq + fmt::Debug { fn summarize(&self) -> Self::Summary; } unsafe trait Foo { } unsafe auto trait Bar { } -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (trait_bounds (type_identifier) (type_identifier) (scoped_type_identifier (identifier) (type_identifier))) (declaration_list (function_signature_item (identifier) (parameters (self_parameter (self))) (scoped_type_identifier (identifier) (type_identifier))))) (trait_item (type_identifier) (declaration_list)) (trait_item (type_identifier) (declaration_list))) ================================================================================ Trait aliases ================================================================================ pub trait StrLike = AsRef; pub trait StrLike2 = StrLike + Sync; -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (generic_type (type_identifier) (type_arguments (primitive_type)))) (trait_item (visibility_modifier) (type_identifier) (bounded_type (type_identifier) (type_identifier)))) ================================================================================ Trait declarations with optional type parameters ================================================================================ trait Add { type Output; fn add(self, rhs: RHS) -> Self::Output; } -------------------------------------------------------------------------------- (source_file (trait_item (type_identifier) (type_parameters (type_parameter (type_identifier) (type_identifier))) (declaration_list (type_item (type_identifier)) (function_signature_item (identifier) (parameters (self_parameter (self)) (parameter (identifier) (type_identifier))) (scoped_type_identifier (identifier) (type_identifier)))))) ================================================================================ Unsized types in trait bounds ================================================================================ trait Foo { } fn univariant(this: &impl ?Sized, that: &(impl LayoutCalculator + ?Sized)) {} -------------------------------------------------------------------------------- (source_file (trait_item (type_identifier) (type_parameters (type_parameter (type_identifier) (trait_bounds (removed_trait_bound (type_identifier))))) (declaration_list)) (function_item (identifier) (parameters (parameter (identifier) (reference_type (abstract_type (removed_trait_bound (type_identifier))))) (parameter (identifier) (reference_type (tuple_type (bounded_type (abstract_type (type_identifier)) (removed_trait_bound (type_identifier))))))) (block))) ================================================================================ Trait bounds in type arguments in trait ================================================================================ impl> HasNodeId for T {} -------------------------------------------------------------------------------- (source_file (impl_item (type_parameters (type_parameter (type_identifier) (trait_bounds (generic_type (type_identifier) (type_arguments (type_identifier) (trait_bounds (type_identifier))))))) (type_identifier) (type_identifier) (declaration_list))) ================================================================================ Trait bounds with modifiers ================================================================================ impl Foo for Bar {} impl Foo for Bar {} -------------------------------------------------------------------------------- (source_file (impl_item (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier)))) (type_identifier) (type_identifier) (declaration_list)) (impl_item (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier)))) (type_identifier) (type_identifier) (declaration_list))) ================================================================================ Macro invocations inside trait declarations ================================================================================ pub trait A: B + C + D { private_decl!{} fn f(&self); } -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (trait_bounds (type_identifier) (type_identifier) (type_identifier)) (declaration_list (macro_invocation_item (macro_invocation (identifier) (token_tree))) (function_signature_item (identifier) (parameters (self_parameter (self))))))) ================================================================================ Associated Types ================================================================================ pub trait Graph { type N: fmt::Display; type E; } -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (declaration_list (type_item (type_identifier) (trait_bounds (scoped_type_identifier (identifier) (type_identifier)))) (type_item (type_identifier))))) ================================================================================ Associated Type Definitions ================================================================================ impl Trait for T { type Associated = T where 'static: 'static; } -------------------------------------------------------------------------------- (source_file (impl_item (type_identifier) (type_identifier) (declaration_list (type_item (type_identifier) (type_identifier) (where_clause (where_predicate (lifetime (identifier)) (trait_bounds (lifetime (identifier))))))))) ================================================================================ Generic Associated Types ================================================================================ pub trait Database { type F<'a, D>: Future + 'a; } impl Database for Foo { type F<'a, D> = DatabaseFuture<'a, D>; } fn use_database1 = F>>() {} fn use_database2() where D: Database = F>, {} -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (declaration_list (type_item (type_identifier) (type_parameters (lifetime_parameter (lifetime (identifier))) (type_parameter (type_identifier))) (trait_bounds (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (type_identifier)))) (lifetime (identifier)))))) (impl_item (type_identifier) (type_identifier) (declaration_list (type_item (type_identifier) (type_parameters (lifetime_parameter (lifetime (identifier))) (type_parameter (type_identifier))) (generic_type (type_identifier) (type_arguments (lifetime (identifier)) (type_identifier)))))) (function_item (identifier) (type_parameters (type_parameter (type_identifier) (trait_bounds (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (type_arguments (lifetime (identifier)) (type_identifier)) (type_identifier))))))) (parameters) (block)) (function_item (identifier) (type_parameters (type_parameter (type_identifier))) (parameters) (where_clause (where_predicate (type_identifier) (trait_bounds (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (type_arguments (lifetime (identifier)) (type_identifier)) (type_identifier))))))) (block))) ================================================================================ Associated types with defaults ================================================================================ pub trait TypeVisitor: Sized { type Result: Foo = (); } -------------------------------------------------------------------------------- (source_file (trait_item (visibility_modifier) (type_identifier) (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier)))) (trait_bounds (type_identifier)) (declaration_list (type_item (type_identifier) (trait_bounds (type_identifier)) (unit_type))))) ================================================================================ Extern types ================================================================================ extern { pub type Opaque; } -------------------------------------------------------------------------------- (source_file (foreign_mod_item (extern_modifier) (declaration_list (type_item (visibility_modifier) (type_identifier))))) ================================================================================ Higher-ranked types ================================================================================ trait T: for<'a> AddAssign<&'a usize> { } type FnObject<'b> = dyn for<'a> FnLike<&'a isize, &'a isize> + 'b; -------------------------------------------------------------------------------- (source_file (trait_item (type_identifier) (trait_bounds (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier)))) (generic_type (type_identifier) (type_arguments (reference_type (lifetime (identifier)) (primitive_type)))))) (declaration_list)) (type_item (type_identifier) (type_parameters (lifetime_parameter (lifetime (identifier)))) (bounded_type (dynamic_type (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier)))) (generic_type (type_identifier) (type_arguments (reference_type (lifetime (identifier)) (primitive_type)) (reference_type (lifetime (identifier)) (primitive_type)))))) (lifetime (identifier))))) ================================================================================ Visibility modifiers ================================================================================ pub fn a() {} pub(super) fn b() {} pub(self) fn c() {} pub(crate) fn c() {} pub(in crate::d) fn e() {} -------------------------------------------------------------------------------- (source_file (function_item (visibility_modifier) (identifier) (parameters) (block)) (function_item (visibility_modifier (super)) (identifier) (parameters) (block)) (function_item (visibility_modifier (self)) (identifier) (parameters) (block)) (function_item (visibility_modifier (crate)) (identifier) (parameters) (block)) (function_item (visibility_modifier (scoped_identifier (crate) (identifier))) (identifier) (parameters) (block))) ================================================================================ Function parameter names that match built-in type names ================================================================================ fn foo(str: *const c_char) {} fn bar(bool: bool) {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (parameter (identifier) (pointer_type (type_identifier)))) (block)) (function_item (identifier) (parameters (parameter (identifier) (primitive_type))) (block))) ================================================================================ Where clauses ================================================================================ fn walk(&self, it: &mut F) -> bool where F: FnMut(&Pat) -> bool { return false } impl<'a, T: 'a + Item> Iterator for Iter<'a, T> where Self: 'a { } impl A for B where C: D, T: 'c, 'c: 'b, { } impl<'a, E> Read where &'a E: Read, { } impl A for B where (T, T, T): C, {} impl A for B where for<'a> D: E<'a>, { } fn g() where dyn 'static: 'static + Copy, { } pub trait A where B: C, { } fn foo() where A: B + As, f64: As {} impl Default for B where *mut A: C + D {} struct A where i32: Copy; -------------------------------------------------------------------------------- (source_file (function_item name: (identifier) type_parameters: (type_parameters (type_parameter name: (type_identifier))) parameters: (parameters (self_parameter (self)) (parameter pattern: (identifier) type: (reference_type (mutable_specifier) type: (type_identifier)))) return_type: (primitive_type) (where_clause (where_predicate left: (type_identifier) bounds: (trait_bounds (function_type trait: (type_identifier) parameters: (parameters (reference_type type: (type_identifier))) return_type: (primitive_type))))) body: (block (return_expression (boolean_literal)))) (impl_item type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier))) (type_parameter name: (type_identifier) bounds: (trait_bounds (lifetime (identifier)) (type_identifier)))) trait: (type_identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (lifetime (identifier)) (type_identifier))) (where_clause (where_predicate left: (type_identifier) bounds: (trait_bounds (lifetime (identifier))))) body: (declaration_list)) (impl_item type_parameters: (type_parameters (type_parameter name: (type_identifier))) trait: (type_identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier))) (where_clause (where_predicate left: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier))) bounds: (trait_bounds (type_identifier))) (where_predicate left: (type_identifier) bounds: (trait_bounds (lifetime (identifier)))) (where_predicate left: (lifetime (identifier)) bounds: (trait_bounds (lifetime (identifier))))) body: (declaration_list)) (impl_item type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier))) (type_parameter name: (type_identifier))) type: (type_identifier) (where_clause (where_predicate left: (reference_type (lifetime (identifier)) type: (type_identifier)) bounds: (trait_bounds (type_identifier)))) body: (declaration_list)) (impl_item type_parameters: (type_parameters (type_parameter name: (type_identifier))) trait: (type_identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier))) (where_clause (where_predicate left: (tuple_type (type_identifier) (type_identifier) (type_identifier)) bounds: (trait_bounds (type_identifier)))) body: (declaration_list)) (impl_item type_parameters: (type_parameters (type_parameter name: (type_identifier))) trait: (type_identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier))) (where_clause (where_predicate left: (higher_ranked_trait_bound type_parameters: (type_parameters (lifetime_parameter name: (lifetime (identifier)))) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier)))) bounds: (trait_bounds (generic_type type: (type_identifier) type_arguments: (type_arguments (lifetime (identifier))))))) body: (declaration_list)) (function_item name: (identifier) parameters: (parameters) (where_clause (where_predicate left: (dynamic_type trait: (lifetime (identifier))) bounds: (trait_bounds (lifetime (identifier)) (type_identifier)))) body: (block)) (trait_item (visibility_modifier) name: (type_identifier) type_parameters: (type_parameters (type_parameter name: (type_identifier))) (where_clause (where_predicate left: (type_identifier) bounds: (trait_bounds (type_identifier)))) body: (declaration_list)) (function_item name: (identifier) type_parameters: (type_parameters (type_parameter name: (type_identifier))) parameters: (parameters) (where_clause (where_predicate left: (type_identifier) bounds: (trait_bounds (type_identifier) (generic_type type: (type_identifier) type_arguments: (type_arguments (primitive_type))))) (where_predicate left: (primitive_type) bounds: (trait_bounds (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier)))))) body: (block)) (impl_item type_parameters: (type_parameters (type_parameter name: (type_identifier))) trait: (type_identifier) type: (generic_type type: (type_identifier) type_arguments: (type_arguments (type_identifier))) (where_clause (where_predicate left: (pointer_type (mutable_specifier) type: (type_identifier)) bounds: (trait_bounds (type_identifier) (type_identifier)))) body: (declaration_list)) (struct_item name: (type_identifier) (where_clause (where_predicate left: (primitive_type) bounds: (trait_bounds (type_identifier)))))) ================================================================================ Empty bounds in where clauses ================================================================================ pub fn empty<'b, U>() where U:, 'b:, {} -------------------------------------------------------------------------------- (source_file (function_item (visibility_modifier) (identifier) (type_parameters (lifetime_parameter (lifetime (identifier))) (type_parameter (type_identifier))) (parameters) (where_clause (where_predicate (type_identifier) (trait_bounds)) (where_predicate (lifetime (identifier)) (trait_bounds))) (block))) ================================================================================ External Modules ================================================================================ pub extern "C" { pub fn napi_module_register(mod_: *mut napi_module); } extern { } extern "C" {} unsafe extern "C" {} -------------------------------------------------------------------------------- (source_file (foreign_mod_item (visibility_modifier) (extern_modifier (string_literal (string_content))) (declaration_list (function_signature_item (visibility_modifier) (identifier) (parameters (parameter (identifier) (pointer_type (mutable_specifier) (type_identifier))))))) (foreign_mod_item (extern_modifier) (declaration_list)) (foreign_mod_item (extern_modifier (string_literal (string_content))) (declaration_list)) (foreign_mod_item (extern_modifier (string_literal (string_content))) (declaration_list))) ================================================================================ Extern declarations with raw string literals ================================================================================ extern r#"C"# fn foo() {} extern r#"C"# { fn bar(); } type T = extern r#"C"# fn(); -------------------------------------------------------------------------------- (source_file (function_item (function_modifiers (extern_modifier (raw_string_literal (string_content)))) (identifier) (parameters) (block)) (foreign_mod_item (extern_modifier (raw_string_literal (string_content))) (declaration_list (function_signature_item (identifier) (parameters)))) (type_item (type_identifier) (function_type (function_modifiers (extern_modifier (raw_string_literal (string_content)))) (parameters)))) ================================================================================ Crate visibility ================================================================================ crate mod foo; crate struct Foo(crate crate::Bar); crate fn foo() { } crate const X: u32 = 0; -------------------------------------------------------------------------------- (source_file (mod_item (visibility_modifier (crate)) (identifier)) (struct_item (visibility_modifier (crate)) (type_identifier) (ordered_field_declaration_list (visibility_modifier (crate)) (scoped_type_identifier (crate) (type_identifier)))) (function_item (visibility_modifier (crate)) (identifier) (parameters) (block)) (const_item (visibility_modifier (crate)) (identifier) (primitive_type) (integer_literal))) ================================================================================ Reserved keywords in path ================================================================================ struct A { a: default::B, b: union::C, } -------------------------------------------------------------------------------- (source_file (struct_item (type_identifier) (field_declaration_list (field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier))) (field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier)))))) ================================================================================ Function constraint in where clause ================================================================================ fn some_fun(t: fn(&A)) where fn(&A) : for<'a> Foo<(&'a A,)>, {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (type_parameters (type_parameter (type_identifier))) (parameters (parameter (identifier) (function_type (parameters (reference_type (type_identifier)))))) (where_clause (where_predicate (function_type (parameters (reference_type (type_identifier)))) (trait_bounds (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier)))) (generic_type (type_identifier) (type_arguments (tuple_type (reference_type (lifetime (identifier)) (type_identifier))))))))) (block))) ================================================================================ Unit type in where clause ================================================================================ fn some_fun() where () : Foo, {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (where_clause (where_predicate (unit_type) (trait_bounds (type_identifier)))) (block))) ================================================================================ Array Constraint in Where Clause ================================================================================ fn foo(val: D) where [u8; 32]: From, {} -------------------------------------------------------------------------------- (source_file (function_item (identifier) (type_parameters (type_parameter (type_identifier))) (parameters (parameter (identifier) (type_identifier))) (where_clause (where_predicate (array_type (primitive_type) (integer_literal)) (trait_bounds (generic_type (type_identifier) (type_arguments (type_identifier)))))) (block))) ================================================================================ Const generics with default ================================================================================ pub struct Loaf([T; N]); -------------------------------------------------------------------------------- (source_file (struct_item (visibility_modifier) (type_identifier) (type_parameters (type_parameter (type_identifier) (trait_bounds (type_identifier))) (const_parameter (identifier) (primitive_type) (integer_literal))) (ordered_field_declaration_list (array_type (type_identifier) (identifier))))) ================================================================================ Unsafe extern blocks ================================================================================ unsafe extern "C" { pub safe fn sqrt(x: f64) -> f64; pub unsafe fn strlen(p: *const std::ffi::c_char) -> usize; pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; } -------------------------------------------------------------------------------- (source_file (foreign_mod_item (extern_modifier (string_literal (string_content))) (declaration_list (function_signature_item (visibility_modifier) (function_modifiers) (identifier) (parameters (parameter (identifier) (primitive_type))) (primitive_type)) (function_signature_item (visibility_modifier) (function_modifiers) (identifier) (parameters (parameter (identifier) (pointer_type (scoped_type_identifier (scoped_identifier (identifier) (identifier)) (type_identifier))))) (primitive_type)) (function_signature_item (visibility_modifier) (identifier) (parameters (parameter (identifier) (pointer_type (mutable_specifier) (scoped_type_identifier (scoped_identifier (identifier) (identifier)) (type_identifier)))))) (static_item (visibility_modifier) (identifier) (array_type (primitive_type) (integer_literal)))))) ================================================================================ Reserved identifiers ================================================================================ mod async {} fn auto() {} macro_rules! {} use async::auto; mod await {} fn default() {} dyn! {} use gen::macro_rules; mod raw {} fn safe() {} try! {} use union; -------------------------------------------------------------------------------- (source_file (mod_item (identifier) (declaration_list)) (function_item (identifier) (parameters) (block)) (macro_invocation_item (macro_invocation (identifier) (token_tree))) (use_declaration (scoped_identifier (identifier) (identifier))) (mod_item (identifier) (declaration_list)) (function_item (identifier) (parameters) (block)) (macro_invocation_item (macro_invocation (identifier) (token_tree))) (use_declaration (scoped_identifier (identifier) (identifier))) (mod_item (identifier) (declaration_list)) (function_item (identifier) (parameters) (block)) (macro_invocation_item (macro_invocation (identifier) (token_tree))) (use_declaration (identifier))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/error.txt000066400000000000000000000013751516074642400232700ustar00rootroot00000000000000==================================== Unexpected string literal prefixes ==================================== const A: &[&str] = &[ @"asdf", <"asdf", >"asdf", :"asdf" ]; --- (source_file (const_item name: (identifier) type: (reference_type type: (array_type element: (reference_type type: (primitive_type)))) value: (reference_expression value: (array_expression (ERROR) (string_literal (string_content)) (ERROR) (string_literal (string_content)) (ERROR) (string_literal (string_content)) (ERROR) (string_literal (string_content)))))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/expressions.txt000066400000000000000000001257721516074642400245310ustar00rootroot00000000000000================================================================================ Identifiers ================================================================================ fn main() { abc; } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (expression_statement (identifier))))) ================================================================================ Raw identifiers ================================================================================ fn main() { (r#abc as r#Def).r#ghi; } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (expression_statement (field_expression (parenthesized_expression (type_cast_expression (identifier) (type_identifier))) (field_identifier)))))) ================================================================================ Unary operator expressions ================================================================================ -num; !bits; *boxed_thing; -------------------------------------------------------------------------------- (source_file (expression_statement (unary_expression (identifier))) (expression_statement (unary_expression (identifier))) (expression_statement (unary_expression (identifier)))) ================================================================================ Reference expressions ================================================================================ &a; &mut self.name; &raw const b; &raw mut self.age; -------------------------------------------------------------------------------- (source_file (expression_statement (reference_expression (identifier))) (expression_statement (reference_expression (mutable_specifier) (field_expression (self) (field_identifier)))) (expression_statement (reference_expression (identifier))) (expression_statement (reference_expression (mutable_specifier) (field_expression (self) (field_identifier))))) ================================================================================ Try expressions ================================================================================ a.unwrap()?; &a?; -------------------------------------------------------------------------------- (source_file (expression_statement (try_expression (call_expression (field_expression (identifier) (field_identifier)) (arguments)))) (expression_statement (reference_expression (try_expression (identifier))))) ================================================================================ Binary operator expressions ================================================================================ a * b; a / b; a % b; a + b; a - b; a >> b; a << b; a == b; a && b; a || b; -------------------------------------------------------------------------------- (source_file (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier))) (expression_statement (binary_expression (identifier) (identifier)))) ================================================================================ Grouped expressions ================================================================================ (0); (2 * (3 + 4)); -------------------------------------------------------------------------------- (source_file (expression_statement (parenthesized_expression (integer_literal))) (expression_statement (parenthesized_expression (binary_expression (integer_literal) (parenthesized_expression (binary_expression (integer_literal) (integer_literal))))))) ================================================================================ Range expressions ================================================================================ 1..2; 3..; ..4; ..; 1..b; a..b; 1..(1); (1)..1; (1)..(1); 1..{1}; for i in 1.. { } -------------------------------------------------------------------------------- (source_file (expression_statement (range_expression (integer_literal) (integer_literal))) (expression_statement (range_expression (integer_literal))) (expression_statement (range_expression (integer_literal))) (expression_statement (range_expression)) (expression_statement (range_expression (integer_literal) (identifier))) (expression_statement (range_expression (identifier) (identifier))) (expression_statement (range_expression (integer_literal) (parenthesized_expression (integer_literal)))) (expression_statement (range_expression (parenthesized_expression (integer_literal)) (integer_literal))) (expression_statement (range_expression (parenthesized_expression (integer_literal)) (parenthesized_expression (integer_literal)))) (expression_statement (range_expression (integer_literal) (block (integer_literal)))) (expression_statement (for_expression (identifier) (range_expression (integer_literal)) (block)))) ================================================================================ Range expressions with leading unary operators ================================================================================ foo(..*a); foo(..!b); foo(..-c); let _ = ..*ptr; -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (identifier) (arguments (range_expression (unary_expression (identifier)))))) (expression_statement (call_expression (identifier) (arguments (range_expression (unary_expression (identifier)))))) (expression_statement (call_expression (identifier) (arguments (range_expression (unary_expression (identifier)))))) (let_declaration (range_expression (unary_expression (identifier))))) ================================================================================ Assignment expressions ================================================================================ x = y; -------------------------------------------------------------------------------- (source_file (expression_statement (assignment_expression left: (identifier) right: (identifier)))) ================================================================================ Compound assignment expressions ================================================================================ x += 1; x += y; -------------------------------------------------------------------------------- (source_file (expression_statement (compound_assignment_expr left: (identifier) right: (integer_literal))) (expression_statement (compound_assignment_expr left: (identifier) right: (identifier)))) ================================================================================ Type cast expressions ================================================================================ 1000 as u8; let character = integer as char; let size: f64 = 1.0 + -len(values) as f64 + 1.0; -------------------------------------------------------------------------------- (source_file (expression_statement (type_cast_expression value: (integer_literal) type: (primitive_type))) (let_declaration pattern: (identifier) value: (type_cast_expression value: (identifier) type: (primitive_type))) (let_declaration pattern: (identifier) type: (primitive_type) value: (binary_expression left: (binary_expression left: (float_literal) right: (type_cast_expression value: (unary_expression (call_expression function: (identifier) arguments: (arguments (identifier)))) type: (primitive_type))) right: (float_literal)))) ================================================================================ Call expressions ================================================================================ foo(); add(1i32, 2i32); add( 1i32, 2i32, ); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression function: (identifier) arguments: (arguments))) (expression_statement (call_expression function: (identifier) arguments: (arguments (integer_literal) (integer_literal)))) (expression_statement (call_expression function: (identifier) arguments: (arguments (integer_literal) (integer_literal))))) ================================================================================ Array expressions ================================================================================ []; [1, 2, 3]; ["a", "b", "c"]; [0; 128]; [ #[cfg(foo)] "foo", #[cfg(bar)] "bar", ]; -------------------------------------------------------------------------------- (source_file (expression_statement (array_expression)) (expression_statement (array_expression (integer_literal) (integer_literal) (integer_literal))) (expression_statement (array_expression (string_literal (string_content)) (string_literal (string_content)) (string_literal (string_content)))) (expression_statement (array_expression (integer_literal) length: (integer_literal))) (expression_statement (array_expression (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier))))) expression: (string_literal (string_content))) (expression_with_attribute attributes: (attributes (attribute_item (attribute (identifier) arguments: (token_tree (identifier))))) expression: (string_literal (string_content)))))) ================================================================================ Tuple expressions ================================================================================ (); (0,); let (x, y, z) = (1, 2, 3); -------------------------------------------------------------------------------- (source_file (expression_statement (unit_expression)) (expression_statement (tuple_expression (integer_literal))) (let_declaration (tuple_pattern (identifier) (identifier) (identifier)) (tuple_expression (integer_literal) (integer_literal) (integer_literal)))) ================================================================================ Struct expressions ================================================================================ NothingInMe {}; Point {x: 10.0, y: 20.0}; let a = SomeStruct { field1, field2: expression, field3, }; let u = game::User {name: "Joe", age: 35, score: 100_000}; let i = Instant { 0: Duration::from_millis(0) }; Foo { x: y, z, .. } = Foo { x: 3, z: 8, a: 6 }; -------------------------------------------------------------------------------- (source_file (expression_statement (struct_expression (type_identifier) (field_initializer_list))) (expression_statement (struct_expression (type_identifier) (field_initializer_list (field_initializer (field_identifier) (float_literal)) (field_initializer (field_identifier) (float_literal))))) (let_declaration (identifier) (struct_expression (type_identifier) (field_initializer_list (shorthand_field_initializer (identifier)) (field_initializer (field_identifier) (identifier)) (shorthand_field_initializer (identifier))))) (let_declaration (identifier) (struct_expression (scoped_type_identifier (identifier) (type_identifier)) (field_initializer_list (field_initializer (field_identifier) (string_literal (string_content))) (field_initializer (field_identifier) (integer_literal)) (field_initializer (field_identifier) (integer_literal))))) (let_declaration (identifier) (struct_expression (type_identifier) (field_initializer_list (field_initializer (integer_literal) (call_expression (scoped_identifier (identifier) (identifier)) (arguments (integer_literal))))))) (expression_statement (assignment_expression (struct_expression (type_identifier) (field_initializer_list (field_initializer (field_identifier) (identifier)) (shorthand_field_initializer (identifier)) (field_ellipsis))) (struct_expression (type_identifier) (field_initializer_list (field_initializer (field_identifier) (integer_literal)) (field_initializer (field_identifier) (integer_literal)) (field_initializer (field_identifier) (integer_literal))))))) ================================================================================ Struct expressions with update initializers ================================================================================ let u = User{name, ..current_user()}; -------------------------------------------------------------------------------- (source_file (let_declaration (identifier) (struct_expression (type_identifier) (field_initializer_list (shorthand_field_initializer (identifier)) (base_field_initializer (call_expression (identifier) (arguments))))))) ================================================================================ If expressions ================================================================================ fn main() { if n == 1 { } else if n == 2 { } else { } } let y = if x == 5 { 10 } else { 15 }; if foo && bar {} if foo && bar || baz {} -------------------------------------------------------------------------------- (source_file (function_item name: (identifier) parameters: (parameters) body: (block (expression_statement (if_expression condition: (binary_expression left: (identifier) right: (integer_literal)) consequence: (block) alternative: (else_clause (if_expression condition: (binary_expression left: (identifier) right: (integer_literal)) consequence: (block) alternative: (else_clause (block)))))))) (let_declaration pattern: (identifier) value: (if_expression condition: (binary_expression left: (identifier) right: (integer_literal)) consequence: (block (integer_literal)) alternative: (else_clause (block (integer_literal))))) (expression_statement (if_expression condition: (binary_expression left: (identifier) right: (identifier)) consequence: (block))) (expression_statement (if_expression condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) consequence: (block)))) ================================================================================ Basic if let expressions ================================================================================ if let Some(a) = b && c && d && let Some(e) = f { } -------------------------------------------------------------------------------- (source_file (expression_statement (if_expression condition: (let_chain (let_condition pattern: (tuple_struct_pattern type: (identifier) (identifier)) value: (identifier)) (identifier) (identifier) (let_condition pattern: (tuple_struct_pattern type: (identifier) (identifier)) value: (identifier))) consequence: (block)))) ================================================================================ If let expressions ================================================================================ if let ("Bacon", b) = dish { } if let Some("chained") = a && b && let (C, D) = e { } if foo && let bar = || baz && quux {} if a && let b = || c || d && e {} -------------------------------------------------------------------------------- (source_file (expression_statement (if_expression condition: (let_condition pattern: (tuple_pattern (string_literal (string_content)) (identifier)) value: (identifier)) consequence: (block))) (expression_statement (if_expression condition: (let_chain (let_condition pattern: (tuple_struct_pattern type: (identifier) (string_literal (string_content))) value: (identifier)) (identifier) (let_condition pattern: (tuple_pattern (identifier) (identifier)) value: (identifier))) consequence: (block))) (expression_statement (if_expression condition: (let_chain (identifier) (let_condition pattern: (identifier) value: (closure_expression parameters: (closure_parameters) body: (binary_expression left: (identifier) right: (identifier))))) consequence: (block))) (expression_statement (if_expression condition: (let_chain (identifier) (let_condition pattern: (identifier) value: (closure_expression parameters: (closure_parameters) body: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) consequence: (block)))) ================================================================================ Struct let expressions with attributes ================================================================================ let MyStruct { #[doc(alias = "bar")] foo } = MyStruct { foo: 123 }; -------------------------------------------------------------------------------- (source_file (let_declaration (struct_pattern (type_identifier) (attributes (attribute_item (attribute (identifier) (token_tree (identifier) (string_literal (string_content)))))) (field_pattern (shorthand_field_identifier))) (struct_expression (type_identifier) (field_initializer_list (field_initializer (field_identifier) (integer_literal)))))) ================================================================================ While let expressions ================================================================================ while let ("Bacon", b) = dish { } -------------------------------------------------------------------------------- (source_file (expression_statement (while_expression (let_condition (tuple_pattern (string_literal (string_content)) (identifier)) (identifier)) (block)))) ================================================================================ Match expressions ================================================================================ match x { 1 => { "one" } 2 => "two", -1 => 1, -3.14 => 3, #[attr1] 3 => "three", macro!(4) => "four", _ => "something else", } let msg = match x { 0 | 1 | 10 => "one of zero, one, or ten", y if y < 20 => "less than 20, but not zero, one, or ten", y if y == 200 => if a { "200 (but this is not very stylish)" } y if let Some(z) = foo && z && let Some(w) = bar => "very chained", _ => "something else", }; -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (integer_literal)) value: (block (string_literal (string_content)))) (match_arm pattern: (match_pattern (integer_literal)) value: (string_literal (string_content))) (match_arm pattern: (match_pattern (negative_literal (integer_literal))) value: (integer_literal)) (match_arm pattern: (match_pattern (negative_literal (float_literal))) value: (integer_literal)) (match_arm (attributes (attribute_item (attribute (identifier)))) pattern: (match_pattern (integer_literal)) value: (string_literal (string_content))) (match_arm pattern: (match_pattern (macro_invocation macro: (identifier) (token_tree (integer_literal)))) value: (string_literal (string_content))) (match_arm pattern: (match_pattern) value: (string_literal (string_content)))))) (let_declaration pattern: (identifier) value: (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (or_pattern (or_pattern (integer_literal) (integer_literal)) (integer_literal))) value: (string_literal (string_content))) (match_arm pattern: (match_pattern (identifier) condition: (binary_expression left: (identifier) right: (integer_literal))) value: (string_literal (string_content))) (match_arm pattern: (match_pattern (identifier) condition: (binary_expression left: (identifier) right: (integer_literal))) value: (if_expression condition: (identifier) consequence: (block (string_literal (string_content))))) (match_arm pattern: (match_pattern (identifier) condition: (let_chain (let_condition pattern: (tuple_struct_pattern type: (identifier) (identifier)) value: (identifier)) (identifier) (let_condition pattern: (tuple_struct_pattern type: (identifier) (identifier)) value: (identifier)))) value: (string_literal (string_content))) (match_arm pattern: (match_pattern) value: (string_literal (string_content))))))) ================================================================================ While expressions ================================================================================ while !done { done = true; } -------------------------------------------------------------------------------- (source_file (expression_statement (while_expression condition: (unary_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (boolean_literal))))))) ================================================================================ Loop expressions ================================================================================ 'outer: loop { 'inner: loop { break 'outer; break true; } } -------------------------------------------------------------------------------- (source_file (expression_statement (loop_expression (label (identifier)) (block (expression_statement (loop_expression (label (identifier)) (block (expression_statement (break_expression (label (identifier)))) (expression_statement (break_expression (boolean_literal)))))))))) ================================================================================ For expressions ================================================================================ for e in v { bar(e); } for i in 0..256 { bar(i); } 'outer: for x in 0..10 { 'inner: for y in 0..10 { if x % 2 == 0 { continue 'outer; } if y % 2 == 0 { continue 'inner; } } } -------------------------------------------------------------------------------- (source_file (expression_statement (for_expression (identifier) (identifier) (block (expression_statement (call_expression (identifier) (arguments (identifier))))))) (expression_statement (for_expression (identifier) (range_expression (integer_literal) (integer_literal)) (block (expression_statement (call_expression (identifier) (arguments (identifier))))))) (expression_statement (for_expression (label (identifier)) (identifier) (range_expression (integer_literal) (integer_literal)) (block (expression_statement (for_expression (label (identifier)) (identifier) (range_expression (integer_literal) (integer_literal)) (block (expression_statement (if_expression (binary_expression (binary_expression (identifier) (integer_literal)) (integer_literal)) (block (expression_statement (continue_expression (label (identifier))))))) (expression_statement (if_expression (binary_expression (binary_expression (identifier) (integer_literal)) (integer_literal)) (block (expression_statement (continue_expression (label (identifier)))))))))))))) ================================================================================ Field expressions ================================================================================ mystruct.myfield; foo().x; value.0.1.iter(); 1.max(2); 1._method(); -------------------------------------------------------------------------------- (source_file (expression_statement (field_expression (identifier) (field_identifier))) (expression_statement (field_expression (call_expression (identifier) (arguments)) (field_identifier))) (expression_statement (call_expression (field_expression (field_expression (field_expression (identifier) (integer_literal)) (integer_literal)) (field_identifier)) (arguments))) (expression_statement (call_expression (field_expression (integer_literal) (field_identifier)) (arguments (integer_literal)))) (expression_statement (call_expression (field_expression (integer_literal) (field_identifier)) (arguments)))) ================================================================================ Method call expressions ================================================================================ mystruct.foo(); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments)))) ================================================================================ Index expressions ================================================================================ ([1, 2, 3, 4])[0]; arr[10]; arr[n]; -------------------------------------------------------------------------------- (source_file (expression_statement (index_expression (parenthesized_expression (array_expression (integer_literal) (integer_literal) (integer_literal) (integer_literal))) (integer_literal))) (expression_statement (index_expression (identifier) (integer_literal))) (expression_statement (index_expression (identifier) (identifier)))) ================================================================================ Scoped functions ================================================================================ a::b(); C::::e(); ::f(); ::g::h(); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (scoped_identifier (identifier) (identifier)) (arguments))) (expression_statement (call_expression (scoped_identifier (generic_type (type_identifier) (type_arguments (type_identifier))) (identifier)) (arguments))) (expression_statement (call_expression (scoped_identifier (identifier)) (arguments))) (expression_statement (call_expression (scoped_identifier (scoped_identifier (identifier)) (identifier)) (arguments)))) ================================================================================ Scoped functions with fully qualified syntax ================================================================================ ::eat(d); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (scoped_identifier (bracketed_type (qualified_type (type_identifier) (type_identifier))) (identifier)) (arguments (identifier))))) ================================================================================ Scoped functions with macros as types ================================================================================ ::foo(); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (scoped_identifier (bracketed_type (macro_invocation (identifier) (token_tree))) (identifier)) (arguments)))) ================================================================================ Scoped identifier with nested super ================================================================================ super::super::foo(); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (scoped_identifier (scoped_identifier (super) (super)) (identifier)) (arguments)))) ================================================================================ Generic functions ================================================================================ std::sizeof::(); foo::<8>(); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression function: (generic_function function: (scoped_identifier path: (identifier) name: (identifier)) type_arguments: (type_arguments (primitive_type))) arguments: (arguments))) (expression_statement (call_expression function: (generic_function function: (identifier) type_arguments: (type_arguments (integer_literal))) arguments: (arguments)))) ================================================================================ Closures ================================================================================ a.map(|(b, c)| b.push(c)); d.map(move |mut e| { f(e); g(e) }); h(|| -> i { j }); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments (closure_expression (closure_parameters (tuple_pattern (identifier) (identifier))) (call_expression (field_expression (identifier) (field_identifier)) (arguments (identifier))))))) (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments (closure_expression (closure_parameters (mut_pattern (mutable_specifier) (identifier))) (block (expression_statement (call_expression (identifier) (arguments (identifier)))) (call_expression (identifier) (arguments (identifier)))))))) (expression_statement (call_expression (identifier) (arguments (closure_expression (closure_parameters) (type_identifier) (block (identifier))))))) ================================================================================ Closures with typed parameters ================================================================================ a.map(|#[warn(unused_parens)] b: usize| b.push(c)); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments (closure_expression (closure_parameters (parameter (attributes (attribute_item (attribute (identifier) (token_tree (identifier))))) (identifier) (primitive_type))) (call_expression (field_expression (identifier) (field_identifier)) (arguments (identifier)))))))) ================================================================================ Closure parameters can have a trailing comma ================================================================================ a.map(|b: usize,| b.push(c)); -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (field_expression (identifier) (field_identifier)) (arguments (closure_expression (closure_parameters (parameter (identifier) (primitive_type))) (call_expression (field_expression (identifier) (field_identifier)) (arguments (identifier)))))))) ================================================================================ Generators ================================================================================ move || { while i <= n { yield i; i += 1; } return; }; -------------------------------------------------------------------------------- (source_file (expression_statement (closure_expression (closure_parameters) (block (expression_statement (while_expression (binary_expression (identifier) (identifier)) (block (expression_statement (yield_expression (identifier))) (expression_statement (compound_assignment_expr (identifier) (integer_literal)))))) (expression_statement (return_expression)))))) ================================================================================ Unsafe blocks ================================================================================ const a : A = unsafe { foo() }; -------------------------------------------------------------------------------- (source_file (const_item (identifier) (type_identifier) (unsafe_block (block (call_expression (identifier) (arguments)))))) ================================================================================ Inline const or Const blocks as expression ================================================================================ const { 1 + 3 }; if *x < 0 { const { &4i32.pow(4) } } else { x } let three_ranges = [const { (0..=5).into_inner() }; 3]; -------------------------------------------------------------------------------- (source_file (expression_statement (const_block body: (block (binary_expression left: (integer_literal) right: (integer_literal))))) (empty_statement) (expression_statement (if_expression condition: (binary_expression left: (unary_expression (identifier)) right: (integer_literal)) consequence: (block (expression_statement (const_block body: (block (reference_expression value: (call_expression function: (field_expression value: (integer_literal) field: (field_identifier)) arguments: (arguments (integer_literal)))))))) alternative: (else_clause (block (identifier))))) (let_declaration pattern: (identifier) value: (array_expression (const_block body: (block (call_expression function: (field_expression value: (parenthesized_expression (range_expression (integer_literal) (integer_literal))) field: (field_identifier)) arguments: (arguments)))) length: (integer_literal)))) ================================================================================ Negative number in turbofish ================================================================================ fn main() { const_generic_fn_signed_int::<-7>(); } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (expression_statement (call_expression (generic_function (identifier) (type_arguments (negative_literal (integer_literal)))) (arguments)))))) ================================================================================ Raw reference expression conflicts ================================================================================ some_call(&raw); let a = &raw const b; -------------------------------------------------------------------------------- (source_file (expression_statement (call_expression (identifier) (arguments (reference_expression (identifier))))) (let_declaration (identifier) (reference_expression (identifier)))) ================================================================================ Become expressions ================================================================================ fn forever() { become forever() } become TABLE[*inst as usize](rest, state); match slice { [first, rest @ ..] => become fold(rest, f(init, *first), f), [] => init, } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (become_expression (call_expression (identifier) (arguments))))) (expression_statement (become_expression (call_expression (index_expression (identifier) (type_cast_expression (unary_expression (identifier)) (primitive_type))) (arguments (identifier) (identifier))))) (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (slice_pattern (identifier) (captured_pattern (identifier) (remaining_field_pattern)))) (become_expression (call_expression (identifier) (arguments (identifier) (call_expression (identifier) (arguments (identifier) (unary_expression (identifier)))) (identifier))))) (match_arm (match_pattern (slice_pattern)) (identifier)))))) ====================================================== Trailing alphanumeric characters in numeric literals ====================================================== some_macro! { 123c"foo" } ------------------------------------------------------ (source_file (macro_invocation_item (macro_invocation (identifier) (token_tree (integer_literal) (string_literal (string_content)))))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/keywords.txt000066400000000000000000000027121516074642400240020ustar00rootroot00000000000000================================================================================ auto is contextual ================================================================================ auto!(); fn main() { auto(); let auto = 3; auto; auto as usize; } fn auto() {} -------------------------------------------------------------------------------- (source_file (expression_statement (macro_invocation (identifier) (token_tree))) (function_item (identifier) (parameters) (block (expression_statement (call_expression (identifier) (arguments))) (let_declaration (identifier) (integer_literal)) (expression_statement (identifier)) (expression_statement (type_cast_expression (identifier) (primitive_type))))) (function_item (identifier) (parameters) (block))) ================================================================================ 'raw' is a valid identifier too (issue #277) ================================================================================ fn main() { foo(&raw); } -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters) (block (expression_statement (call_expression (identifier) (arguments (reference_expression (identifier)))))))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/literals.txt000066400000000000000000000131361516074642400237540ustar00rootroot00000000000000================================================================================ Integer literals ================================================================================ 0; 0___0; 123; 0usize; 123i32; 123u32; 123_u32; 0xff_u8; 0o70_i16; 0b1111_1111_1001_0000_i32; 1u128; -------------------------------------------------------------------------------- (source_file (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal)) (expression_statement (integer_literal))) ================================================================================ Floating-point literals ================================================================================ 123.123; 2.; 123.0f64; 0.1f64; 0.1f32; 12E+99_f64; 0.1f16; 0.1f128; -------------------------------------------------------------------------------- (source_file (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal)) (expression_statement (float_literal))) ================================================================================ String literals ================================================================================ ""; "abc"; c"foo"; b"foo\nbar"; "foo\ bar"; "\"foo\""; "/* foo bar */ foo bar"; "foo\x42\x43bar"; "foo \x42 \x43 bar"; "\u{10__FFFF}"; -------------------------------------------------------------------------------- (source_file (expression_statement (string_literal)) (expression_statement (string_literal (string_content))) (expression_statement (string_literal (string_content))) (expression_statement (string_literal (string_content) (escape_sequence) (string_content))) (expression_statement (string_literal (string_content) (escape_sequence) (string_content))) (expression_statement (string_literal (escape_sequence) (string_content) (escape_sequence))) (expression_statement (string_literal (string_content))) (expression_statement (string_literal (string_content) (escape_sequence) (escape_sequence) (string_content))) (expression_statement (string_literal (string_content) (escape_sequence) (string_content) (escape_sequence) (string_content))) (expression_statement (string_literal (escape_sequence)))) ================================================================================ Raw string literals ================================================================================ r#"abc"#; r##"ok"##; r##"foo #"# bar"##; r###"foo ##"## bar"###; r######"foo ##### bar"######; -------------------------------------------------------------------------------- (source_file (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content)))) ================================================================================ Raw byte string literals ================================================================================ br#"abc"#; br##"abc"##; -------------------------------------------------------------------------------- (source_file (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content)))) ================================================================================ Raw C string literals ================================================================================ cr#"abc"#; cr##"abc"##; -------------------------------------------------------------------------------- (source_file (expression_statement (raw_string_literal (string_content))) (expression_statement (raw_string_literal (string_content)))) ================================================================================ Character literals ================================================================================ 'a'; '\''; '\0'; b'x'; '\t'; '\xff'; '\\'; '\u{10__FFFF}'; -------------------------------------------------------------------------------- (source_file (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal)) (expression_statement (char_literal))) ================================================================================ Boolean literals ================================================================================ true; false; -------------------------------------------------------------------------------- (source_file (expression_statement (boolean_literal)) (expression_statement (boolean_literal))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/macros.txt000066400000000000000000000263671516074642400234330ustar00rootroot00000000000000================================================================================ Macro invocation - no arguments ================================================================================ a!(); b![]; c!{}; d::e!(); f::g::h!{}; -------------------------------------------------------------------------------- (source_file (expression_statement (macro_invocation (identifier) (token_tree))) (expression_statement (macro_invocation (identifier) (token_tree))) (expression_statement (macro_invocation (identifier) (token_tree))) (expression_statement (macro_invocation (scoped_identifier (identifier) (identifier)) (token_tree))) (expression_statement (macro_invocation (scoped_identifier (scoped_identifier (identifier) (identifier)) (identifier)) (token_tree)))) ================================================================================ Macro invocation - arbitrary tokens ================================================================================ a!(* a *); a!(& a &); a!(- a -); a!(b + c + +); a!('a'..='z'); a!('\u{0}'..='\u{2}'); a!('lifetime) default!(a); union!(a); a!($); a!($()); a!($ a $); a!(${$([ a ])}); a!($a $a:ident $($a);*); -------------------------------------------------------------------------------- (source_file (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier) (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (char_literal) (char_literal)))) (expression_statement (macro_invocation (identifier) (token_tree (char_literal) (char_literal)))) (macro_invocation_item (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree))) (expression_statement (macro_invocation (identifier) (token_tree (token_tree)))) (expression_statement (macro_invocation (identifier) (token_tree (identifier)))) (expression_statement (macro_invocation (identifier) (token_tree (token_tree (token_tree (token_tree (identifier))))))) (expression_statement (macro_invocation (identifier) (token_tree (identifier) (identifier) (identifier) (token_tree (identifier)))))) ================================================================================ Macro invocation with comments ================================================================================ ok! { // one /* two */ } -------------------------------------------------------------------------------- (source_file (macro_invocation_item (macro_invocation (identifier) (token_tree (line_comment) (block_comment))))) ================================================================================ Macro definition ================================================================================ macro_rules! say_hello { () => ( println!("Hello!"); ) } macro_rules! four { () => {1 + 3}; } macro_rules! foo { (x => $e:expr) => (println!("mode X: {}", $e)); (y => $e:expr) => (println!("mode Y: {}", $e)) } macro_rules! o_O { ( $($x:expr; [ $( $y:expr ),* ]);* ) => { $($($x + $e),*),* } } macro_rules! zero_or_one { ($($e:expr),?) => { $($e),? }; } macro_rules ! empty [ () => {}; ]; macro_rules! with_dollar_sign { ($a:tt => $b:tt) => { macro_rules! __with_dollar_sign { $a => $b } __with_dollar_sign!($); } } macro_rules ! macro_with_whitespace { ($ x : expr, $ y : expr) => { $ x + $ y } } -------------------------------------------------------------------------------- (source_file (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern) right: (token_tree (identifier) (token_tree (string_literal (string_content)))))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern) right: (token_tree (integer_literal) (integer_literal)))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern (identifier) (token_binding_pattern name: (metavariable) type: (fragment_specifier))) right: (token_tree (identifier) (token_tree (string_literal (string_content)) (metavariable)))) (macro_rule left: (token_tree_pattern (identifier) (token_binding_pattern name: (metavariable) type: (fragment_specifier))) right: (token_tree (identifier) (token_tree (string_literal (string_content)) (metavariable))))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern (token_repetition_pattern (token_binding_pattern name: (metavariable) type: (fragment_specifier)) (token_tree_pattern (token_repetition_pattern (token_binding_pattern name: (metavariable) type: (fragment_specifier)))))) right: (token_tree (token_repetition (token_repetition (metavariable) (metavariable)))))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern (token_repetition_pattern (token_binding_pattern name: (metavariable) type: (fragment_specifier)))) right: (token_tree (token_repetition (metavariable))))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern) right: (token_tree))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern (token_binding_pattern name: (metavariable) type: (fragment_specifier)) (token_binding_pattern name: (metavariable) type: (fragment_specifier))) right: (token_tree (identifier) (identifier) (token_tree (metavariable) (metavariable)) (identifier) (token_tree)))) (macro_definition name: (identifier) (macro_rule left: (token_tree_pattern (token_binding_pattern name: (metavariable) type: (fragment_specifier)) (token_binding_pattern name: (metavariable) type: (fragment_specifier))) right: (token_tree (metavariable) (metavariable))))) ================================================================================ Macro definition with unicode characters ================================================================================ macro_rules! macro_that_defines_a_function { (fn $名:ident () $体:tt) => { fn $名 () $体 fn 他 () {} } } -------------------------------------------------------------------------------- (source_file (macro_definition (identifier) (macro_rule (token_tree_pattern (token_binding_pattern (metavariable) (fragment_specifier)) (token_tree_pattern) (token_binding_pattern (metavariable) (fragment_specifier))) (token_tree (metavariable) (token_tree) (metavariable) (identifier) (token_tree) (token_tree))))) ================================================================================ Macro definition v2 ================================================================================ pub macro m($key_ty:ident, $val_ty:ident) { struct $key_ty { inner: usize, } impl T for $val_ty { type Key = $key_ty; fn index_from_key(key: Self::Key) -> usize { key.inner } } } fn main() { async { macro mm() {} }; } pub macro my_macro_2($($tok:tt)*) { } pub macro my_macro_multi { (_) => { }, ($foo:ident . $bar:expr) => { }, ($($foo:literal),+) => { } } #[rustc_builtin_macro] pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) { /* compiler built-in */ } -------------------------------------------------------------------------------- (source_file (macro_definition_v2 (visibility_modifier) (identifier) (macro_arguments_declaration (token_binding_pattern (metavariable) (fragment_specifier)) (token_binding_pattern (metavariable) (fragment_specifier))) (macro_body_v2 (metavariable) (token_tree (identifier) (primitive_type)) (identifier) (metavariable) (token_tree (identifier) (metavariable) (identifier) (token_tree (identifier) (identifier) (identifier)) (primitive_type) (token_tree (identifier) (identifier))))) (function_item (identifier) (parameters) (block (expression_statement (async_block (block (macro_definition_v2 (identifier) (macro_arguments_declaration) (macro_body_v2))))) (empty_statement))) (macro_definition_v2 (visibility_modifier) (identifier) (macro_arguments_declaration (token_repetition_pattern (token_binding_pattern (metavariable) (fragment_specifier)))) (macro_body_v2)) (macro_definition_v2 (visibility_modifier) (identifier) (macro_rules_v2 (macro_rule_v2 (token_tree_pattern) (token_tree)) (macro_rule_v2 (token_tree_pattern (token_binding_pattern (metavariable) (fragment_specifier)) (token_binding_pattern (metavariable) (fragment_specifier))) (token_tree)) (macro_rule_v2 (token_tree_pattern (token_repetition_pattern (token_binding_pattern (metavariable) (fragment_specifier)))) (token_tree)))) (macro_definition_v2 (attributes (attribute_item (attribute (identifier)))) (visibility_modifier) (identifier) (macro_arguments_declaration (string_literal (string_content)) (token_repetition_pattern (identifier)) (token_repetition_pattern (identifier) (token_tree_pattern (token_repetition_pattern (identifier))))) (macro_body_v2 (block_comment)))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/patterns.txt000066400000000000000000000426371516074642400240050ustar00rootroot00000000000000================================================================================ Tuple struct patterns ================================================================================ match x { Some(x) => "some", std::None() => "none" } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (tuple_struct_pattern (identifier) (identifier))) (string_literal (string_content))) (match_arm (match_pattern (tuple_struct_pattern (scoped_identifier (identifier) (identifier)))) (string_literal (string_content))))))) ================================================================================ Reference patterns ================================================================================ match x { A(ref x) => x.0, ref mut y => y, & mut z => z, } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (tuple_struct_pattern (identifier) (ref_pattern (identifier)))) (field_expression (identifier) (integer_literal))) (match_arm (match_pattern (ref_pattern (mut_pattern (mutable_specifier) (identifier)))) (identifier)) (match_arm (match_pattern (reference_pattern (mutable_specifier) (identifier))) (identifier)))))) ================================================================================ Box patterns ================================================================================ match x { A(box x) => x.0, } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (tuple_struct_pattern (identifier) (box_pattern (identifier)))) (field_expression (identifier) (integer_literal))))))) ================================================================================ Struct patterns ================================================================================ match x { Person{name, age} if age < 5 => ("toddler", name), Person{name: adult_name, age: _} => ("adult", adult_name), } match y { Bar::T1(_, Some::(x)) => println!("{x}"), } match ConstGenericEnum::Bar { ConstGenericEnum::<3>::Foo(field, ..) => (), ConstGenericEnum::<3>::Bar => (), } match todo!() { Bar::<3> { field: Foo::<3>, } => (), } let TupleStruct { 0: first, 1: second } = ts; -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (struct_pattern (type_identifier) (field_pattern (shorthand_field_identifier)) (field_pattern (shorthand_field_identifier))) (binary_expression (identifier) (integer_literal))) (tuple_expression (string_literal (string_content)) (identifier))) (match_arm (match_pattern (struct_pattern (type_identifier) (field_pattern (field_identifier) (identifier)) (field_pattern (field_identifier)))) (tuple_expression (string_literal (string_content)) (identifier)))))) (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (tuple_struct_pattern (scoped_identifier (identifier) (identifier)) (tuple_struct_pattern (generic_type (type_identifier) (type_arguments (primitive_type))) (identifier)))) (macro_invocation (identifier) (token_tree (string_literal (string_content)))))))) (expression_statement (match_expression (scoped_identifier (identifier) (identifier)) (match_block (match_arm (match_pattern (tuple_struct_pattern (scoped_identifier (generic_type (type_identifier) (type_arguments (integer_literal))) (identifier)) (identifier) (remaining_field_pattern))) (unit_expression)) (match_arm (match_pattern (scoped_identifier (generic_type (type_identifier) (type_arguments (integer_literal))) (identifier))) (unit_expression))))) (expression_statement (match_expression (macro_invocation (identifier) (token_tree)) (match_block (match_arm (match_pattern (struct_pattern (generic_type_with_turbofish (type_identifier) (type_arguments (integer_literal))) (field_pattern (field_identifier) (generic_pattern (identifier) (type_arguments (integer_literal)))))) (unit_expression))))) (let_declaration (struct_pattern (type_identifier) (field_pattern (integer_literal) (identifier)) (field_pattern (integer_literal) (identifier))) (identifier))) ================================================================================ Ignored patterns ================================================================================ match x { (a, ..) => a, B(..) => c, D::E{f: g, ..} => g } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (tuple_pattern (identifier) (remaining_field_pattern))) (identifier)) (match_arm (match_pattern (tuple_struct_pattern (identifier) (remaining_field_pattern))) (identifier)) (match_arm (match_pattern (struct_pattern (scoped_type_identifier (identifier) (type_identifier)) (field_pattern (field_identifier) (identifier)) (remaining_field_pattern))) (identifier)))))) ================================================================================ Captured patterns ================================================================================ match x { a @ A(_) | b @ B(..) => a, a @ 1 ... 5 => a, Some(1 ... 5) => a, a @ b...c => a, a @ b..=c => a, d.. => a, ..d => d, a @ ..=5 => a } match name { | "IPV6_FLOWINFO" | "IPV6_FLOWLABEL_MGR" | "IPV6_FLOWINFO_SEND" => true, _ => false, } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (or_pattern (captured_pattern (identifier) (tuple_struct_pattern type: (identifier))) (captured_pattern (identifier) (tuple_struct_pattern type: (identifier) (remaining_field_pattern))))) value: (identifier)) (match_arm pattern: (match_pattern (captured_pattern (identifier) (range_pattern left: (integer_literal) right: (integer_literal)))) value: (identifier)) (match_arm pattern: (match_pattern (tuple_struct_pattern type: (identifier) (range_pattern left: (integer_literal) right: (integer_literal)))) value: (identifier)) (match_arm pattern: (match_pattern (captured_pattern (identifier) (range_pattern left: (identifier) right: (identifier)))) value: (identifier)) (match_arm pattern: (match_pattern (captured_pattern (identifier) (range_pattern left: (identifier) right: (identifier)))) value: (identifier)) (match_arm pattern: (match_pattern (range_pattern left: (identifier))) value: (identifier)) (match_arm pattern: (match_pattern (range_pattern right: (identifier))) value: (identifier)) (match_arm pattern: (match_pattern (captured_pattern (identifier) (range_pattern right: (integer_literal)))) value: (identifier))))) (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (or_pattern (or_pattern (or_pattern (string_literal (string_content))) (string_literal (string_content))) (string_literal (string_content)))) value: (boolean_literal)) (match_arm pattern: (match_pattern) value: (boolean_literal)))))) ================================================================================ Or patterns ================================================================================ if let A(x) | B(x) = expr { do_stuff_with(x); } while let A(x) | B(x) = expr { do_stuff_with(x); } let Ok(index) | Err(index) = slice.binary_search(&x); for ref a | b in c {} let Ok(x) | Err(x) = binary_search(x); for A | B | C in c {} |(Ok(x) | Err(x))| expr(); let ref mut x @ (A | B | C); fn foo((1 | 2 | 3): u8) {} if let x!() | y!() = () {} -------------------------------------------------------------------------------- (source_file (expression_statement (if_expression condition: (let_condition pattern: (or_pattern (tuple_struct_pattern type: (identifier) (identifier)) (tuple_struct_pattern type: (identifier) (identifier))) value: (identifier)) consequence: (block (expression_statement (call_expression function: (identifier) arguments: (arguments (identifier))))))) (expression_statement (while_expression condition: (let_condition pattern: (or_pattern (tuple_struct_pattern type: (identifier) (identifier)) (tuple_struct_pattern type: (identifier) (identifier))) value: (identifier)) body: (block (expression_statement (call_expression function: (identifier) arguments: (arguments (identifier))))))) (let_declaration pattern: (or_pattern (tuple_struct_pattern type: (identifier) (identifier)) (tuple_struct_pattern type: (identifier) (identifier))) value: (call_expression function: (field_expression value: (identifier) field: (field_identifier)) arguments: (arguments (reference_expression value: (identifier))))) (expression_statement (for_expression pattern: (or_pattern (ref_pattern (identifier)) (identifier)) value: (identifier) body: (block))) (let_declaration pattern: (or_pattern (tuple_struct_pattern type: (identifier) (identifier)) (tuple_struct_pattern type: (identifier) (identifier))) value: (call_expression function: (identifier) arguments: (arguments (identifier)))) (expression_statement (for_expression pattern: (or_pattern (or_pattern (identifier) (identifier)) (identifier)) value: (identifier) body: (block))) (expression_statement (closure_expression parameters: (closure_parameters (tuple_pattern (or_pattern (tuple_struct_pattern type: (identifier) (identifier)) (tuple_struct_pattern type: (identifier) (identifier))))) body: (call_expression function: (identifier) arguments: (arguments)))) (let_declaration pattern: (ref_pattern (mut_pattern (mutable_specifier) (captured_pattern (identifier) (tuple_pattern (or_pattern (or_pattern (identifier) (identifier)) (identifier))))))) (function_item name: (identifier) parameters: (parameters (parameter pattern: (tuple_pattern (or_pattern (or_pattern (integer_literal) (integer_literal)) (integer_literal))) type: (primitive_type))) body: (block)) (expression_statement (if_expression condition: (let_condition pattern: (or_pattern (macro_invocation macro: (identifier) (token_tree)) (macro_invocation macro: (identifier) (token_tree))) value: (unit_expression)) consequence: (block)))) ================================================================================ Inline const or Const blocks as pattern ================================================================================ fn foo(x: i32) { const CUBE: i32 = 3.pow(3); match x { CUBE => println!("three cubed"), _ => {} } } fn foo(x: i32) { match x { const { 3.pow(3) } => println!("three cubed"), _ => {} } } -------------------------------------------------------------------------------- (source_file (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (primitive_type))) body: (block (const_item name: (identifier) type: (primitive_type) value: (call_expression function: (field_expression value: (integer_literal) field: (field_identifier)) arguments: (arguments (integer_literal)))) (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (identifier)) value: (macro_invocation macro: (identifier) (token_tree (string_literal (string_content))))) (match_arm pattern: (match_pattern) value: (block))))))) (function_item name: (identifier) parameters: (parameters (parameter pattern: (identifier) type: (primitive_type))) body: (block (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (const_block body: (block (call_expression function: (field_expression value: (integer_literal) field: (field_identifier)) arguments: (arguments (integer_literal)))))) value: (macro_invocation macro: (identifier) (token_tree (string_literal (string_content))))) (match_arm pattern: (match_pattern) value: (block)))))))) ================================================================================ Pattern with turbofish ================================================================================ match y { None:: => 17, _ => 42, } -------------------------------------------------------------------------------- (source_file (expression_statement (match_expression (identifier) (match_block (match_arm (match_pattern (generic_pattern (identifier) (type_arguments (type_identifier)))) (integer_literal)) (match_arm (match_pattern) (integer_literal)))))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/source_files.txt000066400000000000000000000166161516074642400246250ustar00rootroot00000000000000============================================ Block comments ============================================ /* * Block comments */ /* Comment with asterisks **/ /** Outer block comment */ fn test() {} /*! Inner block comment */ /**/ ---- (source_file (block_comment) (block_comment) (function_item attributes: (attributes (block_outer_doc_comment doc: (doc_comment))) name: (identifier) parameters: (parameters) body: (block)) (block_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (block_comment)) ============================================ Nested block comments ============================================ /* /* double nested */ */ // --- /*/*/* triple nested */*/*/ // --- /**** /**** nested with extra stars which makes it a regular block comment and not a block doc comment ****/ ****/ // --- /* nested with extra slash between two nested block comments /**///**/ */ // --- ---- (source_file (block_comment) (line_comment) (block_comment) (line_comment) (block_comment) (line_comment) (block_comment) (line_comment)) ============================================ Line comments ============================================ // Comment /// Outer line doc comment fn test() {} //! Inner line doc comment ---- (source_file (line_comment) (function_item attributes: (attributes (line_outer_doc_comment doc: (doc_comment))) name: (identifier) parameters: (parameters) body: (block)) (line_comment inner: (inner_doc_comment_marker) doc: (doc_comment))) ==================================== Line doc comments ==================================== //! - Inner line doc //!! - Still an inner line doc (but with a bang at the beginning) // - Only a comment /// - Outer line doc (exactly 3 slashes) /// let x = 1; //// - this is only a comment, not a doc one --- (source_file (line_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (line_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (line_comment) (let_declaration attributes: (attributes (line_outer_doc_comment doc: (doc_comment)) (line_outer_doc_comment doc: (doc_comment))) pattern: (identifier) value: (integer_literal)) (line_comment)) ==================================== Block doc comments ==================================== /*! - Inner block doc */ /*!! - Still an inner block doc (but with a bang at the beginning) */ /* - Only a comment */ /** - Outer block doc (exactly) 2 asterisks */ fn test() {} /*** - Only a comment */ ---- (source_file (block_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (block_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (block_comment) (function_item attributes: (attributes (block_outer_doc_comment doc: (doc_comment))) name: (identifier) parameters: (parameters) body: (block)) (block_comment)) ===================================== Nested doc block comments ===================================== /* /* */ /** */ /*! */ */ /*! /* */ /** */ /*! */ */ /** /* */ /** */ /*! */ */ fn test() {} ---- (source_file (block_comment) (block_comment inner: (inner_doc_comment_marker) doc: (doc_comment)) (function_item attributes: (attributes (block_outer_doc_comment doc: (doc_comment))) name: (identifier) parameters: (parameters) body: (block))) ==================================== Comments degenerate cases ==================================== //! /*!*/ // /// let x; // <- immediate item after an empty line doc comment /**/ /***/ ---- (source_file (line_comment (inner_doc_comment_marker) (doc_comment)) (block_comment (inner_doc_comment_marker)) (line_comment) (let_declaration (attributes (line_outer_doc_comment (doc_comment))) (identifier)) (line_comment) (block_comment) (block_comment)) ================================================================================ Line doc comment with no EOL ================================================================================ //! Doc comment -------------------------------------------------------------------------------- (source_file (line_comment (inner_doc_comment_marker) (doc_comment))) ===================================== Greek letters in identifiers ===================================== const σ1 : Σ = 0; const ψ_2 : Ψ = 1; --- (source_file (const_item (identifier) (type_identifier) (integer_literal)) (const_item (identifier) (type_identifier) (integer_literal))) ================================================================================ Frontmatter ================================================================================ #!/usr/bin/env cargo --- [package] edition = "2024" --- -------------------------------------------------------------------------------- (source_file (shebang) (frontmatter (frontmatter_content))) ================================================================================ Frontmatter with escaping ================================================================================ ----- [package] description = """ --- --- """ ----- -------------------------------------------------------------------------------- (source_file (frontmatter (frontmatter_content))) ================================================================================ Empty frontmatter ================================================================================ --- --- fn main() {} -------------------------------------------------------------------------------- (source_file (frontmatter (frontmatter_content)) (function_item (identifier) (parameters) (block))) ================================================================================ Empty frontmatter with info string ================================================================================ --- info string --- fn main() {} -------------------------------------------------------------------------------- (source_file (frontmatter (frontmatter_content)) (function_item (identifier) (parameters) (block))) ================================================================================ Shebang line containing spaces ================================================================================ #!/usr/bin/env -S cargo +nightly -Zscript -------------------------------------------------------------------------------- (source_file (shebang)) ================================================================================ Empty shebang with code after ================================================================================ #! fn main() {} -------------------------------------------------------------------------------- (source_file (shebang) (function_item (identifier) (parameters) (block))) ================================================================================ Immediate inner attribute ================================================================================ #![feature(thing)] fn main() {} -------------------------------------------------------------------------------- (source_file (inner_attribute_item (attribute (identifier) (token_tree (identifier)))) (function_item (identifier) (parameters) (block))) tree-sitter-rust-orchard-0.16.3+ds/test/corpus/types.txt000066400000000000000000000314341516074642400233020ustar00rootroot00000000000000================================================================================ The unit type ================================================================================ type A = (); -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (unit_type))) ================================================================================ Tuple types ================================================================================ type A = (i32, String); -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (tuple_type (primitive_type) (type_identifier)))) ================================================================================ Reference types ================================================================================ type A = &B; type C = &'a str; type D = &'a mut str; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (reference_type (type_identifier))) (type_item (type_identifier) (reference_type (lifetime (identifier)) (primitive_type))) (type_item (type_identifier) (reference_type (lifetime (identifier)) (mutable_specifier) (primitive_type)))) ================================================================================ Raw pointer types ================================================================================ type A = *mut B; type C = *const str; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (pointer_type (mutable_specifier) (type_identifier))) (type_item (type_identifier) (pointer_type (primitive_type)))) ================================================================================ Generic types ================================================================================ type A = B; type D = E; type G = H<'a, I>; type J = H; pub struct G(std::marker::PhantomData::<(T, K)>); pub struct H(epsilon::Foo::<>); type K = u8<>; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier)))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier) (primitive_type)))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (lifetime (identifier)) (type_identifier)))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (type_binding (type_identifier) (type_identifier))))) (struct_item (visibility_modifier) (type_identifier) (type_parameters (type_parameter (type_identifier)) (type_parameter (type_identifier))) (ordered_field_declaration_list (generic_type_with_turbofish (scoped_identifier (scoped_identifier (identifier) (identifier)) (identifier)) (type_arguments (tuple_type (type_identifier) (type_identifier)))))) (struct_item (visibility_modifier) (type_identifier) (ordered_field_declaration_list (generic_type_with_turbofish (scoped_identifier (identifier) (identifier)) (type_arguments)))) (type_item (type_identifier) (generic_type (primitive_type) (type_arguments)))) ================================================================================ Scoped types ================================================================================ type A = B::C; type D = E::F::G; type H = I::J; type L = M::O; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (scoped_type_identifier (identifier) (type_identifier))) (type_item (type_identifier) (scoped_type_identifier (scoped_identifier (identifier) (identifier)) (type_identifier))) (type_item (type_identifier) (generic_type (scoped_type_identifier (identifier) (type_identifier)) (type_arguments (type_identifier)))) (type_item (type_identifier) (scoped_type_identifier (generic_type (type_identifier) (type_arguments (type_identifier))) (type_identifier)))) ================================================================================ Array types ================================================================================ type A = [B; 4]; type C = &[D]; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (array_type (type_identifier) (integer_literal))) (type_item (type_identifier) (reference_type (array_type (type_identifier))))) ================================================================================ Function types ================================================================================ fn high_order1(value: i32, f: fn(i32)) -> i32 {} fn high_order2(value: i32, f: fn(i32) -> i32) -> i32 { f(value) } fn high_order3(value: i32, f: &FnOnce(i32) -> i32) -> i32 { f(value) } type F = for<'a, 'b> fn(x: &'a A, y: &'a mut B<'i, 't>,) -> C; -------------------------------------------------------------------------------- (source_file (function_item (identifier) (parameters (parameter (identifier) (primitive_type)) (parameter (identifier) (function_type (parameters (primitive_type))))) (primitive_type) (block)) (function_item (identifier) (parameters (parameter (identifier) (primitive_type)) (parameter (identifier) (function_type (parameters (primitive_type)) (primitive_type)))) (primitive_type) (block (call_expression (identifier) (arguments (identifier))))) (function_item (identifier) (parameters (parameter (identifier) (primitive_type)) (parameter (identifier) (reference_type (function_type (type_identifier) (parameters (primitive_type)) (primitive_type))))) (primitive_type) (block (call_expression (identifier) (arguments (identifier))))) (type_item (type_identifier) (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier))) (lifetime_parameter (lifetime (identifier)))) (function_type (parameters (parameter (identifier) (reference_type (lifetime (identifier)) (type_identifier))) (parameter (identifier) (reference_type (lifetime (identifier)) (mutable_specifier) (generic_type (type_identifier) (type_arguments (lifetime (identifier)) (lifetime (identifier))))))) (type_identifier))))) ================================================================================ Unsafe and extern function types ================================================================================ type a = extern "C" fn(*mut c_void); type b = unsafe extern "C" fn() -> *mut c_void; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (function_type (function_modifiers (extern_modifier (string_literal (string_content)))) (parameters (pointer_type (mutable_specifier) (type_identifier))))) (type_item (type_identifier) (function_type (function_modifiers (extern_modifier (string_literal (string_content)))) (parameters) (pointer_type (mutable_specifier) (type_identifier))))) ================================================================================ Trait objects ================================================================================ type a = Box; type b = Rc; type c = A<&dyn Fn(&B) -> C>; -------------------------------------------------------------------------------- (source_file (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (bounded_type (type_identifier) (lifetime (identifier)))))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (dynamic_type (type_identifier))))) (type_item (type_identifier) (generic_type (type_identifier) (type_arguments (reference_type (dynamic_type (function_type (type_identifier) (parameters (reference_type (type_identifier))) (type_identifier)))))))) ================================================================================ Higher-ranked trait bounds ================================================================================ pub struct Bar<'a> { pub baz: &'a (dyn Unpin + for<'b> Trait<'b>), } type F = for<> (C,D); -------------------------------------------------------------------------------- (source_file (struct_item (visibility_modifier) (type_identifier) (type_parameters (lifetime_parameter (lifetime (identifier)))) (field_declaration_list (field_declaration (visibility_modifier) (field_identifier) (reference_type (lifetime (identifier)) (tuple_type (bounded_type (dynamic_type (type_identifier)) (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier)))) (generic_type (type_identifier) (type_arguments (lifetime (identifier))))))))))) (type_item (type_identifier) (higher_ranked_trait_bound (type_parameters) (tuple_type (type_identifier) (type_identifier))))) ================================================================================ Type cast expressions with generics ================================================================================ a as B; d as *mut E<::G>; -------------------------------------------------------------------------------- (source_file (expression_statement (type_cast_expression (identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) (expression_statement (type_cast_expression (identifier) (pointer_type (mutable_specifier) (generic_type (type_identifier) (type_arguments (scoped_type_identifier (bracketed_type (qualified_type (type_identifier) (type_identifier))) (type_identifier)))))))) ================================================================================ Unsafe binders ================================================================================ pub fn my_fun() -> for<'a> fn(unsafe<'b, 'c> (&'a i32, &'b i32)) { todo!() } -------------------------------------------------------------------------------- (source_file (function_item (visibility_modifier) (identifier) (parameters) (higher_ranked_trait_bound (type_parameters (lifetime_parameter (lifetime (identifier)))) (function_type (parameters (unsafe_bound_type (lifetime (identifier)) (lifetime (identifier)) (tuple_type (reference_type (lifetime (identifier)) (primitive_type)) (reference_type (lifetime (identifier)) (primitive_type))))))) (block (macro_invocation (identifier) (token_tree))))) tree-sitter-rust-orchard-0.16.3+ds/tree-sitter.json000066400000000000000000000025021516074642400222370ustar00rootroot00000000000000{ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json", "grammars": [ { "name": "rust_orchard", "camelcase": "RustOrchard", "title": "Rust", "scope": "source.rust", "path": ".", "file-types": [ "rs" ], "highlights": [ "queries/highlights.scm" ], "injections": [ "queries/injections.scm" ], "tags": [ "queries/tags.scm" ], "injection-regex": "rust", "class-name": "TreeSitterRustOrchard" } ], "metadata": { "version": "0.16.3", "license": "MIT", "description": "Grammar for Rust that aims to be closer to the actual AST", "authors": [ { "name": "Maxim Sokolov", "email": "maxim0xff@gmail.com" }, { "name": "Max Brunsfeld", "email": "maxbrunsfeld@gmail.com" }, { "name": "Amaan Qureshi", "email": "amaanq12@gmail.com" }, { "name": "Antonin Delpeuch", "email": "antonin@delpeuch.eu" } ], "links": { "repository": "https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard" } }, "bindings": { "c": true, "go": true, "node": true, "python": true, "rust": true, "swift": true, "zig": false } }