Skip to content

Commit cafe29b

Browse files
authored
Update grammars (#1141)
* Bump tree-sitter to 0.25.3 * Bump tree-sitter-java to 0.23.5 * Replace tree-sitter-kotlin with tree-sitter-kotlin-ng 1.1.0 * Bump tree-sitter-typescript to 0.23.2 * Bump tree-sitter-javascript to 0.23.1 * Bump tree-sitter-python to 0.23.6 * Bump tree-sitter-rust to 0.23.2 * Bump tree-sitter-preproc to 0.20.3 * Bump tree-sitter-ccomment to 0.20.3 * Bump tree-sitter-mozcpp to 0.20.4 * Bump tree-sitter-mozjs to 0.20.3 * Sync rca-output
1 parent efe9894 commit cafe29b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+747858
-449376
lines changed

Cargo.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ serde = { version = "^1.0", features = ["derive"] }
2424
termcolor = "^1.2"
2525
walkdir = "^2.3"
2626

27-
tree-sitter = "=0.22.6"
28-
tree-sitter-java = "=0.21.0"
29-
tree-sitter-kotlin = "0.3.6"
30-
tree-sitter-typescript = "=0.21.2"
31-
tree-sitter-javascript = "=0.21.4"
32-
tree-sitter-python = "=0.21.0"
33-
tree-sitter-rust = "=0.21.2"
34-
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.2" }
35-
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.2" }
36-
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.3" }
37-
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.2" }
27+
tree-sitter = "=0.25.3"
28+
tree-sitter-java = "=0.23.5"
29+
tree-sitter-kotlin-ng = "1.1.0"
30+
tree-sitter-typescript = "=0.23.2"
31+
tree-sitter-javascript = "=0.23.1"
32+
tree-sitter-python = "=0.23.6"
33+
tree-sitter-rust = "=0.23.2"
34+
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" }
35+
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.3" }
36+
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.4" }
37+
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.3" }
3838

3939
[dev-dependencies]
4040
insta = { version = "1.29.0", features = ["yaml", "json", "redactions"] }

enums/Cargo.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ edition = "2021"
88
clap = { version = "^4.0", features = ["derive"] }
99
askama = "^0.12"
1010

11-
tree-sitter = "=0.22.6"
12-
tree-sitter-java = "=0.21.0"
13-
tree-sitter-kotlin = "0.3.6"
14-
tree-sitter-typescript = "=0.21.2"
15-
tree-sitter-javascript = "=0.21.4"
16-
tree-sitter-python = "=0.21.0"
17-
tree-sitter-rust = "=0.21.2"
18-
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.2" }
19-
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.2" }
20-
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.3" }
21-
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.2" }
11+
tree-sitter = "=0.25.3"
12+
tree-sitter-java = "=0.23.5"
13+
tree-sitter-kotlin-ng = "1.1.0"
14+
tree-sitter-typescript = "=0.23.2"
15+
tree-sitter-javascript = "=0.23.1"
16+
tree-sitter-python = "=0.23.6"
17+
tree-sitter-rust = "=0.23.2"
18+
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" }
19+
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.3" }
20+
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.4" }
21+
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.3" }
2222

2323
[profile.release]
2424
strip = "debuginfo"

enums/src/languages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use tree_sitter::Language;
33
mk_langs!(
44
// 1) Name for enum
55
// 2) tree-sitter function to call to get a Language
6-
(Kotlin, tree_sitter_kotlin),
6+
(Kotlin, tree_sitter_kotlin_ng),
77
(Java, tree_sitter_java),
88
(Rust, tree_sitter_rust),
99
(Cpp, tree_sitter_cpp),

enums/src/macros.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ macro_rules! mk_get_language {
1919
( $( ($camel:ident, $name:ident) ),* ) => {
2020
pub fn get_language(lang: &Lang) -> Language {
2121
match lang {
22-
Lang::Kotlin => tree_sitter_kotlin::language(),
23-
Lang::Java => tree_sitter_java::language(),
24-
Lang::Typescript => tree_sitter_typescript::language_typescript(),
25-
Lang::Tsx => tree_sitter_typescript::language_tsx(),
26-
Lang::Javascript => tree_sitter_javascript::language(),
27-
Lang::Python => tree_sitter_python::language(),
28-
Lang::Rust => tree_sitter_rust::language(),
29-
Lang::Preproc => tree_sitter_preproc::language(),
30-
Lang::Ccomment => tree_sitter_ccomment::language(),
31-
Lang::Cpp => tree_sitter_mozcpp::language(),
32-
Lang::Mozjs => tree_sitter_mozjs::language(),
22+
Lang::Kotlin => tree_sitter_kotlin_ng::LANGUAGE.into(),
23+
Lang::Java => tree_sitter_java::LANGUAGE.into(),
24+
Lang::Typescript => tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
25+
Lang::Tsx => tree_sitter_typescript::LANGUAGE_TSX.into(),
26+
Lang::Javascript => tree_sitter_javascript::LANGUAGE.into(),
27+
Lang::Python => tree_sitter_python::LANGUAGE.into(),
28+
Lang::Rust => tree_sitter_rust::LANGUAGE.into(),
29+
Lang::Preproc => tree_sitter_preproc::LANGUAGE.into(),
30+
Lang::Ccomment => tree_sitter_ccomment::LANGUAGE.into(),
31+
Lang::Cpp => tree_sitter_mozcpp::LANGUAGE.into(),
32+
Lang::Mozjs => tree_sitter_mozjs::LANGUAGE.into(),
3333
}
3434
}
3535
};

generate-grammars/generate-mozcpp.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ npm install -y
5353
# Exit tree-sitter-cpp directory
5454
popd
5555

56-
# Copy tree-sitter-cpp `scanner.cc` functions into the `src` directory
57-
cp --verbose $TS_CPP_CRATE/src/scanner.cc ./src/scanner.cc
56+
# Copy tree-sitter-cpp `scanner.c` functions into the `src` directory
57+
cp --verbose $TS_CPP_CRATE/src/scanner.c ./src/scanner.c
58+
59+
# Since the tree-sitter-mozcpp `scanner.c` file contains the very same functions
60+
# present in the tree-sitter-cpp `scanner.c` file, to avoid having a
61+
# multiple symbol definition error during the linking phase,
62+
# those functions will be assigned a new prefix.
63+
sed -i 's/tree_sitter_cpp/tree_sitter_mozcpp/g' ./src/scanner.c
5864

5965
# Exit tree-sitter-mozcpp directory
6066
popd

generate-grammars/generate-mozjs.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TS_JS_CRATE="tree-sitter-javascript"
1212
JSON_CRATE_FILENAME=".cargo_vcs_info.json"
1313

1414
# Get the current tree-sitter-javascript crate version
15-
TS_JS_VERSION=`grep $TS_JS_CRATE Cargo.toml | cut -f2 -d "=" | tr -d ' ' | tr -d \"`
15+
TS_JS_VERSION=`grep -m 1 $TS_JS_CRATE tree-sitter-mozjs/Cargo.toml | cut -f2 -d "," | cut -f2 -d "=" | tr -d ' ' | tr -d } | tr -d \"`
1616

1717
# Name assigned to the compressed binary crate downloaded from crates.io
1818
CRATE_OUTPUT="$TS_JS_CRATE-download.gz"
@@ -50,13 +50,14 @@ git checkout FETCH_HEAD
5050
# Exit tree-sitter-javascript directory
5151
popd
5252

53-
# Since the tree-sitter-mozjs `scanner.cc` file contains the very same functions
54-
# present in the tree-sitter-javascript `scanner.cc` file, to avoid having a
55-
# multiple symbols definitions error during the linking phase,
56-
# to those functions will be assigned a new prefix and the relative
57-
# output file will be saved into the `src` directory.
58-
SED_PATTERN="s/tree_sitter_javascript_external_scanner_/tree_sitter_javascript_external_scanner_mozjs_/g"
59-
sed $SED_PATTERN $TS_JS_CRATE/src/scanner.c > ./src/tree_sitter_javascript_scanner.c
53+
# Copy tree-sitter-cpp `scanner.c` functions into the `src` directory
54+
cp --verbose $TS_JS_CRATE/src/scanner.c ./src/scanner.c
55+
56+
# Since the tree-sitter-mozjs `scanner.c` file contains the very same functions
57+
# present in the tree-sitter-javascript `scanner.c` file, to avoid having a
58+
# multiple symbol definition error during the linking phase,
59+
# those functions will be assigned a new prefix.
60+
sed -i 's/tree_sitter_javascript/tree_sitter_mozjs/g' ./src/scanner.c
6061

6162
# Exit tree-sitter-mozjs directory
6263
popd

src/checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl Checker for CppCode {
253253
return false;
254254
}
255255
if let Some(parent) = node.parent() {
256-
return node.kind_id() == Cpp::IfStatement && parent.kind_id() == Cpp::IfStatement;
256+
return parent.kind_id() == Cpp::ElseClause;
257257
}
258258
false
259259
}

src/getter.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,24 @@ impl Getter for RustCode {
396396
use Rust::*;
397397

398398
match node.kind_id().into() {
399+
// `||` is treated as an operator only if it's part of a binary expression.
400+
// This prevents misclassification inside macros where closures without arguments (e.g., `let closure = || { /* ... */ };`)
401+
// are not recognized as `ClosureExpression` and their `||` node is identified as `PIPEPIPE` instead of `ClosureParameters`.
402+
//
403+
// Similarly, exclude `/` when it corresponds to the third slash in `///` (`OuterDocCommentMarker`)
404+
PIPEPIPE | SLASH => match node.parent() {
405+
Some(parent) if matches!(parent.kind_id().into(), BinaryExpression) => HalsteadType::Operator,
406+
_ => HalsteadType::Unknown
407+
}
408+
// Ensure `!` is counted as an operator unless it belongs to an `InnerDocCommentMarker` `//!`
409+
BANG => match node.parent() {
410+
Some(parent) if !matches!(parent.kind_id().into(), InnerDocCommentMarker) => HalsteadType::Operator,
411+
_ => HalsteadType::Unknown
412+
}
399413
LPAREN | LBRACE | LBRACK | EQGT | PLUS | STAR | Async | Await | Continue | For | If
400-
| Let | Loop | Match | Return | Unsafe | While | BANG | EQ | COMMA | DASHGT | QMARK
401-
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP | PIPEPIPE
402-
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | SLASH | PERCENT
414+
| Let | Loop | Match | Return | Unsafe | While | EQ | COMMA | DASHGT | QMARK
415+
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP
416+
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | PERCENT
403417
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ | AMPEQ | PIPEEQ | CARETEQ
404418
| LTLTEQ | GTGTEQ | Move | DOT | PrimitiveType | Fn | SEMI => HalsteadType::Operator,
405419
Identifier | StringLiteral | RawStringLiteral | IntegerLiteral | FloatLiteral
@@ -478,13 +492,17 @@ impl Getter for CppCode {
478492
match node.kind_id().into() {
479493
DOT | LPAREN | LPAREN2 | COMMA | STAR | GTGT | COLON | SEMI | Return | Break
480494
| Continue | If | Else | Switch | Case | Default | For | While | Goto | Do | Delete
481-
| New | Try | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH | DASHGT
495+
| New | Try | Try2 | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH | DASHGT
482496
| PLUS | PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE | LT | LTEQ | EQEQ
483497
| BANGEQ | GTEQ | GT | GT2 | PLUSEQ | BANG | STAREQ | SLASHEQ | PERCENTEQ | GTGTEQ
484498
| LTLTEQ | AMPEQ | CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE | QMARK | COLONCOLON
485499
| PrimitiveType | TypeSpecifier | Sizeof => HalsteadType::Operator,
486500
Identifier | TypeIdentifier | FieldIdentifier | RawStringLiteral | StringLiteral
487-
| NumberLiteral | True | False | Null | Nullptr | DOTDOTDOT => HalsteadType::Operand,
501+
| NumberLiteral | True | False | Null | DOTDOTDOT => HalsteadType::Operand,
502+
NamespaceIdentifier => match node.parent() {
503+
Some(parent) if matches!(parent.kind_id().into(), NamespaceDefinition) => HalsteadType::Operand,
504+
_ => HalsteadType::Unknown,
505+
},
488506
_ => HalsteadType::Unknown,
489507
}
490508
}

src/langs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mk_langs!(
5353
"kotlin",
5454
KotlinCode,
5555
KotlinParser,
56-
tree_sitter_kotlin,
56+
tree_sitter_kotlin_ng,
5757
[kt, kts],
5858
["kotlin"]
5959
),

0 commit comments

Comments
 (0)