Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ serde = { version = "^1.0", features = ["derive"] }
termcolor = "^1.2"
walkdir = "^2.3"

tree-sitter = "=0.22.6"
tree-sitter-java = "=0.21.0"
tree-sitter-kotlin = "0.3.6"
tree-sitter-typescript = "=0.21.2"
tree-sitter-javascript = "=0.21.4"
tree-sitter-python = "=0.21.0"
tree-sitter-rust = "=0.21.2"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.2" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.2" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.3" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.2" }
tree-sitter = "=0.25.3"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-ng = "1.1.0"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.23.1"
tree-sitter-python = "=0.23.6"
tree-sitter-rust = "=0.23.2"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.3" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.4" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.3" }

[dev-dependencies]
insta = { version = "1.29.0", features = ["yaml", "json", "redactions"] }
Expand Down
22 changes: 11 additions & 11 deletions enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ edition = "2021"
clap = { version = "^4.0", features = ["derive"] }
askama = "^0.12"

tree-sitter = "=0.22.6"
tree-sitter-java = "=0.21.0"
tree-sitter-kotlin = "0.3.6"
tree-sitter-typescript = "=0.21.2"
tree-sitter-javascript = "=0.21.4"
tree-sitter-python = "=0.21.0"
tree-sitter-rust = "=0.21.2"
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.2" }
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.2" }
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.3" }
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.2" }
tree-sitter = "=0.25.3"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-ng = "1.1.0"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.23.1"
tree-sitter-python = "=0.23.6"
tree-sitter-rust = "=0.23.2"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.3" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.4" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.3" }

[profile.release]
strip = "debuginfo"
2 changes: 1 addition & 1 deletion enums/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tree_sitter::Language;
mk_langs!(
// 1) Name for enum
// 2) tree-sitter function to call to get a Language
(Kotlin, tree_sitter_kotlin),
(Kotlin, tree_sitter_kotlin_ng),
(Java, tree_sitter_java),
(Rust, tree_sitter_rust),
(Cpp, tree_sitter_cpp),
Expand Down
22 changes: 11 additions & 11 deletions enums/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ macro_rules! mk_get_language {
( $( ($camel:ident, $name:ident) ),* ) => {
pub fn get_language(lang: &Lang) -> Language {
match lang {
Lang::Kotlin => tree_sitter_kotlin::language(),
Lang::Java => tree_sitter_java::language(),
Lang::Typescript => tree_sitter_typescript::language_typescript(),
Lang::Tsx => tree_sitter_typescript::language_tsx(),
Lang::Javascript => tree_sitter_javascript::language(),
Lang::Python => tree_sitter_python::language(),
Lang::Rust => tree_sitter_rust::language(),
Lang::Preproc => tree_sitter_preproc::language(),
Lang::Ccomment => tree_sitter_ccomment::language(),
Lang::Cpp => tree_sitter_mozcpp::language(),
Lang::Mozjs => tree_sitter_mozjs::language(),
Lang::Kotlin => tree_sitter_kotlin_ng::LANGUAGE.into(),
Lang::Java => tree_sitter_java::LANGUAGE.into(),
Lang::Typescript => tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
Lang::Tsx => tree_sitter_typescript::LANGUAGE_TSX.into(),
Lang::Javascript => tree_sitter_javascript::LANGUAGE.into(),
Lang::Python => tree_sitter_python::LANGUAGE.into(),
Lang::Rust => tree_sitter_rust::LANGUAGE.into(),
Lang::Preproc => tree_sitter_preproc::LANGUAGE.into(),
Lang::Ccomment => tree_sitter_ccomment::LANGUAGE.into(),
Lang::Cpp => tree_sitter_mozcpp::LANGUAGE.into(),
Lang::Mozjs => tree_sitter_mozjs::LANGUAGE.into(),
}
}
};
Expand Down
10 changes: 8 additions & 2 deletions generate-grammars/generate-mozcpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ npm install -y
# Exit tree-sitter-cpp directory
popd

# Copy tree-sitter-cpp `scanner.cc` functions into the `src` directory
cp --verbose $TS_CPP_CRATE/src/scanner.cc ./src/scanner.cc
# Copy tree-sitter-cpp `scanner.c` functions into the `src` directory
cp --verbose $TS_CPP_CRATE/src/scanner.c ./src/scanner.c

# Since the tree-sitter-mozcpp `scanner.c` file contains the very same functions
# present in the tree-sitter-cpp `scanner.c` file, to avoid having a
# multiple symbol definition error during the linking phase,
# those functions will be assigned a new prefix.
sed -i 's/tree_sitter_cpp/tree_sitter_mozcpp/g' ./src/scanner.c

# Exit tree-sitter-mozcpp directory
popd
Expand Down
17 changes: 9 additions & 8 deletions generate-grammars/generate-mozjs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TS_JS_CRATE="tree-sitter-javascript"
JSON_CRATE_FILENAME=".cargo_vcs_info.json"

# Get the current tree-sitter-javascript crate version
TS_JS_VERSION=`grep $TS_JS_CRATE Cargo.toml | cut -f2 -d "=" | tr -d ' ' | tr -d \"`
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 \"`

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

# Since the tree-sitter-mozjs `scanner.cc` file contains the very same functions
# present in the tree-sitter-javascript `scanner.cc` file, to avoid having a
# multiple symbols definitions error during the linking phase,
# to those functions will be assigned a new prefix and the relative
# output file will be saved into the `src` directory.
SED_PATTERN="s/tree_sitter_javascript_external_scanner_/tree_sitter_javascript_external_scanner_mozjs_/g"
sed $SED_PATTERN $TS_JS_CRATE/src/scanner.c > ./src/tree_sitter_javascript_scanner.c
# Copy tree-sitter-cpp `scanner.c` functions into the `src` directory
cp --verbose $TS_JS_CRATE/src/scanner.c ./src/scanner.c

# Since the tree-sitter-mozjs `scanner.c` file contains the very same functions
# present in the tree-sitter-javascript `scanner.c` file, to avoid having a
# multiple symbol definition error during the linking phase,
# those functions will be assigned a new prefix.
sed -i 's/tree_sitter_javascript/tree_sitter_mozjs/g' ./src/scanner.c

# Exit tree-sitter-mozjs directory
popd
Expand Down
2 changes: 1 addition & 1 deletion src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Checker for CppCode {
return false;
}
if let Some(parent) = node.parent() {
return node.kind_id() == Cpp::IfStatement && parent.kind_id() == Cpp::IfStatement;
return parent.kind_id() == Cpp::ElseClause;
}
false
}
Expand Down
28 changes: 23 additions & 5 deletions src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,24 @@ impl Getter for RustCode {
use Rust::*;

match node.kind_id().into() {
// `||` is treated as an operator only if it's part of a binary expression.
// This prevents misclassification inside macros where closures without arguments (e.g., `let closure = || { /* ... */ };`)
// are not recognized as `ClosureExpression` and their `||` node is identified as `PIPEPIPE` instead of `ClosureParameters`.
//
// Similarly, exclude `/` when it corresponds to the third slash in `///` (`OuterDocCommentMarker`)
PIPEPIPE | SLASH => match node.parent() {
Some(parent) if matches!(parent.kind_id().into(), BinaryExpression) => HalsteadType::Operator,
_ => HalsteadType::Unknown
}
// Ensure `!` is counted as an operator unless it belongs to an `InnerDocCommentMarker` `//!`
BANG => match node.parent() {
Some(parent) if !matches!(parent.kind_id().into(), InnerDocCommentMarker) => HalsteadType::Operator,
_ => HalsteadType::Unknown
}
LPAREN | LBRACE | LBRACK | EQGT | PLUS | STAR | Async | Await | Continue | For | If
| Let | Loop | Match | Return | Unsafe | While | BANG | EQ | COMMA | DASHGT | QMARK
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP | PIPEPIPE
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | SLASH | PERCENT
| Let | Loop | Match | Return | Unsafe | While | EQ | COMMA | DASHGT | QMARK
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | PERCENT
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ | AMPEQ | PIPEEQ | CARETEQ
| LTLTEQ | GTGTEQ | Move | DOT | PrimitiveType | Fn | SEMI => HalsteadType::Operator,
Identifier | StringLiteral | RawStringLiteral | IntegerLiteral | FloatLiteral
Expand Down Expand Up @@ -478,13 +492,17 @@ impl Getter for CppCode {
match node.kind_id().into() {
DOT | LPAREN | LPAREN2 | COMMA | STAR | GTGT | COLON | SEMI | Return | Break
| Continue | If | Else | Switch | Case | Default | For | While | Goto | Do | Delete
| New | Try | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH | DASHGT
| New | Try | Try2 | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH | DASHGT
| PLUS | PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE | LT | LTEQ | EQEQ
| BANGEQ | GTEQ | GT | GT2 | PLUSEQ | BANG | STAREQ | SLASHEQ | PERCENTEQ | GTGTEQ
| LTLTEQ | AMPEQ | CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE | QMARK | COLONCOLON
| PrimitiveType | TypeSpecifier | Sizeof => HalsteadType::Operator,
Identifier | TypeIdentifier | FieldIdentifier | RawStringLiteral | StringLiteral
| NumberLiteral | True | False | Null | Nullptr | DOTDOTDOT => HalsteadType::Operand,
| NumberLiteral | True | False | Null | DOTDOTDOT => HalsteadType::Operand,
NamespaceIdentifier => match node.parent() {
Some(parent) if matches!(parent.kind_id().into(), NamespaceDefinition) => HalsteadType::Operand,
_ => HalsteadType::Unknown,
},
_ => HalsteadType::Unknown,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mk_langs!(
"kotlin",
KotlinCode,
KotlinParser,
tree_sitter_kotlin,
tree_sitter_kotlin_ng,
[kt, kts],
["kotlin"]
),
Expand Down
Loading