Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tree-sitter/tree-sitter-rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8746bd4b584b8063ee8e445bf31015e887417d33
Choose a base ref
...
head repository: tree-sitter/tree-sitter-rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a250c4582510ff34767ec3b7dcdd3c24e8c8aa68
Choose a head ref

Commits on Jan 5, 2021

  1. Add const block expression (#97)

    * Add const block expression
    
    * Fix const block pattern test
    GrayJack authored Jan 5, 2021
    Copy the full SHA
    2beedf2 View commit details

Commits on Feb 17, 2021

  1. Disambiguate parenthesized range expressions from call expressions (#100

    )
    
    * disambiguate parenthesized range expressions from call expressions
    
    * regenerate parser for 'range_expression'
    
    Co-authored-by: resolritter <resolritter@users.noreply.github.com>
    resolritter and resolritter authored Feb 17, 2021
    Copy the full SHA
    ab7f796 View commit details

Commits on Feb 25, 2021

  1. Add Rust package (#103)

    Luni-4 authored Feb 25, 2021
    Copy the full SHA
    1be73c2 View commit details

Commits on Mar 4, 2021

  1. Copy the full SHA
    9d002ee View commit details
  2. 0.19.0

    maxbrunsfeld committed Mar 4, 2021
    Copy the full SHA
    2a5c1ff View commit details
  3. Copy the full SHA
    f131d9a View commit details
  4. 0.19.1

    maxbrunsfeld committed Mar 4, 2021
    Copy the full SHA
    20f064b View commit details

Commits on Mar 9, 2021

  1. Switch to GH Actions CI.

    patrickt committed Mar 9, 2021
    Copy the full SHA
    b70dc93 View commit details
  2. Merge pull request #104 from tree-sitter/actions

    Switch to GH Actions CI.
    patrickt authored Mar 9, 2021
    Copy the full SHA
    94693ab View commit details
  3. Update badge.

    patrickt authored Mar 9, 2021
    Copy the full SHA
    a3e6768 View commit details

Commits on Mar 27, 2021

  1. Allow 'default' and 'union' in paths (#77)

    * Allow 'default' and 'union' in paths
    
    * And allow them as macro identifiers
    
    * Add a test for macros default! and union!
    calixteman authored Mar 27, 2021
    Copy the full SHA
    a360da0 View commit details

Commits on Aug 17, 2021

  1. Update package.json to include the repository key (#111)

    With the rise in supply chain attacks and OSS dependencies being used as a attack vector, Microsoft is working with our ecosystem partners, such as the Linux Foundation's OpenSSF, to enable OSS consumers to track packages back to their public sources.
    We've identified that the following packages published to NPM do not report where sources can be found, typically accomplished by including a link to your GitHub repository in your `package.json` REPOSITORY field. This PR was created to add this value, ensuring future releases will include this provenance information.
    Published NPM packages with repository information:
    * tree-sitter-rust
    msftenhanceprovenance authored Aug 17, 2021
    Copy the full SHA
    cc7bdd3 View commit details

Commits on Dec 6, 2021

  1. Permit impl item to end with semicolon (#118)

    * Add test with semicolons after an impl signature
    
    * Permit impl item to end with semicolon
    
    * Regenerate parser
    dtolnay authored Dec 6, 2021
    Copy the full SHA
    0c250fc View commit details
  2. Copy the full SHA
    3e3a6ac View commit details
  3. 0.20

    maxbrunsfeld committed Dec 6, 2021
    Copy the full SHA
    e06d078 View commit details

Commits on Dec 12, 2021

  1. Add Generic Associated Types support (#124)

    * tests: put tests for GAT
    
    * feat: support GAT
    
    * tests: add normal type parameter to generic associated type
    
    * tests: add checks for type binding
    
    * feat: support type binding to have type arguments
    
    * chore: regenerate parser
    
    * chore: fix formatting
    kawaemon authored Dec 12, 2021
    Copy the full SHA
    d045b04 View commit details

Commits on Jan 5, 2022

  1. Copy the full SHA
    0a9d1c5 View commit details
  2. Copy the full SHA
    b100b7d View commit details

Commits on Jan 6, 2022

  1. Merge pull request #110 from Keating950/master

    Add highlighting for yield keyword from #[feature(generators)]
    aryx authored Jan 6, 2022
    Copy the full SHA
    c7c50d4 View commit details

Commits on Jan 8, 2022

  1. fix "endless range" parsing

    add more tests
    resolritter committed Jan 8, 2022
    Copy the full SHA
    573907f View commit details
  2. regenerate parser

    resolritter committed Jan 8, 2022
    Copy the full SHA
    0a9f0b4 View commit details

Commits on Jan 9, 2022

  1. Merge pull request #127 from resolritter/range

    Fix range parsing
    aryx authored Jan 9, 2022
    Copy the full SHA
    5993f53 View commit details
  2. designate doc comments

    resolritter committed Jan 9, 2022
    Copy the full SHA
    d8015ac View commit details
  3. regenerate parser

    resolritter committed Jan 9, 2022
    Copy the full SHA
    5c30f3d View commit details

Commits on Jan 10, 2022

  1. Merge pull request #99 from resolritter/doc_comments

    Designate doc comments
    aryx authored Jan 10, 2022
    Copy the full SHA
    67d304c View commit details
  2. Revert "Merge pull request #99 from resolritter/doc_comments"

    This reverts commit 67d304c, reversing
    changes made to 5993f53.
    maxbrunsfeld committed Jan 10, 2022
    Copy the full SHA
    eeb0702 View commit details

Commits on Feb 4, 2022

  1. Make expression_statement visible

    Co-Authored-By: Nathan Sobo <nathan@zed.dev>
    maxbrunsfeld and nathansobo committed Feb 4, 2022
    Copy the full SHA
    b255b17 View commit details
  2. 0.20.1

    maxbrunsfeld committed Feb 4, 2022
    Copy the full SHA
    a250c45 View commit details
Showing with 90,555 additions and 75,364 deletions.
  1. +28 −0 .github/workflows/ci.yml
  2. +2 −0 .gitignore
  3. +1 −1 .npmignore
  4. +0 −11 .travis.yml
  5. +29 −0 Cargo.toml
  6. +1 −2 README.md
  7. +0 −22 appveyor.yml
  8. +1 −1 binding.gyp
  9. 0 {src → bindings/node}/binding.cc
  10. +19 −0 bindings/node/index.js
  11. +37 −0 bindings/rust/README.md
  12. +16 −0 bindings/rust/build.rs
  13. +66 −0 bindings/rust/lib.rs
  14. +52 −35 corpus/async.txt
  15. +877 −363 corpus/declarations.txt
  16. +783 −356 corpus/expressions.txt
  17. +117 −66 corpus/literals.txt
  18. +98 −31 corpus/macros.txt
  19. +308 −167 corpus/patterns.txt
  20. +226 −79 corpus/types.txt
  21. +39 −15 grammar.js
  22. +0 −13 index.js
  23. +8 −4 package.json
  24. +149 −22 src/grammar.json
  25. +241 −3 src/node-types.json
  26. +87,384 −74,086 src/parser.c
  27. +73 −87 src/tree_sitter/parser.h
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build/test
on:
push:
branches:
- "**"
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install
- run: npm test
test_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install
- run: npm run-script test-windows
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Cargo.lock
node_modules
build
*.log
package-lock.json
examples
!examples/ast.rs
/target/
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -2,4 +2,4 @@ corpus
build
script
examples

target
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

29 changes: 29 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "tree-sitter-rust"
description = "Rust grammar for the tree-sitter parsing library"
version = "0.20.1"
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
license = "MIT"
readme = "bindings/rust/README.md"
keywords = ["incremental", "parsing", "rust"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-rust"
edition = "2018"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
autoexamples = false

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "0.20"

[build-dependencies]
cc = "1.0"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# tree-sitter-rust

[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-rust.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-rust)
[![Build status](https://ci.appveyor.com/api/projects/status/q57l49j9ancaw0fs/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-rust/branch/master)
[![Build/test](https://github.com/tree-sitter/tree-sitter-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-rust/actions/workflows/ci.yml)

Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)

22 changes: 0 additions & 22 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
"sources": [
"src/parser.c",
"src/scanner.c",
"src/binding.cc"
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99",
File renamed without changes.
19 changes: 19 additions & 0 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_rust_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_rust_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}

try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
37 changes: 37 additions & 0 deletions bindings/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# tree-sitter-rust

This crate provides a Rust grammar for the [tree-sitter][] parsing library. To
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
file. (Note that you will probably also need to depend on the
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
way.)

``` toml
[dependencies]
tree-sitter = "0.17"
tree-sitter-rust = "0.16"
```

Typically, you will use the [language][language func] function to add this
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:

``` rust
let code = r#"
fn double(x: i32) -> i32 {
x * 2
}
"#;
let mut parser = Parser::new();
parser.set_language(tree_sitter_rust::language()).expect("Error loading Rust grammar");
let parsed = parser.parse(code, None);
```

If you have any questions, please reach out to us in the [tree-sitter
discussions] page.

[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
[language func]: https://docs.rs/tree-sitter-rust/*/tree_sitter_rust/fn.language.html
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
[tree-sitter]: https://tree-sitter.github.io/
[tree-sitter crate]: https://crates.io/crates/tree-sitter
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions
16 changes: 16 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn main() {
let src_dir = std::path::Path::new("src");
let mut config = cc::Build::new();
config.include(&src_dir);
config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
let scanner_path = src_dir.join("scanner.c");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
config.file(&parser_path);
config.file(&scanner_path);
config.compile("parser-scanner");
}
66 changes: 66 additions & 0 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// -*- coding: utf-8 -*-
// ------------------------------------------------------------------------------------------------
// Copyright © 2021, tree-sitter-rust authors.
// See the LICENSE file in this repo for license details.
// ------------------------------------------------------------------------------------------------

//! This crate provides a Rust grammar for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this grammar to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! use tree_sitter::Parser;
//!
//! let code = r#"
//! fn double(x: i32) -> i32 {
//! x * 2
//! }
//! "#;
//! let mut parser = Parser::new();
//! parser.set_language(tree_sitter_rust::language()).expect("Error loading Rust grammar");
//! let parsed = parser.parse(code, None);
//! # let parsed = parsed.unwrap();
//! # let root = parsed.root_node();
//! # assert!(!root.has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;

extern "C" {
fn tree_sitter_rust() -> Language;
}

/// Returns the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_rust() }
}

/// The source of the Rust tree-sitter grammar description.
pub const GRAMMAR: &str = include_str!("../../grammar.js");

/// The syntax highlighting query for this language.
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm");

/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

#[cfg(test)]
mod tests {
#[test]
fn can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading Rust grammar");
}
}
87 changes: 52 additions & 35 deletions corpus/async.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,88 @@
============================================
================================================================================
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)
(function_item
(function_modifiers)
(identifier)
(parameters)
(block
(let_declaration (identifier) (try_expression
(await_expression (identifier)))))))
(let_declaration
(identifier)
(try_expression
(await_expression
(identifier)))))))

============================================
================================================================================
Await expression
============================================
================================================================================

futures.await;
futures.await?;
futures.await?.await?;
futures.await?.function().await?;

---
--------------------------------------------------------------------------------

(source_file
(await_expression (identifier))
(try_expression
(await_expression (identifier)))
(try_expression
(expression_statement
(await_expression
(try_expression
(await_expression (identifier)))))
(try_expression
(await_expression
(call_expression
(field_expression
(try_expression
(await_expression (identifier)))
(field_identifier))
(arguments)))))
(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
(async_block
(block))
(async_block
(block
(let_declaration
(identifier)
(integer_literal))))
(async_block
(block)))
(expression_statement
(async_block
(block)))
(expression_statement
(async_block
(block
(let_declaration
(identifier)
(integer_literal)))))
(expression_statement
(async_block
(block))))
Loading