Skip to content

Commit e861cc9

Browse files
committed
Add tree-sitter-mozcpp crate
1 parent fe9cd9a commit e861cc9

File tree

12 files changed

+189
-0
lines changed

12 files changed

+189
-0
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tree-sitter = "^0.17"
3434
tree-sitter-java = "^0.16"
3535
tree-sitter-preproc = { path = "./tree-sitter-preproc" }
3636
tree-sitter-ccomment = { path = "./tree-sitter-ccomment" }
37+
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp" }
3738

3839
[dev-dependencies]
3940
pretty_assertions = "^0.6"

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ fn main() {
158158
let ignore = vec![
159159
"tree-sitter-preproc".to_string(),
160160
"tree-sitter-ccomment".to_string(),
161+
"tree-sitter-mozcpp".to_string(),
161162
"tree-sitter-typescript".to_string(),
162163
"tree-sitter-cpp".to_string(),
163164
];

enums/Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enums/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ tree-sitter = "^0.17"
2020
tree-sitter-java = "^0.16"
2121
tree-sitter-preproc = { path = "../tree-sitter-preproc" }
2222
tree-sitter-ccomment = { path = "../tree-sitter-ccomment" }
23+
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp" }

enums/src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ macro_rules! mk_get_language {
1818
LANG::Java => tree_sitter_java::language(),
1919
LANG::Preproc => tree_sitter_preproc::language(),
2020
LANG::Ccomment => tree_sitter_ccomment::language(),
21+
LANG::Cpp => tree_sitter_mozcpp::language(),
2122
_ => match lang {
2223
$(
2324
LANG::$camel => {

src/macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ macro_rules! get_language {
4747
tree_sitter_ccomment::language()
4848
}
4949
};
50+
(tree_sitter_cpp) => {
51+
fn get_language() -> Language {
52+
tree_sitter_mozcpp::language()
53+
}
54+
};
5055
($name:ident) => {
5156
fn get_language() -> Language {
5257
extern "C" {

tree-sitter-mozcpp/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Cargo.lock
2+
node_modules
3+
build
4+
package-lock.json
5+
/target/

tree-sitter-mozcpp/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "tree-sitter-mozcpp"
3+
description = "Mozcpp grammar for the tree-sitter parsing library"
4+
version = "0.16.0"
5+
authors = ["Calixte Denizet <cdenizet@mozilla.com>"]
6+
license = "MIT"
7+
readme = "bindings/rust/README.md"
8+
keywords = ["incremental", "parsing", "mozcpp"]
9+
categories = ["parsing", "text-editors"]
10+
repository = "https://github.com/tree-sitter/tree-sitter-mozcpp"
11+
edition = "2018"
12+
13+
build = "bindings/rust/build.rs"
14+
include = [
15+
"bindings/rust/*",
16+
"grammar.js",
17+
"src/*",
18+
]
19+
20+
[lib]
21+
path = "bindings/rust/lib.rs"
22+
23+
[dependencies]
24+
tree-sitter = "^0.17"
25+
26+
[build-dependencies]
27+
cc = "^1.0"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# tree-sitter-mozcpp
2+
3+
This crate provides a Mozcpp grammar for the [tree-sitter][] parsing library. To
4+
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
5+
file. (Note that you will probably also need to depend on the
6+
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
7+
way.)
8+
9+
``` toml
10+
[dependencies]
11+
tree-sitter = "0.17"
12+
tree-sitter-mozcpp = "0.16"
13+
```
14+
15+
Typically, you will use the [language][language func] function to add this
16+
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
17+
18+
``` rust
19+
let code = r#"
20+
int double(int x) {
21+
return x * 2;
22+
}
23+
"#;
24+
let mut parser = Parser::new();
25+
parser.set_language(tree_sitter_mozcpp::language()).expect("Error loading Mozcpp grammar");
26+
let parsed = parser.parse(code, None);
27+
```
28+
29+
If you have any questions, please reach out to us in the [tree-sitter
30+
discussions] page.
31+
32+
[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
33+
[language func]: https://docs.rs/tree-sitter-mozcpp/*/tree_sitter_mozcpp/fn.language.html
34+
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
35+
[tree-sitter]: https://tree-sitter.github.io/
36+
[tree-sitter crate]: https://crates.io/crates/tree-sitter
37+
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions

0 commit comments

Comments
 (0)