From b6db1f63cb8d9696eee7a9d90afdafb79de07859 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 15:34:27 +0200 Subject: [PATCH 01/42] kotlin: Add loc metrics --- src/metrics/loc.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index d081ab489..23e7e49b1 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -856,7 +856,29 @@ impl Loc for JavaCode { } } -implement_metric_trait!(Loc, PreprocCode, CcommentCode, KotlinCode); +implement_metric_trait!(Loc, PreprocCode, CcommentCode); + +impl Loc for KotlinCode { + fn compute(node: &Node, stats: &mut Stats, is_func_space: bool, is_unit: bool) { + use Kotlin::*; + + let (start, end) = init(node, stats, is_func_space, is_unit); + let kind_id: Kotlin = node.kind_id().into(); + match kind_id { + Comment => { + add_cloc_lines(stats, start, end); + } + Statements | Statement | LoopStatement | ForStatement | WhileStatement + | DoWhileStatement | StatementRepeat1 => { + stats.lloc.logical_lines += 1; + } + _ => { + check_comment_ends_on_code_line(stats, start); + stats.ploc.lines.insert(start); + } + } + } +} #[cfg(test)] mod tests { From 28b6ec3dde6f7c03e3c84cc81c14320e4e25862f Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 17:57:41 +0200 Subject: [PATCH 02/42] kotlin: add npa metric --- src/metrics/npa.rs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index 64338b76c..01648af74 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -23,6 +23,7 @@ pub struct Stats { class_na_sum: usize, interface_na_sum: usize, is_class_space: bool, + is_interface: bool, } impl Serialize for Stats { @@ -265,10 +266,49 @@ implement_metric_trait!( RustCode, CppCode, PreprocCode, - CcommentCode, - KotlinCode + CcommentCode ); +impl Npa for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + use Kotlin::*; + + // Enables the `Npa` metric if computing stats of a class space + if Self::is_func_space(node) && stats.is_disabled() { + stats.is_class_space = true; + } + + if let ClassDeclaration = node.kind_id().into() { + for class_child in node.children() { + match class_child.kind_id().into() { + Interface => stats.is_interface = true, + ClassBody => { + for node in class_child.children() { + if matches!(node.kind_id().into(), PropertyDeclaration) { + for modifiers in node.children() { + if matches!(modifiers.kind_id().into(), Modifiers) + && modifiers.child(0).map_or(false, |modifier| { + matches!(modifier.kind_id().into(), VisibilityModifier) + && modifier.first_child(|id| id == Public).is_some() + }) + { + if stats.is_interface { + stats.interface_npa += 1; + } else { + stats.class_npa += 1; + } + } + } + } + } + } + _ => (), + } + } + } + } +} + #[cfg(test)] mod tests { use crate::tools::check_metrics; From 17cc0eb7d99ac6682452d0abdbabe335836e6606 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 18:01:27 +0200 Subject: [PATCH 03/42] kotlin: Add cyclomatic metric --- src/metrics/cyclomatic.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/metrics/cyclomatic.rs b/src/metrics/cyclomatic.rs index 3bbc93a65..d959b5356 100644 --- a/src/metrics/cyclomatic.rs +++ b/src/metrics/cyclomatic.rs @@ -221,7 +221,20 @@ impl Cyclomatic for JavaCode { } } -implement_metric_trait!(Cyclomatic, KotlinCode, PreprocCode, CcommentCode); +implement_metric_trait!(Cyclomatic, PreprocCode, CcommentCode); + +impl Cyclomatic for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + use Kotlin::*; + + match node.kind_id().into() { + If | For | While | WhenEntry | Catch | AMPAMP | PIPEPIPE => { + stats.cyclomatic += 1.; + } + _ => {} + } + } +} #[cfg(test)] mod tests { From 6c13b6c32b305464f42649ef63d6bdf711e1369a Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 18:14:50 +0200 Subject: [PATCH 04/42] kotlin: Add exit metric --- src/metrics/exit.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/metrics/exit.rs b/src/metrics/exit.rs index 774419c99..33a8aab47 100644 --- a/src/metrics/exit.rs +++ b/src/metrics/exit.rs @@ -182,7 +182,15 @@ impl Exit for JavaCode { } } -implement_metric_trait!(Exit, KotlinCode, PreprocCode, CcommentCode); +implement_metric_trait!(Exit, PreprocCode, CcommentCode); + +impl Exit for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + if matches!(node.kind_id().into(), Kotlin::Return) { + stats.exit += 1; + } + } +} #[cfg(test)] mod tests { From d28585ebac995e1394363a6f1607c6b325fb75e6 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 18:18:54 +0200 Subject: [PATCH 05/42] kotlin: add wmc metric --- src/metrics/wmc.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/metrics/wmc.rs b/src/metrics/wmc.rs index c2b02b560..45eac8296 100644 --- a/src/metrics/wmc.rs +++ b/src/metrics/wmc.rs @@ -124,18 +124,16 @@ where fn compute(space_kind: SpaceKind, cyclomatic: &cyclomatic::Stats, stats: &mut Stats); } -impl Wmc for JavaCode { - fn compute(space_kind: SpaceKind, cyclomatic: &cyclomatic::Stats, stats: &mut Stats) { - use SpaceKind::*; +fn compute_wmc(space_kind: SpaceKind, cyclomatic: &cyclomatic::Stats, stats: &mut Stats) { + use SpaceKind::*; - if let Unit | Class | Interface | Function = space_kind { - if stats.space_kind == Unknown { - stats.space_kind = space_kind; - } - if space_kind == Function { - // Saves the cyclomatic complexity of the method - stats.cyclomatic = cyclomatic.cyclomatic_sum(); - } + if let Unit | Class | Interface | Function = space_kind { + if stats.space_kind == Unknown { + stats.space_kind = space_kind; + } + if space_kind == Function { + // Saves the cyclomatic complexity of the method + stats.cyclomatic = cyclomatic.cyclomatic_sum(); } } } @@ -150,10 +148,21 @@ implement_metric_trait!( RustCode, CppCode, PreprocCode, - CcommentCode, - KotlinCode + CcommentCode ); +impl Wmc for JavaCode { + fn compute(space_kind: SpaceKind, cyclomatic: &cyclomatic::Stats, stats: &mut Stats) { + compute_wmc(space_kind, cyclomatic, stats) + } +} + +impl Wmc for KotlinCode { + fn compute(space_kind: SpaceKind, cyclomatic: &cyclomatic::Stats, stats: &mut Stats) { + compute_wmc(space_kind, cyclomatic, stats) + } +} + #[cfg(test)] mod tests { use crate::tools::check_metrics; From bd8605eff01fee195d45a60ffa279f531c8b440c Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 23:14:48 +0200 Subject: [PATCH 06/42] kotlin: implement getter --- src/getter.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/getter.rs b/src/getter.rs index 8a03adc50..7311d75e8 100644 --- a/src/getter.rs +++ b/src/getter.rs @@ -576,4 +576,48 @@ impl Getter for JavaCode { } } -impl Getter for KotlinCode {} +impl Getter for KotlinCode { + fn get_space_kind(node: &Node) -> SpaceKind { + use Kotlin::*; + + let typ = node.object().kind_id().into(); + match typ { + ClassDeclaration => SpaceKind::Class, + FunctionDeclaration | Constructor | AnnotatedLambda => SpaceKind::Function, + SourceFile => SpaceKind::Unit, + _ => SpaceKind::Unknown, + } + } + + fn get_op_type(node: &Node) -> HalsteadType { + use Kotlin::*; + + let typ = node.object().kind_id(); + + match typ.into() { + // Operator: function calls + CallExpression + // Operator: control flow + | If | Else | When | Try | Catch | Throw | For | While | Continue | Break | Do | Finally + // Operator: keywords + | Return | Abstract | Final | Super | This + // Operator: brackets and comma and terminators (separators) + | SEMI | COMMA | COLONCOLON | LBRACE | LBRACK | LPAREN | RBRACE | RBRACK | RPAREN | DOTDOT | DOT + // Operator: operators + | EQ | LT | GT | BANG | QMARKCOLON | AsQMARK | COLON // no grammar for lambda operator -> + | EQEQ | LTEQ | GTEQ | BANGEQ | AMPAMP | PIPEPIPE | PLUSPLUS | DASHDASH + | PLUS | DASH | STAR | SLASH | PERCENT + | PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ + // Operands: variables, constants, literals + | RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1 + | LiteralConstant | StringLiteral | LineStringLiteral | MultiLineStringLiteral | LambdaLiteral | FunctionLiteral => { + HalsteadType::Operand + }, + _ => { + HalsteadType::Unknown + }, + } + } + + get_operator!(Kotlin); +} From 73e5b493f6a504555935d0c89d0f2aeb7ed55cd6 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 27 Mar 2023 23:26:34 +0200 Subject: [PATCH 07/42] kotlin: implement checker --- src/checker.rs | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index 75c433b82..2e0fef2a7 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -663,39 +663,59 @@ impl Checker for RustCode { } impl Checker for KotlinCode { - fn is_comment(_: &Node) -> bool { - false + fn is_comment(node: &Node) -> bool { + node.object().kind_id() == Kotlin::Comment } fn is_useful_comment(_: &Node, _: &[u8]) -> bool { false } - fn is_func_space(_: &Node) -> bool { - false + fn is_func_space(node: &Node) -> bool { + matches!( + node.object().kind_id().into(), + Kotlin::SourceFile | Kotlin::FunctionDeclaration | Kotlin::LambdaLiteral + ) } - fn is_func(_: &Node) -> bool { - false + fn is_func(node: &Node) -> bool { + node.object().kind_id() == Kotlin::FunctionDeclaration } fn is_closure(_: &Node) -> bool { false } - fn is_call(_: &Node) -> bool { - false + fn is_call(node: &Node) -> bool { + node.object().kind_id() == Kotlin::CallExpression } - fn is_non_arg(_: &Node) -> bool { - false + fn is_non_arg(node: &Node) -> bool { + matches!( + node.object().kind_id().into(), + Kotlin::LPAREN + | Kotlin::COMMA + | Kotlin::RPAREN + | Kotlin::PIPEPIPE + | Kotlin::UnaryExpression + ) } - fn is_string(_: &Node) -> bool { - false + fn is_string(node: &Node) -> bool { + matches!( + node.object().kind_id().into(), + Kotlin::StringLiteral | Kotlin::LineStringLiteral | Kotlin::MultiLineStringLiteral + ) } - fn is_else_if(_: &Node) -> bool { + fn is_else_if(node: &Node) -> bool { + if node.object().kind_id() != Kotlin::IfExpression { + return false; + } + if let Some(parent) = node.object().parent() { + return parent.kind_id() == Kotlin::Else; + } + false } From 5735eb4421b4eae40b3f778fe8c541ea0f18ec8a Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 28 Mar 2023 11:54:46 +0200 Subject: [PATCH 08/42] kotlin: add npm metric --- src/asttools.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++++ src/metrics/npm.rs | 46 ++++++++++++++++++++++- 2 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/asttools.rs diff --git a/src/asttools.rs b/src/asttools.rs new file mode 100644 index 000000000..6a93afccc --- /dev/null +++ b/src/asttools.rs @@ -0,0 +1,94 @@ +use crate::node::Node; + +#[allow(dead_code)] +pub fn get_parent<'a>(node: &'a Node<'a>, level: usize) -> Option> { + let mut level = level; + let mut node = *node; + while level != 0 { + if let Some(parent) = node.object().parent() { + node = Node::new(parent); + } else { + return None; + } + level -= 1; + } + + Some(node) +} + +// Traverse a tree passing from children to children in search of a specific +// token or series of tokens +pub(crate) fn traverse_children<'a, F>(node: &'a Node<'a>, token_list: &[F]) -> Option> +where + F: FnOnce(u16) -> bool + Copy, +{ + let mut node = *node; + 'outer: for token in token_list { + for temp_node in node.children() { + if token(temp_node.object().kind_id()) { + node = temp_node; + continue 'outer; + } + } + // If a token has not been found, return None + return None; + } + Some(node) +} + +macro_rules! has_ancestors { + ($node:expr, $( $typs:pat_param )|*, $( $typ:pat_param ),+) => {{ + let mut res = false; + loop { + let mut node = *$node; + $( + if let Some(parent) = node.object().parent() { + match parent.kind_id().into() { + $typ => { + node = Node::new(parent); + }, + _ => { + break; + } + } + } else { + break; + } + )* + if let Some(parent) = node.object().parent() { + match parent.kind_id().into() { + $( $typs )|+ => { + res = true; + }, + _ => { + break; + } + } + } else { + break; + } + break; + } + res + }}; +} + +macro_rules! count_specific_ancestors { + ($node:expr, $( $typs:pat_param )|*, $( $stops:pat_param )|*) => {{ + let mut count = 0; + let mut node = *$node; + while let Some(parent) = node.object().parent() { + match parent.kind_id().into() { + $( $typs )|* => { + if !Self::is_else_if(&Node::new(parent)) { + count += 1; + } + }, + $( $stops )|* => break, + _ => {} + } + node = Node::new(parent); + } + count + }}; +} diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index 9a248e2d2..ca499df11 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -2,6 +2,7 @@ use serde::Serialize; use serde::ser::{SerializeStruct, Serializer}; use std::fmt; +use crate::asttools::traverse_children; use crate::checker::Checker; use crate::langs::*; use crate::macros::implement_metric_trait; @@ -23,6 +24,7 @@ pub struct Stats { class_nm_sum: usize, interface_nm_sum: usize, is_class_space: bool, + is_interface: bool, } impl Serialize for Stats { @@ -256,10 +258,50 @@ implement_metric_trait!( RustCode, CppCode, PreprocCode, - CcommentCode, - KotlinCode + CcommentCode ); +impl Npm for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + use Kotlin::*; + + // Enables the `Npm` metric if computing stats of a class space + if Self::is_func_space(node) && stats.is_disabled() { + stats.is_class_space = true; + } + + if node.kind_id() == ClassDeclaration { + for class_child in node.children() { + match class_child.kind_id().into() { + Interface => stats.is_interface = true, + ClassBody => { + for node in class_child.children() { + if node.kind_id() == FunctionDeclaration + && traverse_children( + &node, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if stats.is_interface { + stats.interface_npm += 1; + } else { + stats.class_npm += 1; + } + } + } + } + _ => (), + } + } + } + } +} + #[cfg(test)] mod tests { use crate::tools::check_metrics; From 0c6ede24803df8fef94faccf10a6e418251e7c90 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 28 Mar 2023 16:41:05 +0200 Subject: [PATCH 09/42] kotlin: fix npm --- src/metrics/npm.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index ca499df11..8b168ff0a 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -288,9 +288,11 @@ impl Npm for KotlinCode { .is_none() { if stats.is_interface { - stats.interface_npm += 1; + stats.interface_nm += 1; + stats.interface_npm = stats.interface_nm; } else { stats.class_npm += 1; + stats.class_nm = stats.class_npm; } } } From 0093646ee3fdaeb3b1fea76f3516cdadc2e457f9 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 28 Mar 2023 16:41:13 +0200 Subject: [PATCH 10/42] kotlin: simplify npa --- src/metrics/npa.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index 01648af74..2d8bc5f39 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -2,6 +2,7 @@ use serde::Serialize; use serde::ser::{SerializeStruct, Serializer}; use std::fmt; +use crate::asttools::traverse_children; use crate::checker::Checker; use crate::langs::*; use crate::macros::implement_metric_trait; @@ -284,20 +285,23 @@ impl Npa for KotlinCode { Interface => stats.is_interface = true, ClassBody => { for node in class_child.children() { - if matches!(node.kind_id().into(), PropertyDeclaration) { - for modifiers in node.children() { - if matches!(modifiers.kind_id().into(), Modifiers) - && modifiers.child(0).map_or(false, |modifier| { - matches!(modifier.kind_id().into(), VisibilityModifier) - && modifier.first_child(|id| id == Public).is_some() - }) - { - if stats.is_interface { - stats.interface_npa += 1; - } else { - stats.class_npa += 1; - } - } + if node.kind_id() == PropertyDeclaration + && traverse_children( + &node, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if stats.is_interface { + stats.interface_na += 1; + stats.interface_npa = stats.interface_na; + } else { + stats.class_npa += 1; + stats.class_na = stats.class_npa; } } } From 196053f65da3f4b52efd102a06c571229f99e8c2 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 28 Mar 2023 16:43:02 +0200 Subject: [PATCH 11/42] kotlin: implement halstead --- src/metrics/halstead.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/metrics/halstead.rs b/src/metrics/halstead.rs index a244e2cdc..fc0604edf 100644 --- a/src/metrics/halstead.rs +++ b/src/metrics/halstead.rs @@ -328,7 +328,13 @@ impl Halstead for JavaCode { } } -implement_metric_trait!(Halstead, KotlinCode, PreprocCode, CcommentCode); +implement_metric_trait!(Halstead, PreprocCode, CcommentCode); + +impl Halstead for KotlinCode { + fn compute<'a>(node: &Node<'a>, code: &'a [u8], halstead_maps: &mut HalsteadMaps<'a>) { + compute_halstead::(node, code, halstead_maps); + } +} #[cfg(test)] mod tests { From 0f64bec6b9a60678b2f3248e22e325b024ac39ee Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 28 Mar 2023 17:04:12 +0200 Subject: [PATCH 12/42] kotlin: implement abc --- src/metrics/abc.rs | 235 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 2 deletions(-) diff --git a/src/metrics/abc.rs b/src/metrics/abc.rs index 2a1e62a89..52b47c34c 100644 --- a/src/metrics/abc.rs +++ b/src/metrics/abc.rs @@ -352,8 +352,7 @@ implement_metric_trait!( RustCode, CppCode, PreprocCode, - CcommentCode, - KotlinCode + CcommentCode ); // Fitzpatrick, Jerry (1997). "Applying the ABC metric to C, C++ and Java". C++ Report. @@ -546,6 +545,238 @@ impl Abc for JavaCode { } } +// Inspects the content of Kotlin parenthesized expressions +// and `Not` operators to find unary conditional expressions +fn kotlin_inspect_container(container_node: &Node, conditions: &mut f64) { + use Kotlin::*; + + let mut node = *container_node; + let mut node_kind = node.kind_id().into(); + + // Initializes the flag to true if the container is known to contain a boolean value + let mut has_boolean_content = matches!( + node.parent().unwrap().kind_id().into(), + BinaryExpression | IfExpression | WhileStatement | DoWhileStatement | ForStatement + ); + + // Looks inside parenthesized expressions and `Not` operators to find what they contain + loop { + // Checks if the node is a parenthesized expression or a `Not` operator + // The child node of index 0 contains the unary expression operator (we look for the `!` operator) + let is_parenthesised_exp = matches!(node_kind, ParenthesizedExpression); + let is_not_operator = matches!(node_kind, UnaryExpression) + && matches!(node.child(0).unwrap().kind_id().into(), BANG); + + // Stops the exploration if the node is neither + // a parenthesized expression nor a `Not` operator + if !is_parenthesised_exp && !is_not_operator { + break; + } + + // Sets the flag to true if a `Not` operator is found + // This is used to prove if a variable or a value returned by a method is actually boolean + // e.g. `return (!x);` + if !has_boolean_content && is_not_operator { + has_boolean_content = true; + } + + // Parenthesized expressions and `Not` operators nodes + // always store their expressions in the children nodes of index one + // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2472 + // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2150 + node = node.child(1).unwrap(); + node_kind = node.kind_id().into(); + + // Stops the exploration when the content is found + if matches!(node_kind, CallExpression | Identifier | True | False) { + if has_boolean_content { + *conditions += 1.; + } + break; + } + } +} + +// Inspects a list of elements and counts any unary conditional expression found +fn kotlin_count_unary_conditions(list_node: &Node, conditions: &mut f64) { + use Kotlin::*; + + let list_kind = list_node.kind_id().into(); + let mut cursor = list_node.cursor(); + + // Scans the immediate children nodes of the argument node + if cursor.goto_first_child() { + loop { + // Gets the current child node and its kind + let node = cursor.node(); + let node_kind = node.kind_id().into(); + + // Checks if the node is a unary condition + if matches!(node_kind, CallExpression | Identifier | True | False) + && matches!(list_kind, BinaryExpression) + { + *conditions += 1.; + } else { + // Checks if the node is a unary condition container + kotlin_inspect_container(&node, conditions); + } + + // Moves the cursor to the next sibling node of the current node + // Exits the scan if there is no next sibling node + if !cursor.goto_next_sibling() { + break; + } + } + } +} + +impl Abc for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + use Kotlin::*; + + match node.kind_id().into() { + STAREQ | SLASHEQ | PERCENTEQ | DASHEQ | PLUSEQ | PLUSPLUS | DASHDASH => { + stats.assignments += 1.; + } + VariableDeclaration | PropertyDeclaration => { + stats.declaration.push(DeclKind::Var); + } + Final => { + if let Some(DeclKind::Var) = stats.declaration.last() { + stats.declaration.push(DeclKind::Const); + } + } + SEMI => { + if let Some(DeclKind::Const | DeclKind::Var) = stats.declaration.last() { + stats.declaration.clear(); + } + } + EQ => { + // Excludes constant declarations + stats + .declaration + .last() + .map(|decl| { + if matches!(decl, DeclKind::Var) { + stats.assignments += 1.; + } + }) + .unwrap_or_else(|| { + stats.assignments += 1.; + }); + } + CallExpression => { + stats.branches += 1.; + } + GTEQ | LTEQ | EQEQ | BANGEQ | Else | Try | Catch => { + stats.conditions += 1.; + } + GT | LT => { + // Excludes `<` and `>` used for generic types + if let Some(parent) = node.parent() { + if !matches!(parent.kind_id().into(), TypeArguments) { + stats.conditions += 1.; + } + } + } + // Counts unary conditions in elements separated by `&&` or `||` boolean operators + AMPAMP | PIPEPIPE => { + if let Some(parent) = node.parent() { + kotlin_count_unary_conditions(&parent, &mut stats.conditions); + } + } + // Counts unary conditions inside assignments + Assignment => { + // The child node of index 2 contains the right operand of an assignment operation + if let Some(right_operand) = node.child(2) { + if matches!( + right_operand.kind_id().into(), + ParenthesizedExpression | UnaryExpression + ) { + kotlin_inspect_container(&right_operand, &mut stats.conditions); + } + } + } + // Counts unary conditions inside if and while statements + IfExpression | WhileStatement => { + // The child node of index 1 contains the condition + if let Some(condition) = node.child(1) { + if matches!(condition.kind_id().into(), ParenthesizedExpression) { + kotlin_inspect_container(&condition, &mut stats.conditions); + } + } + } + // Counts unary conditions do-while statements + DoWhileStatement => { + // The child node of index 3 contains the condition + if let Some(condition) = node.child(3) { + if matches!(condition.kind_id().into(), ParenthesizedExpression) { + kotlin_inspect_container(&condition, &mut stats.conditions); + } + } + } + // Counts unary conditions inside for statements + ForStatement => { + // The child node of index 3 contains the `condition` when + // the initialization expression is a variable declaration + // e.g. `for ( int i=0; `condition`; ... ) {}` + if let Some(condition) = node.child(3) { + match condition.kind_id().into() { + SEMI => { + // The child node of index 4 contains the `condition` when + // the initialization expression is not a variable declaration + // e.g. `for ( i=0; `condition`; ... ) {}` + if let Some(cond) = node.child(4) { + match cond.kind_id().into() { + CallExpression | Identifier | True | False | SEMI | RPAREN => { + stats.conditions += 1.; + } + ParenthesizedExpression | UnaryExpression => { + kotlin_inspect_container(&cond, &mut stats.conditions); + } + _ => {} + } + } + } + CallExpression | Identifier | True | False => { + stats.conditions += 1.; + } + ParenthesizedExpression | UnaryExpression => { + kotlin_inspect_container(&condition, &mut stats.conditions); + } + _ => {} + } + } + } + // Counts unary conditions inside return statements + Return => { + // The child node of index 1 contains the return value + if let Some(value) = node.child(1) { + if matches!( + value.kind_id().into(), + ParenthesizedExpression | UnaryExpression + ) { + kotlin_inspect_container(&value, &mut stats.conditions) + } + } + } + // Counts unary conditions inside implicit return statements in lambda expressions + AnnotatedLambda => { + // The child node of index 2 contains the return value + if let Some(value) = node.child(2) { + if matches!( + value.kind_id().into(), + ParenthesizedExpression | UnaryExpression + ) { + kotlin_inspect_container(&value, &mut stats.conditions) + } + } + } + _ => {} + } + } +} + #[cfg(test)] mod tests { use crate::tools::check_metrics; From c6f497caadeb487becdad5f9982bf0b3d00a229f Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 5 May 2023 19:35:35 +0200 Subject: [PATCH 13/42] kotlin: Do not add a new variable to stats for npm --- src/metrics/npm.rs | 58 +++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index 8b168ff0a..c4c5cf656 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -24,7 +24,6 @@ pub struct Stats { class_nm_sum: usize, interface_nm_sum: usize, is_class_space: bool, - is_interface: bool, } impl Serialize for Stats { @@ -270,36 +269,41 @@ impl Npm for KotlinCode { stats.is_class_space = true; } - if node.kind_id() == ClassDeclaration { - for class_child in node.children() { - match class_child.kind_id().into() { - Interface => stats.is_interface = true, - ClassBody => { - for node in class_child.children() { - if node.kind_id() == FunctionDeclaration - && traverse_children( - &node, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() - { - if stats.is_interface { - stats.interface_nm += 1; - stats.interface_npm = stats.interface_nm; - } else { - stats.class_npm += 1; - stats.class_nm = stats.class_npm; - } - } + match node.kind_id().into() { + ClassBody => { + // Check if this node is an interfaces + let mut is_interface = false; + let mut node_sibling = *node; + while let Some(prev_sibling) = node_sibling.previous_sibling() { + if let Interface = prev_sibling.kind_id().into() { + is_interface = true; + break; + } + node_sibling = prev_sibling; + } + for child in node.children() { + if child.kind_id() == FunctionDeclaration + && traverse_children( + &child, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if is_interface { + stats.interface_nm += 1; + stats.interface_npm = stats.interface_nm; + } else { + stats.class_npm += 1; + stats.class_nm = stats.class_npm; } } - _ => (), } } + _ => (), } } } From 774f3d2870c4211b90ca8700ea15e690f052a44e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 5 May 2023 19:35:40 +0200 Subject: [PATCH 14/42] kotlin: Do not add a new variable to stats for npa --- src/metrics/npa.rs | 59 +++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index 2d8bc5f39..b01b8f5aa 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -24,7 +24,6 @@ pub struct Stats { class_na_sum: usize, interface_na_sum: usize, is_class_space: bool, - is_interface: bool, } impl Serialize for Stats { @@ -279,36 +278,42 @@ impl Npa for KotlinCode { stats.is_class_space = true; } - if let ClassDeclaration = node.kind_id().into() { - for class_child in node.children() { - match class_child.kind_id().into() { - Interface => stats.is_interface = true, - ClassBody => { - for node in class_child.children() { - if node.kind_id() == PropertyDeclaration - && traverse_children( - &node, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() - { - if stats.is_interface { - stats.interface_na += 1; - stats.interface_npa = stats.interface_na; - } else { - stats.class_npa += 1; - stats.class_na = stats.class_npa; - } - } + match node.kind_id().into() { + ClassBody => { + // Check if this node is an interfaces + let mut is_interface = false; + let mut node_sibling = *node; + while let Some(prev_sibling) = node_sibling.previous_sibling() { + if let Interface = prev_sibling.kind_id().into() { + is_interface = true; + break; + } + node_sibling = prev_sibling; + } + + for node in node.children() { + if node.kind_id() == PropertyDeclaration + && traverse_children( + &node, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if is_interface { + stats.interface_na += 1; + stats.interface_npa = stats.interface_na; + } else { + stats.class_npa += 1; + stats.class_na = stats.class_npa; } } - _ => (), } } + _ => (), } } } From 29b419a973f769768ea4239ea922396e5c4eddb6 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 5 May 2023 19:38:38 +0200 Subject: [PATCH 15/42] kotlin: Fix clippy warnings --- src/metrics/npa.rs | 59 ++++++++++++++++++++++------------------------ src/metrics/npm.rs | 59 ++++++++++++++++++++++------------------------ 2 files changed, 56 insertions(+), 62 deletions(-) diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index b01b8f5aa..92f1d38e6 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -278,42 +278,39 @@ impl Npa for KotlinCode { stats.is_class_space = true; } - match node.kind_id().into() { - ClassBody => { - // Check if this node is an interfaces - let mut is_interface = false; - let mut node_sibling = *node; - while let Some(prev_sibling) = node_sibling.previous_sibling() { - if let Interface = prev_sibling.kind_id().into() { - is_interface = true; - break; - } - node_sibling = prev_sibling; + if node.kind_id() == ClassBody { + // Check if this node is an interfaces + let mut is_interface = false; + let mut node_sibling = *node; + while let Some(prev_sibling) = node_sibling.previous_sibling() { + if let Interface = prev_sibling.kind_id().into() { + is_interface = true; + break; } + node_sibling = prev_sibling; + } - for node in node.children() { - if node.kind_id() == PropertyDeclaration - && traverse_children( - &node, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() - { - if is_interface { - stats.interface_na += 1; - stats.interface_npa = stats.interface_na; - } else { - stats.class_npa += 1; - stats.class_na = stats.class_npa; - } + for node in node.children() { + if node.kind_id() == PropertyDeclaration + && traverse_children( + &node, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if is_interface { + stats.interface_na += 1; + stats.interface_npa = stats.interface_na; + } else { + stats.class_npa += 1; + stats.class_na = stats.class_npa; } } } - _ => (), } } } diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index c4c5cf656..c639f01bc 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -269,41 +269,38 @@ impl Npm for KotlinCode { stats.is_class_space = true; } - match node.kind_id().into() { - ClassBody => { - // Check if this node is an interfaces - let mut is_interface = false; - let mut node_sibling = *node; - while let Some(prev_sibling) = node_sibling.previous_sibling() { - if let Interface = prev_sibling.kind_id().into() { - is_interface = true; - break; - } - node_sibling = prev_sibling; + if node.kind_id() == ClassBody { + // Check if this node is an interfaces + let mut is_interface = false; + let mut node_sibling = *node; + while let Some(prev_sibling) = node_sibling.previous_sibling() { + if let Interface = prev_sibling.kind_id().into() { + is_interface = true; + break; } - for child in node.children() { - if child.kind_id() == FunctionDeclaration - && traverse_children( - &child, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() - { - if is_interface { - stats.interface_nm += 1; - stats.interface_npm = stats.interface_nm; - } else { - stats.class_npm += 1; - stats.class_nm = stats.class_npm; - } + node_sibling = prev_sibling; + } + for child in node.children() { + if child.kind_id() == FunctionDeclaration + && traverse_children( + &child, + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() + { + if is_interface { + stats.interface_nm += 1; + stats.interface_npm = stats.interface_nm; + } else { + stats.class_npm += 1; + stats.class_nm = stats.class_npm; } } } - _ => (), } } } From 905d3c0e958ccc1969cc84403f37de5391fbb617 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 26 May 2023 10:04:39 +0200 Subject: [PATCH 16/42] Implement traverse children --- src/metrics/npa.rs | 19 +++++++++---------- src/metrics/npm.rs | 19 +++++++++---------- src/node.rs | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index 92f1d38e6..a5cb87ed0 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -2,7 +2,6 @@ use serde::Serialize; use serde::ser::{SerializeStruct, Serializer}; use std::fmt; -use crate::asttools::traverse_children; use crate::checker::Checker; use crate::langs::*; use crate::macros::implement_metric_trait; @@ -292,15 +291,15 @@ impl Npa for KotlinCode { for node in node.children() { if node.kind_id() == PropertyDeclaration - && traverse_children( - &node, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() + && node + .traverse_children( + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() { if is_interface { stats.interface_na += 1; diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index c639f01bc..9410456a7 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -2,7 +2,6 @@ use serde::Serialize; use serde::ser::{SerializeStruct, Serializer}; use std::fmt; -use crate::asttools::traverse_children; use crate::checker::Checker; use crate::langs::*; use crate::macros::implement_metric_trait; @@ -282,15 +281,15 @@ impl Npm for KotlinCode { } for child in node.children() { if child.kind_id() == FunctionDeclaration - && traverse_children( - &child, - &[ - |c| c == Modifiers, - |c| c == VisibilityModifier, - |c| c == Private || c == Protected, - ][..], - ) - .is_none() + && child + .traverse_children( + &[ + |c| c == Modifiers, + |c| c == VisibilityModifier, + |c| c == Private || c == Protected, + ][..], + ) + .is_none() { if is_interface { stats.interface_nm += 1; diff --git a/src/node.rs b/src/node.rs index 929ffe096..290d2ac5e 100644 --- a/src/node.rs +++ b/src/node.rs @@ -184,6 +184,26 @@ impl<'a> Node<'a> { } res } + + // Traverse a tree passing from children to children in search of a specific + // token or series of tokens + pub(crate) fn traverse_children(&self, token_list: &[F]) -> Option> + where + F: FnOnce(u16) -> bool + Copy, + { + let mut node = *self; + 'outer: for token in token_list { + for temp_node in node.children() { + if token(temp_node.kind_id()) { + node = temp_node; + continue 'outer; + } + } + // If a token has not been found, return None + return None; + } + Some(node) + } } /// An `AST` cursor. From 7c637c16ebb0d3d99f4349e222f6291022f8a4de Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 26 May 2023 10:15:01 +0200 Subject: [PATCH 17/42] Fix checker and getter --- src/checker.rs | 16 ++++++++-------- src/getter.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index 2e0fef2a7..62ed20e23 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -664,7 +664,7 @@ impl Checker for RustCode { impl Checker for KotlinCode { fn is_comment(node: &Node) -> bool { - node.object().kind_id() == Kotlin::Comment + node.kind_id() == Kotlin::Comment } fn is_useful_comment(_: &Node, _: &[u8]) -> bool { @@ -673,13 +673,13 @@ impl Checker for KotlinCode { fn is_func_space(node: &Node) -> bool { matches!( - node.object().kind_id().into(), + node.kind_id().into(), Kotlin::SourceFile | Kotlin::FunctionDeclaration | Kotlin::LambdaLiteral ) } fn is_func(node: &Node) -> bool { - node.object().kind_id() == Kotlin::FunctionDeclaration + node.kind_id() == Kotlin::FunctionDeclaration } fn is_closure(_: &Node) -> bool { @@ -687,12 +687,12 @@ impl Checker for KotlinCode { } fn is_call(node: &Node) -> bool { - node.object().kind_id() == Kotlin::CallExpression + node.kind_id() == Kotlin::CallExpression } fn is_non_arg(node: &Node) -> bool { matches!( - node.object().kind_id().into(), + node.kind_id().into(), Kotlin::LPAREN | Kotlin::COMMA | Kotlin::RPAREN @@ -703,16 +703,16 @@ impl Checker for KotlinCode { fn is_string(node: &Node) -> bool { matches!( - node.object().kind_id().into(), + node.kind_id().into(), Kotlin::StringLiteral | Kotlin::LineStringLiteral | Kotlin::MultiLineStringLiteral ) } fn is_else_if(node: &Node) -> bool { - if node.object().kind_id() != Kotlin::IfExpression { + if node.kind_id() != Kotlin::IfExpression { return false; } - if let Some(parent) = node.object().parent() { + if let Some(parent) = node.parent() { return parent.kind_id() == Kotlin::Else; } diff --git a/src/getter.rs b/src/getter.rs index 7311d75e8..36d3d0d0e 100644 --- a/src/getter.rs +++ b/src/getter.rs @@ -580,7 +580,7 @@ impl Getter for KotlinCode { fn get_space_kind(node: &Node) -> SpaceKind { use Kotlin::*; - let typ = node.object().kind_id().into(); + let typ = node.kind_id().into(); match typ { ClassDeclaration => SpaceKind::Class, FunctionDeclaration | Constructor | AnnotatedLambda => SpaceKind::Function, @@ -592,7 +592,7 @@ impl Getter for KotlinCode { fn get_op_type(node: &Node) -> HalsteadType { use Kotlin::*; - let typ = node.object().kind_id(); + let typ = node.kind_id(); match typ.into() { // Operator: function calls From 803532da35103d5f74e6c4aa65abc23d96743742 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 26 May 2023 11:09:12 +0200 Subject: [PATCH 18/42] Fix wmc --- src/checker.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index 62ed20e23..e18a70c75 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -674,7 +674,7 @@ impl Checker for KotlinCode { fn is_func_space(node: &Node) -> bool { matches!( node.kind_id().into(), - Kotlin::SourceFile | Kotlin::FunctionDeclaration | Kotlin::LambdaLiteral + Kotlin::SourceFile | Kotlin::ClassDeclaration ) } @@ -682,8 +682,8 @@ impl Checker for KotlinCode { node.kind_id() == Kotlin::FunctionDeclaration } - fn is_closure(_: &Node) -> bool { - false + fn is_closure(node: &Node) -> bool { + node.kind_id() == Kotlin::LambdaLiteral } fn is_call(node: &Node) -> bool { From eb4afcd3bac2af44712496a5ca45ca172defe1e5 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 26 May 2023 11:22:54 +0200 Subject: [PATCH 19/42] Fix nargs --- src/metrics/nargs.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/metrics/nargs.rs b/src/metrics/nargs.rs index 9df9a66af..9c64545a5 100644 --- a/src/metrics/nargs.rs +++ b/src/metrics/nargs.rs @@ -193,6 +193,15 @@ fn compute_args(node: &Node, nargs: &mut usize) { } } +#[inline(always)] +fn compute_kotlin_args(node: &Node, nargs: &mut usize) { + node.act_on_child(&mut |n| { + if n.kind_id() == Kotlin::Parameter { + *nargs += 1; + } + }); +} + pub trait NArgs where Self: Checker, @@ -229,6 +238,18 @@ impl NArgs for CppCode { } } +impl NArgs for KotlinCode { + fn compute(node: &Node, stats: &mut Stats) { + if Self::is_func(node) { + compute_kotlin_args(node, &mut stats.fn_nargs); + } + + if Self::is_closure(node) { + compute_kotlin_args(node, &mut stats.closure_nargs); + } + } +} + implement_metric_trait!( [NArgs], PythonCode, @@ -239,8 +260,7 @@ implement_metric_trait!( RustCode, PreprocCode, CcommentCode, - JavaCode, - KotlinCode + JavaCode ); #[cfg(test)] From 51465b6aa16135d4fca1e5de85e15f8ed3aa75fc Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 26 May 2023 11:41:40 +0200 Subject: [PATCH 20/42] Fix halstead --- src/getter.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/getter.rs b/src/getter.rs index 36d3d0d0e..a194120de 100644 --- a/src/getter.rs +++ b/src/getter.rs @@ -607,10 +607,13 @@ impl Getter for KotlinCode { | EQ | LT | GT | BANG | QMARKCOLON | AsQMARK | COLON // no grammar for lambda operator -> | EQEQ | LTEQ | GTEQ | BANGEQ | AMPAMP | PIPEPIPE | PLUSPLUS | DASHDASH | PLUS | DASH | STAR | SLASH | PERCENT - | PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ + | PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ => { + HalsteadType::Operator + } // Operands: variables, constants, literals - | RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1 - | LiteralConstant | StringLiteral | LineStringLiteral | MultiLineStringLiteral | LambdaLiteral | FunctionLiteral => { + RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1 + | LiteralConstant | StringLiteral | LineStringLiteral | MultiLineStringLiteral | LambdaLiteral | FunctionLiteral + | ObjectLiteral | UnsignedLiteral | LongLiteral | BooleanLiteral | CharacterLiteral => { HalsteadType::Operand }, _ => { From 19194d445e27519354884c66e0fdff8405cd2b3e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Thu, 15 Jun 2023 16:50:24 +0200 Subject: [PATCH 21/42] kotlin: add cognitive metric --- src/metrics/cognitive.rs | 46 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index a7b09fea3..215bbc78d 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -490,7 +490,45 @@ impl Cognitive for JavaCode { } } -implement_metric_trait!(Cognitive, PreprocCode, CcommentCode, KotlinCode); +impl Cognitive for KotlinCode { + fn compute( + node: &Node, + stats: &mut Stats, + nesting_map: &mut FxHashMap, + ) { + use Kotlin::*; + + //TODO: Implement macros + let (mut nesting, depth, mut lambda) = get_nesting_from_map(node, nesting_map); + + match node.kind_id().into() { + IfExpression => { + if !Self::is_else_if(node) { + increase_nesting(stats,&mut nesting, depth, lambda); + } + } + ForStatement | WhileStatement | DoWhileStatement | WhenExpression | CatchBlock => { + increase_nesting(stats, &mut nesting, depth, lambda); + } + Else /* else-if also */ => { + increment_by_one(stats); + } + UnaryExpression => { + stats.boolean_seq.not_operator(node.kind_id()); + } + BinaryExpression => { + compute_booleans::(node, stats, AMPAMP, PIPEPIPE); + } + LambdaLiteral => { + lambda += 1; + } + _ => {} + } + nesting_map.insert(node.id(), (nesting, depth, lambda)); + } +} + +implement_metric_trait!(Cognitive, PreprocCode, CcommentCode); #[cfg(test)] mod tests { @@ -1756,7 +1794,7 @@ mod tests { fn java_single_branch_function() { check_metrics::( "class X { - public static void print(boolean a){ + public static void print(boolean a){ if(a){ // +1 System.out.println(\"test1\"); } @@ -1783,7 +1821,7 @@ mod tests { fn java_multiple_branch_function() { check_metrics::( "class X { - public static void print(boolean a, boolean b){ + public static void print(boolean a, boolean b){ if(a){ // +1 System.out.println(\"test1\"); } @@ -1816,7 +1854,7 @@ mod tests { fn java_compound_conditions() { check_metrics::( "class X { - public static void print(boolean a, boolean b, boolean c, boolean d){ + public static void print(boolean a, boolean b, boolean c, boolean d){ if(a && b){ // +2 (+1 &&) System.out.println(\"test1\"); } From 48349c19dc94e37191bf781569ce350080fb9750 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:02:23 +0000 Subject: [PATCH 22/42] build(deps): update tree-sitter-javascript requirement Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases) - [Commits](https://github.com/tree-sitter/tree-sitter-javascript/compare/v0.23.1...v0.25.0) --- updated-dependencies: - dependency-name: tree-sitter-javascript dependency-version: 0.25.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7a5c1bda0..31f908a8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ 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-javascript = "=0.25.0" tree-sitter-python = "=0.23.6" tree-sitter-rust = "=0.23.2" tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" } From b8ce5ddafec6e7886b9a341086138003da920e53 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:47:24 +0000 Subject: [PATCH 23/42] build(deps): update tree-sitter-javascript requirement in /enums Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases) - [Commits](https://github.com/tree-sitter/tree-sitter-javascript/compare/v0.23.1...v0.25.0) --- updated-dependencies: - dependency-name: tree-sitter-javascript dependency-version: 0.25.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- enums/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enums/Cargo.toml b/enums/Cargo.toml index d2dcc438e..078d47123 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -12,7 +12,7 @@ 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-javascript = "=0.25.0" tree-sitter-python = "=0.23.6" tree-sitter-rust = "=0.23.2" tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.3" } From 8e98c277d38822c9e4a417946af5da85505c8768 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 21:44:52 +0000 Subject: [PATCH 24/42] build(deps): update tree-sitter-javascript requirement Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases) - [Commits](https://github.com/tree-sitter/tree-sitter-javascript/compare/v0.23.1...v0.25.0) --- updated-dependencies: - dependency-name: tree-sitter-javascript dependency-version: 0.25.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- tree-sitter-mozjs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-sitter-mozjs/Cargo.toml b/tree-sitter-mozjs/Cargo.toml index b1f3915fe..92b8db84a 100644 --- a/tree-sitter-mozjs/Cargo.toml +++ b/tree-sitter-mozjs/Cargo.toml @@ -27,7 +27,7 @@ tree-sitter-language="0.1.0" cc = "^1.0" # This dependency is not used at all for this crate, but it is here so that # dependabot can send notifications when there are updates for this grammar -tree-sitter-javascript = "0.23.1" +tree-sitter-javascript = "0.25.0" [package.metadata.cargo-udeps.ignore] build = ["tree-sitter-javascript"] From e4f456a9eb0902e78cff2cddf04413e7e361864e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 22:06:21 +0000 Subject: [PATCH 25/42] build(deps): update tree-sitter-python requirement in /enums Updates the requirements on [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter-python/releases) - [Commits](https://github.com/tree-sitter/tree-sitter-python/compare/v0.23.6...v0.25.0) --- updated-dependencies: - dependency-name: tree-sitter-python dependency-version: 0.25.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- enums/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enums/Cargo.toml b/enums/Cargo.toml index d2dcc438e..6ad87e06e 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -13,7 +13,7 @@ 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-python = "=0.25.0" 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" } From 6f5ea2327dc334276c6e8250679671e7ab2d23f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 22:06:25 +0000 Subject: [PATCH 26/42] build(deps): update tree-sitter-python requirement Updates the requirements on [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter-python/releases) - [Commits](https://github.com/tree-sitter/tree-sitter-python/compare/v0.23.6...v0.25.0) --- updated-dependencies: - dependency-name: tree-sitter-python dependency-version: 0.25.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7a5c1bda0..60a6c000f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ 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-python = "=0.25.0" 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" } From 395277eb93972962133d42d57d742525666ea30f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 22:05:33 +0000 Subject: [PATCH 27/42] build(deps): update tree-sitter requirement in /tree-sitter-mozjs Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter/releases) - [Commits](https://github.com/tree-sitter/tree-sitter/compare/v0.25.3...v0.26.3) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.26.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- tree-sitter-mozjs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-sitter-mozjs/Cargo.toml b/tree-sitter-mozjs/Cargo.toml index b1f3915fe..2dfc0488e 100644 --- a/tree-sitter-mozjs/Cargo.toml +++ b/tree-sitter-mozjs/Cargo.toml @@ -33,4 +33,4 @@ tree-sitter-javascript = "0.23.1" build = ["tree-sitter-javascript"] [dev-dependencies] -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" From 189452b10b68aa26511501b7ab078cde5117439a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 22:05:37 +0000 Subject: [PATCH 28/42] build(deps): update tree-sitter requirement in /tree-sitter-mozcpp Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter/releases) - [Commits](https://github.com/tree-sitter/tree-sitter/compare/v0.25.3...v0.26.3) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.26.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- tree-sitter-mozcpp/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-sitter-mozcpp/Cargo.toml b/tree-sitter-mozcpp/Cargo.toml index 7924acb47..fcf869477 100644 --- a/tree-sitter-mozcpp/Cargo.toml +++ b/tree-sitter-mozcpp/Cargo.toml @@ -33,4 +33,4 @@ tree-sitter-cpp = "0.23.4" build = ["tree-sitter-cpp"] [dev-dependencies] -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" From 3d41672435e51414856473957f027624000f0d29 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 22:05:39 +0000 Subject: [PATCH 29/42] build(deps): update tree-sitter requirement in /tree-sitter-preproc Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter/releases) - [Commits](https://github.com/tree-sitter/tree-sitter/compare/v0.25.3...v0.26.3) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.26.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- tree-sitter-preproc/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-sitter-preproc/Cargo.toml b/tree-sitter-preproc/Cargo.toml index 85a564fce..b54d0bb5e 100644 --- a/tree-sitter-preproc/Cargo.toml +++ b/tree-sitter-preproc/Cargo.toml @@ -27,4 +27,4 @@ tree-sitter-language="0.1.0" cc = "^1.0" [dev-dependencies] -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" From a4ee8879e37af652e06825c01bb0c044ee3225a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 22:05:40 +0000 Subject: [PATCH 30/42] build(deps): update tree-sitter requirement in /enums Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter/releases) - [Commits](https://github.com/tree-sitter/tree-sitter/compare/v0.25.3...v0.26.3) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.26.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- enums/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enums/Cargo.toml b/enums/Cargo.toml index d2dcc438e..9235bf67f 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -8,7 +8,7 @@ edition = "2024" clap = { version = "^4.0", features = ["derive"] } askama = "^0.14" -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" tree-sitter-java = "=0.23.5" tree-sitter-kotlin-ng = "1.1.0" tree-sitter-typescript = "=0.23.2" From fc5e9106273b18e91d375f881a57dc6e7754234d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 22:05:48 +0000 Subject: [PATCH 31/42] build(deps): update tree-sitter requirement in /tree-sitter-ccomment Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version. - [Release notes](https://github.com/tree-sitter/tree-sitter/releases) - [Commits](https://github.com/tree-sitter/tree-sitter/compare/v0.25.3...v0.26.3) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.26.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- tree-sitter-ccomment/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-sitter-ccomment/Cargo.toml b/tree-sitter-ccomment/Cargo.toml index d9df06f4e..28f69823c 100644 --- a/tree-sitter-ccomment/Cargo.toml +++ b/tree-sitter-ccomment/Cargo.toml @@ -27,4 +27,4 @@ tree-sitter-language="0.1.0" cc = "^1.0" [dev-dependencies] -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" From 1c3cb86edc3b0e157f0112ca1041daba617dec6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:04:55 +0000 Subject: [PATCH 32/42] build(deps): update askama requirement from ^0.14 to ^0.15 in /enums Updates the requirements on [askama](https://github.com/askama-rs/askama) to permit the latest version. - [Release notes](https://github.com/askama-rs/askama/releases) - [Commits](https://github.com/askama-rs/askama/compare/v0.14.0...v0.15.0) --- updated-dependencies: - dependency-name: askama dependency-version: 0.15.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- enums/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enums/Cargo.toml b/enums/Cargo.toml index d2dcc438e..57751d516 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" [dependencies] clap = { version = "^4.0", features = ["derive"] } -askama = "^0.14" +askama = "^0.15" tree-sitter = "=0.25.3" tree-sitter-java = "=0.23.5" From d683273c6f0f1bf2a9f102a0df1c07ad37c17235 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 13:22:15 -0300 Subject: [PATCH 33/42] Switch to tree-sitter-kotlin-codanna for tree-sitter 0.26.3 compatibility - Replace tree-sitter-kotlin-ng with tree-sitter-kotlin-codanna (0.3.9) - tree-sitter-kotlin-codanna is compatible with tree-sitter 0.26.3 - Update Kotlin node type mappings: - Comment -> LineComment | MultilineComment - LineStringLiteral/MultiLineStringLiteral -> StringLiteral | StringContent - Fix tree-sitter 0.26 API changes: - Node.child() now takes u32 instead of usize - Add special case for kotlin grammar's language() function (vs LANGUAGE constant) - Fix FxHashMap -> HashMap import - Add Makefile for build commands All 251 tests passing + 17 doc tests. --- Cargo.toml | 4 +- Makefile | 19 + enums/Cargo.toml | 2 +- enums/src/languages.rs | 2 +- enums/src/macros.rs | 2 +- src/checker.rs | 9 +- src/getter.rs | 5 +- src/langs.rs | 2 +- src/languages/language_kotlin.rs | 1066 +++++++++++++++++------------- src/macros.rs | 3 + src/metrics/cognitive.rs | 2 +- src/metrics/loc.rs | 7 +- src/node.rs | 6 +- src/parser.rs | 2 +- src/tools.rs | 2 +- src/traits.rs | 2 +- 16 files changed, 651 insertions(+), 484 deletions(-) create mode 100644 Makefile diff --git a/Cargo.toml b/Cargo.toml index 7a5c1bda0..7ec57e2bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ serde = { version = "^1.0", features = ["derive"] } termcolor = "^1.2" walkdir = "^2.3" -tree-sitter = "=0.25.3" +tree-sitter = "=0.26.3" tree-sitter-java = "=0.23.5" -tree-sitter-kotlin-ng = "1.1.0" +tree-sitter-kotlin-codanna = "0.3.9" tree-sitter-typescript = "=0.23.2" tree-sitter-javascript = "=0.23.1" tree-sitter-python = "=0.23.6" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..5242a7235 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: build test check clean fmt + +build: + cargo build + +build-release: + cargo build --release + +test: + cargo test + +check: + cargo check + +clean: + cargo clean + +fmt: + cargo fmt diff --git a/enums/Cargo.toml b/enums/Cargo.toml index 9235bf67f..4fa572844 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -10,7 +10,7 @@ askama = "^0.14" tree-sitter = "=0.26.3" tree-sitter-java = "=0.23.5" -tree-sitter-kotlin-ng = "1.1.0" +tree-sitter-kotlin-codanna = "0.3.9" tree-sitter-typescript = "=0.23.2" tree-sitter-javascript = "=0.23.1" tree-sitter-python = "=0.23.6" diff --git a/enums/src/languages.rs b/enums/src/languages.rs index f7d490495..90c18fd6d 100644 --- a/enums/src/languages.rs +++ b/enums/src/languages.rs @@ -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_ng), + (Kotlin, tree_sitter_kotlin_codanna), (Java, tree_sitter_java), (Rust, tree_sitter_rust), (Cpp, tree_sitter_cpp), diff --git a/enums/src/macros.rs b/enums/src/macros.rs index 3b7c79191..1626dfb03 100644 --- a/enums/src/macros.rs +++ b/enums/src/macros.rs @@ -19,7 +19,7 @@ macro_rules! mk_get_language { ( $( ($camel:ident, $name:ident) ),* ) => { pub fn get_language(lang: &Lang) -> Language { match lang { - Lang::Kotlin => tree_sitter_kotlin_ng::LANGUAGE.into(), + Lang::Kotlin => tree_sitter_kotlin_codanna::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(), diff --git a/src/checker.rs b/src/checker.rs index e18a70c75..40c6b528d 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -664,7 +664,7 @@ impl Checker for RustCode { impl Checker for KotlinCode { fn is_comment(node: &Node) -> bool { - node.kind_id() == Kotlin::Comment + matches!(node.kind_id().into(), Kotlin::LineComment | Kotlin::MultilineComment) } fn is_useful_comment(_: &Node, _: &[u8]) -> bool { @@ -702,10 +702,9 @@ impl Checker for KotlinCode { } fn is_string(node: &Node) -> bool { - matches!( - node.kind_id().into(), - Kotlin::StringLiteral | Kotlin::LineStringLiteral | Kotlin::MultiLineStringLiteral - ) + // StringLiteral covers both single-line and multi-line strings in this grammar + // StringContent captures the text content within strings + matches!(node.kind_id().into(), Kotlin::StringLiteral | Kotlin::StringContent) } fn is_else_if(node: &Node) -> bool { diff --git a/src/getter.rs b/src/getter.rs index a194120de..89ad66e2c 100644 --- a/src/getter.rs +++ b/src/getter.rs @@ -611,8 +611,9 @@ impl Getter for KotlinCode { HalsteadType::Operator } // Operands: variables, constants, literals - RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1 - | LiteralConstant | StringLiteral | LineStringLiteral | MultiLineStringLiteral | LambdaLiteral | FunctionLiteral + // StringLiteral covers both line strings and multi-line strings in this grammar + RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1 + | LiteralConstant | StringLiteral | StringContent | LambdaLiteral | FunctionLiteral | ObjectLiteral | UnsignedLiteral | LongLiteral | BooleanLiteral | CharacterLiteral => { HalsteadType::Operand }, diff --git a/src/langs.rs b/src/langs.rs index 9ee9e1a8a..cbf46d527 100644 --- a/src/langs.rs +++ b/src/langs.rs @@ -53,7 +53,7 @@ mk_langs!( "kotlin", KotlinCode, KotlinParser, - tree_sitter_kotlin_ng, + tree_sitter_kotlin_codanna, [kt, kts], ["kotlin"] ), diff --git a/src/languages/language_kotlin.rs b/src/languages/language_kotlin.rs index b4eaf5670..9e01c2932 100644 --- a/src/languages/language_kotlin.rs +++ b/src/languages/language_kotlin.rs @@ -5,295 +5,366 @@ use num_derive::FromPrimitive; #[derive(Clone, Debug, PartialEq, Eq, FromPrimitive)] pub enum Kotlin { End = 0, - Identifier = 1, - AT = 2, - File = 3, - COLON = 4, - LBRACK = 5, - RBRACK = 6, - Package = 7, - SEMI = 8, - Import2 = 9, - DOT = 10, - STAR = 11, - As = 12, - Class = 13, - Fun = 14, - Interface = 15, - Object = 16, - Val = 17, - Var = 18, - EQ = 19, - Typealias = 20, - Companion = 21, - Init = 22, - Constructor = 23, - This = 24, - Super = 25, - LT = 26, - COMMA = 27, - GT = 28, - LPAREN = 29, - RPAREN = 30, + AlphaIdentifier = 1, + HASHBANG = 2, + ShebangLineToken1 = 3, + AT = 4, + File = 5, + COLON = 6, + LBRACK = 7, + RBRACK = 8, + Package = 9, + Import = 10, + DOT = 11, + WildcardImport = 12, + As = 13, + Typealias = 14, + EQ = 15, + Class = 16, + Fun = 17, + Interface = 18, + Enum = 19, + Constructor = 20, + LBRACE = 21, + RBRACE = 22, + LPAREN = 23, + COMMA = 24, + RPAREN = 25, + Val = 26, + Var = 27, + By = 28, + LT = 29, + GT = 30, Where = 31, - By = 32, - Get = 33, - Set = 34, - LBRACE = 35, - RBRACE = 36, - For = 37, - In = 38, - While = 39, - Do = 40, - Enum = 41, - Sealed = 42, - Annotation2 = 43, - Data = 44, - Inner = 45, - Value = 46, - Tailrec = 47, - Operator = 48, - Infix = 49, - Inline = 50, - External = 51, - Suspend = 52, - Const = 53, - Public = 54, - Private = 55, - Protected = 56, - Internal = 57, - Abstract = 58, - Final = 59, - Open = 60, - Override = 61, - Lateinit = 62, - Vararg = 63, - Noinline = 64, - Crossinline = 65, - ReificationModifier = 66, - Expect = 67, - Actual = 68, - Field = 69, - Property = 70, - Receiver = 71, - Param = 72, - Setparam = 73, - Delegate = 74, - Dynamic = 75, - QMARK = 76, - AMP = 77, - DASHGT = 78, - PLUSEQ = 79, - DASHEQ = 80, - STAREQ = 81, - SLASHEQ = 82, - PERCENTEQ = 83, - PLUSPLUS = 84, - DASHDASH = 85, - PLUS = 86, - DASH = 87, + Init = 32, + Companion = 33, + Object = 34, + SEMI = 35, + Get = 36, + Set = 37, + This = 38, + Super = 39, + Dynamic = 40, + AMP = 41, + Quest = 42, + STAR = 43, + DASHGT = 44, + Label = 45, + For = 46, + In = 47, + While = 48, + Do = 49, + DOTDOT = 50, + QMARKCOLON = 51, + AMPAMP = 52, + PIPEPIPE = 53, + DOLLARLBRACE = 54, + DOLLAR = 55, + If = 56, + Else = 57, + When = 58, + Try = 59, + Catch = 60, + Finally = 61, + Throw = 62, + Return = 63, + Continue = 64, + Break = 65, + COLONCOLON = 66, + PLUSEQ = 67, + DASHEQ = 68, + STAREQ = 69, + SLASHEQ = 70, + PERCENTEQ = 71, + BANGEQ = 72, + BANGEQEQ = 73, + EQEQ = 74, + EQEQEQ = 75, + LTEQ = 76, + GTEQ = 77, + BANGin = 78, + Is = 79, + BANGis = 80, + PLUS = 81, + DASH = 82, + SLASH = 83, + PERCENT = 84, + AsQMARK = 85, + PLUSPLUS = 86, + DASHDASH = 87, BANG = 88, BANGBANG = 89, - SLASH = 90, - PERCENT = 91, - PIPEPIPE = 92, - AMPAMP = 93, - BANGEQ = 94, - BANGEQEQ = 95, - EQEQ = 96, - EQEQEQ = 97, - GTEQ = 98, - LTEQ = 99, - QMARKCOLON = 100, - BANGin = 101, - Is = 102, - AsQMARK = 103, - DOTDOT = 104, - DOTDOTLT = 105, - ThisAT = 106, - SuperAT = 107, - AT2 = 108, - If = 109, - Else = 110, - When = 111, - Try = 112, - Catch = 113, - Finally = 114, - Return = 115, - ReturnAT = 116, - Throw = 117, - COLONCOLON = 118, - DQUOTE = 119, - StringContent = 120, - StringContent2 = 121, - DOLLAR = 122, - DQUOTEDQUOTEDQUOTE = 123, - DQUOTEDQUOTEDQUOTEDQUOTE = 124, - DOLLARLBRACE = 125, - SQUOTE = 126, - CharacterLiteralToken1 = 127, - EscapeSequence = 128, - NumberLiteral = 129, - FloatLiteral = 130, - Out = 131, - Label = 132, - Shebang = 133, - LineComment = 134, - Semi = 135, - ClassMemberSemi = 136, - BlockComment = 137, - BANGis = 138, - In2 = 139, - QMARKDOT = 140, - StringContent3 = 141, - SourceFile = 142, - FileAnnotation = 143, - PackageHeader = 144, - Import = 145, - Declaration = 146, - ClassDeclaration = 147, - ObjectDeclaration = 148, - PropertyDeclaration = 149, - TypeAlias = 150, - CompanionObject = 151, - AnonymousInitializer = 152, - SecondaryConstructor = 153, - ConstructorDelegationCall = 154, - TypeParameters = 155, - TypeParameter = 156, - PrimaryConstructor = 157, - ClassParameters = 158, - ClassParameter = 159, - TypeConstraints = 160, - TypeConstraint = 161, - ConstructorInvocation = 162, - FunctionDeclaration = 163, - FunctionValueParameters = 164, - Parameter = 165, - DelegationSpecifiers = 166, - DelegationSpecifier = 167, - VariableDeclaration = 168, - MultiVariableDeclaration = 169, - PropertyDelegate = 170, + Suspend = 90, + Sealed = 91, + Annotation2 = 92, + Data = 93, + Inner = 94, + Value = 95, + Override = 96, + Lateinit = 97, + Public = 98, + Private = 99, + Internal = 100, + Protected = 101, + Out = 102, + Tailrec = 103, + Operator = 104, + Infix = 105, + Inline = 106, + External = 107, + PropertyModifier = 108, + Abstract = 109, + Final = 110, + Open = 111, + Vararg = 112, + Noinline = 113, + Crossinline = 114, + ReificationModifier = 115, + Expect = 116, + Actual = 117, + Field = 118, + Property = 119, + Receiver = 120, + Param = 121, + Setparam = 122, + Delegate = 123, + LineComment = 124, + ReturnAT = 125, + ContinueAT = 126, + BreakAT = 127, + ThisAT = 128, + SuperAT = 129, + AT2 = 130, + RealLiteral = 131, + IntegerLiteral = 132, + HexLiteral = 133, + BinLiteral = 134, + UnsignedLiteralToken1 = 135, + L = 136, + True = 137, + False = 138, + SQUOTE = 139, + CharacterLiteralToken1 = 140, + NullLiteral = 141, + BacktickIdentifier = 142, + BSLASHu = 143, + UniCharacterLiteralToken1 = 144, + EscapedIdentifier = 145, + AutomaticSemicolon = 146, + ImportListDelimiter = 147, + QMARKDOT = 148, + MultilineComment = 149, + StringStart = 150, + StringEnd = 151, + StringContent = 152, + SourceFile = 153, + ShebangLine = 154, + FileAnnotation = 155, + PackageHeader = 156, + ImportList = 157, + ImportHeader = 158, + ImportAlias = 159, + TypeAlias = 160, + Declaration = 161, + ClassDeclaration = 162, + PrimaryConstructor = 163, + ClassBody = 164, + ClassParameters = 165, + BindingPatternKind = 166, + ClassParameter = 167, + DelegationSpecifiers = 168, + DelegationSpecifier = 169, + ConstructorInvocation = 170, ExplicitDelegation = 171, - Getter = 172, - Setter = 173, - FunctionBody = 174, - Block = 175, - ForStatement = 176, - WhileStatement = 177, - DoWhileStatement = 178, - ClassBody = 179, - ClassMemberDeclaration = 180, - EnumClassBody = 181, - EnumEntry = 182, - ValueArguments = 183, - ValueArgument = 184, - Statement = 185, - Modifiers = 186, - ClassModifier = 187, - FunctionModifier = 188, - PropertyModifier = 189, - VisibilityModifier = 190, - InheritanceModifier = 191, - MemberModifier = 192, - ParameterModifiers = 193, - ParameterModifier = 194, - PlatformModifier = 195, - TypeModifiers = 196, - Annotation = 197, - UseSiteTarget = 198, - UnescapedAnnotation = 199, - Type = 200, - UserType = 201, - SimpleUserType = 202, - NullableType = 203, - NonNullableType = 204, - ReceiverType = 205, - TypeArguments = 206, - TypeProjection = 207, - FunctionType = 208, - FunctionTypeParameters = 209, - ParenthesizedType = 210, - Assignment = 211, - Expression = 212, - PrimaryExpression = 213, - UnaryExpression = 214, - AnnotatedExpression = 215, - LabeledExpression = 216, - BinaryExpression = 217, - InExpression = 218, - IsExpression = 219, - AsExpression = 220, - SpreadExpression = 221, - RangeExpression = 222, - InfixExpression = 223, + TypeParameters = 172, + TypeParameter = 173, + TypeConstraints = 174, + TypeConstraint = 175, + ClassMemberDeclarations = 176, + ClassMemberDeclaration = 177, + AnonymousInitializer = 178, + CompanionObject = 179, + FunctionValueParameters = 180, + FunctionValueParameter = 181, + ReceiverType = 182, + FunctionDeclaration = 183, + FunctionBody = 184, + VariableDeclaration = 185, + PropertyDeclaration = 186, + PropertyDelegate = 187, + Getter = 188, + Setter = 189, + ParameterWithOptionalType = 190, + Parameter = 191, + ObjectDeclaration = 192, + SecondaryConstructor = 193, + ConstructorDelegationCall = 194, + EnumClassBody = 195, + EnumEntries = 196, + EnumEntry = 197, + Type = 198, + TypeReference = 199, + NotNullableType = 200, + NullableType = 201, + UserType = 202, + SimpleUserType = 203, + TypeProjection = 204, + TypeProjectionModifiers = 205, + TypeProjectionModifier = 206, + FunctionType = 207, + FunctionTypeParameters = 208, + ParenthesizedType = 209, + ParenthesizedUserType = 210, + Statements = 211, + Statement = 212, + ControlStructureBody = 213, + Block = 214, + LoopStatement = 215, + ForStatement = 216, + WhileStatement = 217, + DoWhileStatement = 218, + Semi = 219, + Assignment = 220, + Expression = 221, + UnaryExpression = 222, + PostfixExpression = 223, CallExpression = 224, - AnnotatedLambda = 225, - LambdaLiteral = 226, - LambdaParameters = 227, - LambdaParameter = 228, - AnonymousFunction = 229, - IndexExpression = 230, - ThisExpression = 231, - SuperExpression = 232, - IfExpression = 233, - ParenthesizedExpression = 234, - CollectionLiteral = 235, - WhenExpression = 236, - WhenSubject = 237, - WhenEntry = 238, - WhenCondition = 239, - RangeTest = 240, - TypeTest = 241, - TryExpression = 242, - CatchBlock = 243, - FinallyBlock = 244, - ReturnExpression = 245, - ThrowExpression = 246, - CallableReference = 247, - NavigationExpression = 248, - ObjectLiteral = 249, - StringLiteral = 250, - MultilineStringLiteral = 251, - Interpolation = 252, - CharacterLiteral = 253, - VarianceModifier = 254, - TypeParameterModifiers = 255, - QualifiedIdentifier = 256, - ReservedIdentifier = 257, - SourceFileRepeat1 = 258, - SourceFileRepeat2 = 259, - SourceFileRepeat3 = 260, - FileAnnotationRepeat1 = 261, - TypeParametersRepeat1 = 262, - ClassParametersRepeat1 = 263, - TypeConstraintsRepeat1 = 264, - FunctionValueParametersRepeat1 = 265, - DelegationSpecifiersRepeat1 = 266, - DelegationSpecifierRepeat1 = 267, - MultiVariableDeclarationRepeat1 = 268, - ClassBodyRepeat1 = 269, - EnumClassBodyRepeat1 = 270, - ValueArgumentsRepeat1 = 271, - StatementsRepeat1 = 272, - ModifiersRepeat1 = 273, - ParameterModifiersRepeat1 = 274, - TypeModifiersRepeat1 = 275, - UserTypeRepeat1 = 276, - TypeArgumentsRepeat1 = 277, - TypeProjectionRepeat1 = 278, - FunctionTypeParametersRepeat1 = 279, - LambdaParametersRepeat1 = 280, - IndexExpressionRepeat1 = 281, - WhenExpressionRepeat1 = 282, - WhenEntryRepeat1 = 283, - TryExpressionRepeat1 = 284, - StringLiteralRepeat1 = 285, - MultilineStringLiteralRepeat1 = 286, - TypeParameterModifiersRepeat1 = 287, - QualifiedIdentifierRepeat1 = 288, - Error = 289, + IndexingExpression = 225, + NavigationExpression = 226, + PrefixExpression = 227, + AsExpression = 228, + SpreadExpression = 229, + BinaryExpression = 230, + MultiplicativeExpression = 231, + AdditiveExpression = 232, + RangeExpression = 233, + InfixExpression = 234, + ElvisExpression = 235, + CheckExpression = 236, + ComparisonExpression = 237, + EqualityExpression = 238, + ConjunctionExpression = 239, + DisjunctionExpression = 240, + IndexingSuffix = 241, + NavigationSuffix = 242, + CallSuffix = 243, + AnnotatedLambda = 244, + TypeArguments = 245, + ValueArguments = 246, + ValueArgument = 247, + PrimaryExpression = 248, + ParenthesizedExpression = 249, + CollectionLiteral = 250, + LiteralConstant = 251, + StringLiteral = 252, + Interpolation = 253, + LambdaLiteral = 254, + MultiVariableDeclaration = 255, + LambdaParameters = 256, + LambdaParameter = 257, + AnonymousFunction = 258, + FunctionLiteral = 259, + ObjectLiteral = 260, + ThisExpression = 261, + SuperExpression = 262, + IfExpression = 263, + WhenSubject = 264, + WhenExpression = 265, + WhenEntry = 266, + WhenCondition = 267, + RangeTest = 268, + TypeTest = 269, + TryExpression = 270, + CatchBlock = 271, + FinallyBlock = 272, + JumpExpression = 273, + CallableReference = 274, + AssignmentAndOperator = 275, + EqualityOperator = 276, + ComparisonOperator = 277, + InOperator = 278, + IsOperator = 279, + AdditiveOperator = 280, + MultiplicativeOperator = 281, + AsOperator = 282, + PrefixUnaryOperator = 283, + PostfixUnaryOperator = 284, + MemberAccessOperator = 285, + PostfixUnarySuffix = 286, + PostfixUnaryExpression = 287, + DirectlyAssignableExpression = 288, + Modifiers = 289, + ParameterModifiers = 290, + Modifier = 291, + TypeModifiers = 292, + TypeModifier = 293, + ClassModifier = 294, + MemberModifier = 295, + VisibilityModifier = 296, + VarianceModifier = 297, + TypeParameterModifiers = 298, + TypeParameterModifier = 299, + FunctionModifier = 300, + InheritanceModifier = 301, + ParameterModifier = 302, + PlatformModifier = 303, + Annotation = 304, + SingleAnnotation = 305, + MultiAnnotation = 306, + UseSiteTarget = 307, + UnescapedAnnotation = 308, + SimpleIdentifier = 309, + Identifier = 310, + ImportIdentifier = 311, + ReturnAt = 312, + ContinueAt = 313, + BreakAt = 314, + ThisAt = 315, + SuperAt = 316, + UnsignedLiteral = 317, + LongLiteral = 318, + BooleanLiteral = 319, + CharacterLiteral = 320, + CharacterEscapeSeq = 321, + LexicalIdentifier = 322, + UniCharacterLiteral = 323, + SourceFileRepeat1 = 324, + SourceFileRepeat2 = 325, + SourceFileRepeat3 = 326, + FileAnnotationRepeat1 = 327, + ImportListRepeat1 = 328, + ClassParametersRepeat1 = 329, + DelegationSpecifiersRepeat1 = 330, + AnnotatedDelegationSpecifierRepeat1 = 331, + TypeParametersRepeat1 = 332, + TypeConstraintsRepeat1 = 333, + FunctionValueParametersRepeat1 = 334, + EnumEntriesRepeat1 = 335, + NullableTypeRepeat1 = 336, + UserTypeRepeat1 = 337, + TypeProjectionModifiersRepeat1 = 338, + FunctionTypeParametersRepeat1 = 339, + StatementsRepeat1 = 340, + StatementRepeat1 = 341, + IndexingSuffixRepeat1 = 342, + TypeArgumentsRepeat1 = 343, + ValueArgumentsRepeat1 = 344, + StringLiteralRepeat1 = 345, + MultiVariableDeclarationRepeat1 = 346, + LambdaParametersRepeat1 = 347, + WhenExpressionRepeat1 = 348, + WhenEntryRepeat1 = 349, + TryExpressionRepeat1 = 350, + PostfixUnaryExpressionRepeat1 = 351, + ModifiersRepeat1 = 352, + ParameterModifiersRepeat1 = 353, + TypeModifiersRepeat1 = 354, + TypeParameterModifiersRepeat1 = 355, + IdentifierRepeat1 = 356, + InterpolatedExpression = 357, + InterpolatedIdentifier = 358, + TypeIdentifier = 359, + Error = 360, } impl From for &'static str { @@ -301,68 +372,117 @@ impl From for &'static str { fn from(tok: Kotlin) -> Self { match tok { Kotlin::End => "end", - Kotlin::Identifier => "identifier", + Kotlin::AlphaIdentifier => "_alpha_identifier", + Kotlin::HASHBANG => "#!", + Kotlin::ShebangLineToken1 => "shebang_line_token1", Kotlin::AT => "@", Kotlin::File => "file", Kotlin::COLON => ":", Kotlin::LBRACK => "[", Kotlin::RBRACK => "]", Kotlin::Package => "package", - Kotlin::SEMI => ";", - Kotlin::Import2 => "import", + Kotlin::Import => "import", Kotlin::DOT => ".", - Kotlin::STAR => "*", + Kotlin::WildcardImport => "wildcard_import", Kotlin::As => "as", + Kotlin::Typealias => "typealias", + Kotlin::EQ => "=", Kotlin::Class => "class", Kotlin::Fun => "fun", Kotlin::Interface => "interface", - Kotlin::Object => "object", + Kotlin::Enum => "enum", + Kotlin::Constructor => "constructor", + Kotlin::LBRACE => "{", + Kotlin::RBRACE => "}", + Kotlin::LPAREN => "(", + Kotlin::COMMA => ",", + Kotlin::RPAREN => ")", Kotlin::Val => "val", Kotlin::Var => "var", - Kotlin::EQ => "=", - Kotlin::Typealias => "typealias", - Kotlin::Companion => "companion", - Kotlin::Init => "init", - Kotlin::Constructor => "constructor", - Kotlin::This => "this", - Kotlin::Super => "super", + Kotlin::By => "by", Kotlin::LT => "<", - Kotlin::COMMA => ",", Kotlin::GT => ">", - Kotlin::LPAREN => "(", - Kotlin::RPAREN => ")", Kotlin::Where => "where", - Kotlin::By => "by", + Kotlin::Init => "init", + Kotlin::Companion => "companion", + Kotlin::Object => "object", + Kotlin::SEMI => ";", Kotlin::Get => "get", Kotlin::Set => "set", - Kotlin::LBRACE => "{", - Kotlin::RBRACE => "}", + Kotlin::This => "this", + Kotlin::Super => "super", + Kotlin::Dynamic => "dynamic", + Kotlin::AMP => "&", + Kotlin::Quest => "_quest", + Kotlin::STAR => "*", + Kotlin::DASHGT => "->", + Kotlin::Label => "label", Kotlin::For => "for", Kotlin::In => "in", Kotlin::While => "while", Kotlin::Do => "do", - Kotlin::Enum => "enum", + Kotlin::DOTDOT => "..", + Kotlin::QMARKCOLON => "?:", + Kotlin::AMPAMP => "&&", + Kotlin::PIPEPIPE => "||", + Kotlin::DOLLARLBRACE => "${", + Kotlin::DOLLAR => "$", + Kotlin::If => "if", + Kotlin::Else => "else", + Kotlin::When => "when", + Kotlin::Try => "try", + Kotlin::Catch => "catch", + Kotlin::Finally => "finally", + Kotlin::Throw => "throw", + Kotlin::Return => "return", + Kotlin::Continue => "continue", + Kotlin::Break => "break", + Kotlin::COLONCOLON => "::", + Kotlin::PLUSEQ => "+=", + Kotlin::DASHEQ => "-=", + Kotlin::STAREQ => "*=", + Kotlin::SLASHEQ => "/=", + Kotlin::PERCENTEQ => "%=", + Kotlin::BANGEQ => "!=", + Kotlin::BANGEQEQ => "!==", + Kotlin::EQEQ => "==", + Kotlin::EQEQEQ => "===", + Kotlin::LTEQ => "<=", + Kotlin::GTEQ => ">=", + Kotlin::BANGin => "!in", + Kotlin::Is => "is", + Kotlin::BANGis => "!is", + Kotlin::PLUS => "+", + Kotlin::DASH => "-", + Kotlin::SLASH => "/", + Kotlin::PERCENT => "%", + Kotlin::AsQMARK => "as?", + Kotlin::PLUSPLUS => "++", + Kotlin::DASHDASH => "--", + Kotlin::BANG => "!", + Kotlin::BANGBANG => "!!", + Kotlin::Suspend => "suspend", Kotlin::Sealed => "sealed", Kotlin::Annotation2 => "annotation", Kotlin::Data => "data", Kotlin::Inner => "inner", Kotlin::Value => "value", + Kotlin::Override => "override", + Kotlin::Lateinit => "lateinit", + Kotlin::Public => "public", + Kotlin::Private => "private", + Kotlin::Internal => "internal", + Kotlin::Protected => "protected", + Kotlin::Out => "out", Kotlin::Tailrec => "tailrec", Kotlin::Operator => "operator", Kotlin::Infix => "infix", Kotlin::Inline => "inline", Kotlin::External => "external", - Kotlin::Suspend => "suspend", - Kotlin::Const => "const", - Kotlin::Public => "public", - Kotlin::Private => "private", - Kotlin::Protected => "protected", - Kotlin::Internal => "internal", + Kotlin::PropertyModifier => "property_modifier", Kotlin::Abstract => "abstract", Kotlin::Final => "final", Kotlin::Open => "open", - Kotlin::Override => "override", - Kotlin::Lateinit => "lateinit", Kotlin::Vararg => "vararg", Kotlin::Noinline => "noinline", Kotlin::Crossinline => "crossinline", @@ -375,220 +495,244 @@ impl From for &'static str { Kotlin::Param => "param", Kotlin::Setparam => "setparam", Kotlin::Delegate => "delegate", - Kotlin::Dynamic => "dynamic", - Kotlin::QMARK => "?", - Kotlin::AMP => "&", - Kotlin::DASHGT => "->", - Kotlin::PLUSEQ => "+=", - Kotlin::DASHEQ => "-=", - Kotlin::STAREQ => "*=", - Kotlin::SLASHEQ => "/=", - Kotlin::PERCENTEQ => "%=", - Kotlin::PLUSPLUS => "++", - Kotlin::DASHDASH => "--", - Kotlin::PLUS => "+", - Kotlin::DASH => "-", - Kotlin::BANG => "!", - Kotlin::BANGBANG => "!!", - Kotlin::SLASH => "/", - Kotlin::PERCENT => "%", - Kotlin::PIPEPIPE => "||", - Kotlin::AMPAMP => "&&", - Kotlin::BANGEQ => "!=", - Kotlin::BANGEQEQ => "!==", - Kotlin::EQEQ => "==", - Kotlin::EQEQEQ => "===", - Kotlin::GTEQ => ">=", - Kotlin::LTEQ => "<=", - Kotlin::QMARKCOLON => "?:", - Kotlin::BANGin => "!in", - Kotlin::Is => "is", - Kotlin::AsQMARK => "as?", - Kotlin::DOTDOT => "..", - Kotlin::DOTDOTLT => "..<", + Kotlin::LineComment => "line_comment", + Kotlin::ReturnAT => "return@", + Kotlin::ContinueAT => "continue@", + Kotlin::BreakAT => "break@", Kotlin::ThisAT => "this@", Kotlin::SuperAT => "super@", Kotlin::AT2 => "@", - Kotlin::If => "if", - Kotlin::Else => "else", - Kotlin::When => "when", - Kotlin::Try => "try", - Kotlin::Catch => "catch", - Kotlin::Finally => "finally", - Kotlin::Return => "return", - Kotlin::ReturnAT => "return@", - Kotlin::Throw => "throw", - Kotlin::COLONCOLON => "::", - Kotlin::DQUOTE => "\"", - Kotlin::StringContent => "string_content", - Kotlin::StringContent2 => "string_content", - Kotlin::DOLLAR => "$", - Kotlin::DQUOTEDQUOTEDQUOTE => "\"\"\"", - Kotlin::DQUOTEDQUOTEDQUOTEDQUOTE => "\"\"\"\"", - Kotlin::DOLLARLBRACE => "${", + Kotlin::RealLiteral => "real_literal", + Kotlin::IntegerLiteral => "integer_literal", + Kotlin::HexLiteral => "hex_literal", + Kotlin::BinLiteral => "bin_literal", + Kotlin::UnsignedLiteralToken1 => "unsigned_literal_token1", + Kotlin::L => "L", + Kotlin::True => "true", + Kotlin::False => "false", Kotlin::SQUOTE => "'", Kotlin::CharacterLiteralToken1 => "character_literal_token1", - Kotlin::EscapeSequence => "escape_sequence", - Kotlin::NumberLiteral => "number_literal", - Kotlin::FloatLiteral => "float_literal", - Kotlin::Out => "out", - Kotlin::Label => "label", - Kotlin::Shebang => "shebang", - Kotlin::LineComment => "line_comment", - Kotlin::Semi => "_semi", - Kotlin::ClassMemberSemi => "_class_member_semi", - Kotlin::BlockComment => "block_comment", - Kotlin::BANGis => "!is", - Kotlin::In2 => "in", + Kotlin::NullLiteral => "null_literal", + Kotlin::BacktickIdentifier => "_backtick_identifier", + Kotlin::BSLASHu => "\\u", + Kotlin::UniCharacterLiteralToken1 => "_uni_character_literal_token1", + Kotlin::EscapedIdentifier => "_escaped_identifier", + Kotlin::AutomaticSemicolon => "_automatic_semicolon", + Kotlin::ImportListDelimiter => "_import_list_delimiter", Kotlin::QMARKDOT => "?.", - Kotlin::StringContent3 => "string_content", + Kotlin::MultilineComment => "multiline_comment", + Kotlin::StringStart => "_string_start", + Kotlin::StringEnd => "_string_end", + Kotlin::StringContent => "string_content", Kotlin::SourceFile => "source_file", + Kotlin::ShebangLine => "shebang_line", Kotlin::FileAnnotation => "file_annotation", Kotlin::PackageHeader => "package_header", - Kotlin::Import => "import", - Kotlin::Declaration => "declaration", - Kotlin::ClassDeclaration => "class_declaration", - Kotlin::ObjectDeclaration => "object_declaration", - Kotlin::PropertyDeclaration => "property_declaration", + Kotlin::ImportList => "import_list", + Kotlin::ImportHeader => "import_header", + Kotlin::ImportAlias => "import_alias", Kotlin::TypeAlias => "type_alias", - Kotlin::CompanionObject => "companion_object", - Kotlin::AnonymousInitializer => "anonymous_initializer", - Kotlin::SecondaryConstructor => "secondary_constructor", - Kotlin::ConstructorDelegationCall => "constructor_delegation_call", - Kotlin::TypeParameters => "type_parameters", - Kotlin::TypeParameter => "type_parameter", + Kotlin::Declaration => "_declaration", + Kotlin::ClassDeclaration => "class_declaration", Kotlin::PrimaryConstructor => "primary_constructor", - Kotlin::ClassParameters => "class_parameters", + Kotlin::ClassBody => "class_body", + Kotlin::ClassParameters => "_class_parameters", + Kotlin::BindingPatternKind => "binding_pattern_kind", Kotlin::ClassParameter => "class_parameter", + Kotlin::DelegationSpecifiers => "_delegation_specifiers", + Kotlin::DelegationSpecifier => "delegation_specifier", + Kotlin::ConstructorInvocation => "constructor_invocation", + Kotlin::ExplicitDelegation => "explicit_delegation", + Kotlin::TypeParameters => "type_parameters", + Kotlin::TypeParameter => "type_parameter", Kotlin::TypeConstraints => "type_constraints", Kotlin::TypeConstraint => "type_constraint", - Kotlin::ConstructorInvocation => "constructor_invocation", - Kotlin::FunctionDeclaration => "function_declaration", + Kotlin::ClassMemberDeclarations => "_class_member_declarations", + Kotlin::ClassMemberDeclaration => "_class_member_declaration", + Kotlin::AnonymousInitializer => "anonymous_initializer", + Kotlin::CompanionObject => "companion_object", Kotlin::FunctionValueParameters => "function_value_parameters", - Kotlin::Parameter => "parameter", - Kotlin::DelegationSpecifiers => "delegation_specifiers", - Kotlin::DelegationSpecifier => "delegation_specifier", + Kotlin::FunctionValueParameter => "_function_value_parameter", + Kotlin::ReceiverType => "receiver_type", + Kotlin::FunctionDeclaration => "function_declaration", + Kotlin::FunctionBody => "function_body", Kotlin::VariableDeclaration => "variable_declaration", - Kotlin::MultiVariableDeclaration => "multi_variable_declaration", + Kotlin::PropertyDeclaration => "property_declaration", Kotlin::PropertyDelegate => "property_delegate", - Kotlin::ExplicitDelegation => "explicit_delegation", Kotlin::Getter => "getter", Kotlin::Setter => "setter", - Kotlin::FunctionBody => "function_body", - Kotlin::Block => "block", - Kotlin::ForStatement => "for_statement", - Kotlin::WhileStatement => "while_statement", - Kotlin::DoWhileStatement => "do_while_statement", - Kotlin::ClassBody => "class_body", - Kotlin::ClassMemberDeclaration => "class_member_declaration", + Kotlin::ParameterWithOptionalType => "parameter_with_optional_type", + Kotlin::Parameter => "parameter", + Kotlin::ObjectDeclaration => "object_declaration", + Kotlin::SecondaryConstructor => "secondary_constructor", + Kotlin::ConstructorDelegationCall => "constructor_delegation_call", Kotlin::EnumClassBody => "enum_class_body", + Kotlin::EnumEntries => "_enum_entries", Kotlin::EnumEntry => "enum_entry", - Kotlin::ValueArguments => "value_arguments", - Kotlin::ValueArgument => "value_argument", - Kotlin::Statement => "statement", - Kotlin::Modifiers => "modifiers", - Kotlin::ClassModifier => "class_modifier", - Kotlin::FunctionModifier => "function_modifier", - Kotlin::PropertyModifier => "property_modifier", - Kotlin::VisibilityModifier => "visibility_modifier", - Kotlin::InheritanceModifier => "inheritance_modifier", - Kotlin::MemberModifier => "member_modifier", - Kotlin::ParameterModifiers => "parameter_modifiers", - Kotlin::ParameterModifier => "parameter_modifier", - Kotlin::PlatformModifier => "platform_modifier", - Kotlin::TypeModifiers => "type_modifiers", - Kotlin::Annotation => "annotation", - Kotlin::UseSiteTarget => "use_site_target", - Kotlin::UnescapedAnnotation => "_unescaped_annotation", - Kotlin::Type => "type", + Kotlin::Type => "_type", + Kotlin::TypeReference => "_type_reference", + Kotlin::NotNullableType => "not_nullable_type", + Kotlin::NullableType => "nullable_type", Kotlin::UserType => "user_type", Kotlin::SimpleUserType => "_simple_user_type", - Kotlin::NullableType => "nullable_type", - Kotlin::NonNullableType => "non_nullable_type", - Kotlin::ReceiverType => "_receiver_type", - Kotlin::TypeArguments => "type_arguments", Kotlin::TypeProjection => "type_projection", + Kotlin::TypeProjectionModifiers => "type_projection_modifiers", + Kotlin::TypeProjectionModifier => "_type_projection_modifier", Kotlin::FunctionType => "function_type", Kotlin::FunctionTypeParameters => "function_type_parameters", Kotlin::ParenthesizedType => "parenthesized_type", + Kotlin::ParenthesizedUserType => "parenthesized_user_type", + Kotlin::Statements => "statements", + Kotlin::Statement => "_statement", + Kotlin::ControlStructureBody => "control_structure_body", + Kotlin::Block => "_block", + Kotlin::LoopStatement => "_loop_statement", + Kotlin::ForStatement => "for_statement", + Kotlin::WhileStatement => "while_statement", + Kotlin::DoWhileStatement => "do_while_statement", + Kotlin::Semi => "_semi", Kotlin::Assignment => "assignment", - Kotlin::Expression => "expression", - Kotlin::PrimaryExpression => "primary_expression", - Kotlin::UnaryExpression => "unary_expression", - Kotlin::AnnotatedExpression => "annotated_expression", - Kotlin::LabeledExpression => "labeled_expression", - Kotlin::BinaryExpression => "binary_expression", - Kotlin::InExpression => "in_expression", - Kotlin::IsExpression => "is_expression", + Kotlin::Expression => "_expression", + Kotlin::UnaryExpression => "_unary_expression", + Kotlin::PostfixExpression => "postfix_expression", + Kotlin::CallExpression => "call_expression", + Kotlin::IndexingExpression => "indexing_expression", + Kotlin::NavigationExpression => "navigation_expression", + Kotlin::PrefixExpression => "prefix_expression", Kotlin::AsExpression => "as_expression", Kotlin::SpreadExpression => "spread_expression", + Kotlin::BinaryExpression => "_binary_expression", + Kotlin::MultiplicativeExpression => "multiplicative_expression", + Kotlin::AdditiveExpression => "additive_expression", Kotlin::RangeExpression => "range_expression", Kotlin::InfixExpression => "infix_expression", - Kotlin::CallExpression => "call_expression", + Kotlin::ElvisExpression => "elvis_expression", + Kotlin::CheckExpression => "check_expression", + Kotlin::ComparisonExpression => "comparison_expression", + Kotlin::EqualityExpression => "equality_expression", + Kotlin::ConjunctionExpression => "conjunction_expression", + Kotlin::DisjunctionExpression => "disjunction_expression", + Kotlin::IndexingSuffix => "indexing_suffix", + Kotlin::NavigationSuffix => "navigation_suffix", + Kotlin::CallSuffix => "call_suffix", Kotlin::AnnotatedLambda => "annotated_lambda", + Kotlin::TypeArguments => "type_arguments", + Kotlin::ValueArguments => "value_arguments", + Kotlin::ValueArgument => "value_argument", + Kotlin::PrimaryExpression => "_primary_expression", + Kotlin::ParenthesizedExpression => "parenthesized_expression", + Kotlin::CollectionLiteral => "collection_literal", + Kotlin::LiteralConstant => "_literal_constant", + Kotlin::StringLiteral => "string_literal", + Kotlin::Interpolation => "_interpolation", Kotlin::LambdaLiteral => "lambda_literal", + Kotlin::MultiVariableDeclaration => "multi_variable_declaration", Kotlin::LambdaParameters => "lambda_parameters", Kotlin::LambdaParameter => "_lambda_parameter", Kotlin::AnonymousFunction => "anonymous_function", - Kotlin::IndexExpression => "index_expression", + Kotlin::FunctionLiteral => "_function_literal", + Kotlin::ObjectLiteral => "object_literal", Kotlin::ThisExpression => "this_expression", Kotlin::SuperExpression => "super_expression", Kotlin::IfExpression => "if_expression", - Kotlin::ParenthesizedExpression => "parenthesized_expression", - Kotlin::CollectionLiteral => "collection_literal", - Kotlin::WhenExpression => "when_expression", Kotlin::WhenSubject => "when_subject", + Kotlin::WhenExpression => "when_expression", Kotlin::WhenEntry => "when_entry", - Kotlin::WhenCondition => "_when_condition", + Kotlin::WhenCondition => "when_condition", Kotlin::RangeTest => "range_test", Kotlin::TypeTest => "type_test", Kotlin::TryExpression => "try_expression", Kotlin::CatchBlock => "catch_block", Kotlin::FinallyBlock => "finally_block", - Kotlin::ReturnExpression => "return_expression", - Kotlin::ThrowExpression => "throw_expression", + Kotlin::JumpExpression => "jump_expression", Kotlin::CallableReference => "callable_reference", - Kotlin::NavigationExpression => "navigation_expression", - Kotlin::ObjectLiteral => "object_literal", - Kotlin::StringLiteral => "string_literal", - Kotlin::MultilineStringLiteral => "multiline_string_literal", - Kotlin::Interpolation => "interpolation", - Kotlin::CharacterLiteral => "character_literal", + Kotlin::AssignmentAndOperator => "_assignment_and_operator", + Kotlin::EqualityOperator => "_equality_operator", + Kotlin::ComparisonOperator => "_comparison_operator", + Kotlin::InOperator => "_in_operator", + Kotlin::IsOperator => "_is_operator", + Kotlin::AdditiveOperator => "_additive_operator", + Kotlin::MultiplicativeOperator => "_multiplicative_operator", + Kotlin::AsOperator => "_as_operator", + Kotlin::PrefixUnaryOperator => "_prefix_unary_operator", + Kotlin::PostfixUnaryOperator => "_postfix_unary_operator", + Kotlin::MemberAccessOperator => "_member_access_operator", + Kotlin::PostfixUnarySuffix => "_postfix_unary_suffix", + Kotlin::PostfixUnaryExpression => "_postfix_unary_expression", + Kotlin::DirectlyAssignableExpression => "directly_assignable_expression", + Kotlin::Modifiers => "modifiers", + Kotlin::ParameterModifiers => "parameter_modifiers", + Kotlin::Modifier => "_modifier", + Kotlin::TypeModifiers => "type_modifiers", + Kotlin::TypeModifier => "_type_modifier", + Kotlin::ClassModifier => "class_modifier", + Kotlin::MemberModifier => "member_modifier", + Kotlin::VisibilityModifier => "visibility_modifier", Kotlin::VarianceModifier => "variance_modifier", Kotlin::TypeParameterModifiers => "type_parameter_modifiers", - Kotlin::QualifiedIdentifier => "qualified_identifier", - Kotlin::ReservedIdentifier => "_reserved_identifier", + Kotlin::TypeParameterModifier => "_type_parameter_modifier", + Kotlin::FunctionModifier => "function_modifier", + Kotlin::InheritanceModifier => "inheritance_modifier", + Kotlin::ParameterModifier => "parameter_modifier", + Kotlin::PlatformModifier => "platform_modifier", + Kotlin::Annotation => "annotation", + Kotlin::SingleAnnotation => "_single_annotation", + Kotlin::MultiAnnotation => "_multi_annotation", + Kotlin::UseSiteTarget => "use_site_target", + Kotlin::UnescapedAnnotation => "_unescaped_annotation", + Kotlin::SimpleIdentifier => "simple_identifier", + Kotlin::Identifier => "identifier", + Kotlin::ImportIdentifier => "_import_identifier", + Kotlin::ReturnAt => "_return_at", + Kotlin::ContinueAt => "_continue_at", + Kotlin::BreakAt => "_break_at", + Kotlin::ThisAt => "_this_at", + Kotlin::SuperAt => "_super_at", + Kotlin::UnsignedLiteral => "unsigned_literal", + Kotlin::LongLiteral => "long_literal", + Kotlin::BooleanLiteral => "boolean_literal", + Kotlin::CharacterLiteral => "character_literal", + Kotlin::CharacterEscapeSeq => "character_escape_seq", + Kotlin::LexicalIdentifier => "_lexical_identifier", + Kotlin::UniCharacterLiteral => "_uni_character_literal", Kotlin::SourceFileRepeat1 => "source_file_repeat1", Kotlin::SourceFileRepeat2 => "source_file_repeat2", Kotlin::SourceFileRepeat3 => "source_file_repeat3", Kotlin::FileAnnotationRepeat1 => "file_annotation_repeat1", + Kotlin::ImportListRepeat1 => "import_list_repeat1", + Kotlin::ClassParametersRepeat1 => "_class_parameters_repeat1", + Kotlin::DelegationSpecifiersRepeat1 => "_delegation_specifiers_repeat1", + Kotlin::AnnotatedDelegationSpecifierRepeat1 => { + "_annotated_delegation_specifier_repeat1" + } Kotlin::TypeParametersRepeat1 => "type_parameters_repeat1", - Kotlin::ClassParametersRepeat1 => "class_parameters_repeat1", Kotlin::TypeConstraintsRepeat1 => "type_constraints_repeat1", Kotlin::FunctionValueParametersRepeat1 => "function_value_parameters_repeat1", - Kotlin::DelegationSpecifiersRepeat1 => "delegation_specifiers_repeat1", - Kotlin::DelegationSpecifierRepeat1 => "delegation_specifier_repeat1", - Kotlin::MultiVariableDeclarationRepeat1 => "multi_variable_declaration_repeat1", - Kotlin::ClassBodyRepeat1 => "class_body_repeat1", - Kotlin::EnumClassBodyRepeat1 => "enum_class_body_repeat1", - Kotlin::ValueArgumentsRepeat1 => "value_arguments_repeat1", - Kotlin::StatementsRepeat1 => "_statements_repeat1", - Kotlin::ModifiersRepeat1 => "modifiers_repeat1", - Kotlin::ParameterModifiersRepeat1 => "parameter_modifiers_repeat1", - Kotlin::TypeModifiersRepeat1 => "type_modifiers_repeat1", + Kotlin::EnumEntriesRepeat1 => "_enum_entries_repeat1", + Kotlin::NullableTypeRepeat1 => "nullable_type_repeat1", Kotlin::UserTypeRepeat1 => "user_type_repeat1", - Kotlin::TypeArgumentsRepeat1 => "type_arguments_repeat1", - Kotlin::TypeProjectionRepeat1 => "type_projection_repeat1", + Kotlin::TypeProjectionModifiersRepeat1 => "type_projection_modifiers_repeat1", Kotlin::FunctionTypeParametersRepeat1 => "function_type_parameters_repeat1", + Kotlin::StatementsRepeat1 => "statements_repeat1", + Kotlin::StatementRepeat1 => "_statement_repeat1", + Kotlin::IndexingSuffixRepeat1 => "indexing_suffix_repeat1", + Kotlin::TypeArgumentsRepeat1 => "type_arguments_repeat1", + Kotlin::ValueArgumentsRepeat1 => "value_arguments_repeat1", + Kotlin::StringLiteralRepeat1 => "string_literal_repeat1", + Kotlin::MultiVariableDeclarationRepeat1 => "multi_variable_declaration_repeat1", Kotlin::LambdaParametersRepeat1 => "lambda_parameters_repeat1", - Kotlin::IndexExpressionRepeat1 => "index_expression_repeat1", Kotlin::WhenExpressionRepeat1 => "when_expression_repeat1", Kotlin::WhenEntryRepeat1 => "when_entry_repeat1", Kotlin::TryExpressionRepeat1 => "try_expression_repeat1", - Kotlin::StringLiteralRepeat1 => "string_literal_repeat1", - Kotlin::MultilineStringLiteralRepeat1 => "multiline_string_literal_repeat1", + Kotlin::PostfixUnaryExpressionRepeat1 => "_postfix_unary_expression_repeat1", + Kotlin::ModifiersRepeat1 => "modifiers_repeat1", + Kotlin::ParameterModifiersRepeat1 => "parameter_modifiers_repeat1", + Kotlin::TypeModifiersRepeat1 => "type_modifiers_repeat1", Kotlin::TypeParameterModifiersRepeat1 => "type_parameter_modifiers_repeat1", - Kotlin::QualifiedIdentifierRepeat1 => "qualified_identifier_repeat1", + Kotlin::IdentifierRepeat1 => "identifier_repeat1", + Kotlin::InterpolatedExpression => "interpolated_expression", + Kotlin::InterpolatedIdentifier => "interpolated_identifier", + Kotlin::TypeIdentifier => "type_identifier", Kotlin::Error => "ERROR", } } diff --git a/src/macros.rs b/src/macros.rs index 5d77925b5..ce11c0cd8 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -8,6 +8,9 @@ macro_rules! get_language { (tree_sitter_tsx) => { tree_sitter_typescript::LANGUAGE_TSX.into() }; + (tree_sitter_kotlin_codanna) => { + tree_sitter_kotlin_codanna::language().into() + }; ($name:ident) => { $name::LANGUAGE.into() }; diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index 215bbc78d..f66295743 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -494,7 +494,7 @@ impl Cognitive for KotlinCode { fn compute( node: &Node, stats: &mut Stats, - nesting_map: &mut FxHashMap, + nesting_map: &mut HashMap, ) { use Kotlin::*; diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index 23e7e49b1..580a60305 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -865,11 +865,12 @@ impl Loc for KotlinCode { let (start, end) = init(node, stats, is_func_space, is_unit); let kind_id: Kotlin = node.kind_id().into(); match kind_id { - Comment => { + // LineComment and MultilineComment cover all comment types in this grammar + LineComment | MultilineComment => { add_cloc_lines(stats, start, end); } - Statements | Statement | LoopStatement | ForStatement | WhileStatement - | DoWhileStatement | StatementRepeat1 => { + // Statement types for logical lines counting + ForStatement | WhileStatement | DoWhileStatement => { stats.lloc.logical_lines += 1; } _ => { diff --git a/src/node.rs b/src/node.rs index 22bfb09bd..9ec7b01c8 100644 --- a/src/node.rs +++ b/src/node.rs @@ -18,7 +18,7 @@ impl Tree { Self(parser.parse(code, None).unwrap()) } - pub(crate) fn get_root(&self) -> Node { + pub(crate) fn get_root(&self) -> Node<'_> { Node(self.0.root_node()) } } @@ -108,12 +108,12 @@ impl<'a> Node<'a> { self.0.child_count() } - pub(crate) fn child_by_field_name(&self, name: &str) -> Option { + pub(crate) fn child_by_field_name(&self, name: &str) -> Option> { self.0.child_by_field_name(name).map(Node) } pub(crate) fn child(&self, pos: usize) -> Option> { - self.0.child(pos).map(Node) + self.0.child(pos as u32).map(Node) } pub(crate) fn children(&self) -> impl ExactSizeIterator> + use<'a> { diff --git a/src/parser.rs b/src/parser.rs index 6973247e4..b13901fb8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -152,7 +152,7 @@ impl< } #[inline(always)] - fn get_root(&self) -> Node { + fn get_root(&self) -> Node<'_> { self.tree.get_root() } diff --git a/src/tools.rs b/src/tools.rs index 2dd1cf7d9..17d6f9869 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -250,7 +250,7 @@ pub(crate) fn remove_blank_lines(data: &mut Vec) { let count_trailing = data .iter() .rev() - .take_while(|&c| (*c == b'\n' || *c == b'\r')) + .take_while(|&c| *c == b'\n' || *c == b'\r') .count(); if count_trailing > 0 { data.truncate(data.len() - count_trailing); diff --git a/src/traits.rs b/src/traits.rs index 0edb032b8..16d4ed9cb 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -61,7 +61,7 @@ pub trait ParserTrait { fn new(code: Vec, path: &Path, pr: Option>) -> Self; fn get_language(&self) -> LANG; - fn get_root(&self) -> Node; + fn get_root(&self) -> Node<'_>; fn get_code(&self) -> &[u8]; fn get_filters(&self, filters: &[String]) -> Filter; } From 1cb08beab9503e4f500b7141b077b4009d2bbbb2 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 13:41:09 -0300 Subject: [PATCH 34/42] Update dependencies to latest versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tree-sitter-rust: 0.23.2 → 0.24.0 - insta: 1.29.0 → 1.46.1 - Add .claude/ to .gitignore --- .gitignore | 1 + Cargo.toml | 4 ++-- enums/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 97dc21d31..4732d5498 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target enums/target *~ Cargo.lock +.claude/ diff --git a/Cargo.toml b/Cargo.toml index 1e6dcef46..f1561c972 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,14 +30,14 @@ tree-sitter-kotlin-codanna = "0.3.9" tree-sitter-typescript = "=0.23.2" tree-sitter-javascript = "=0.25.0" tree-sitter-python = "=0.25.0" -tree-sitter-rust = "=0.23.2" +tree-sitter-rust = "=0.24.0" 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"] } +insta = { version = "1.46.1", features = ["yaml", "json", "redactions"] } pretty_assertions = "^1.3" [profile.dev.package.insta] diff --git a/enums/Cargo.toml b/enums/Cargo.toml index 5987e7ec2..16fab9a67 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -14,7 +14,7 @@ tree-sitter-kotlin-codanna = "0.3.9" tree-sitter-typescript = "=0.23.2" tree-sitter-javascript = "=0.25.0" tree-sitter-python = "=0.25.0" -tree-sitter-rust = "=0.23.2" +tree-sitter-rust = "=0.24.0" 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" } From 9f4dae33c5dba48b06fee8fa1a572b7256527cd9 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:04:58 -0300 Subject: [PATCH 35/42] ci: Add GitHub Actions workflows for CI and Release --- .github/workflows/ci.yml | 63 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 57 +++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..4f81b38d0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: CI + +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo check --all-features + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy --all-targets --all-features -- -D warnings + + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - run: cargo fmt --all -- --check + + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo test --all-features + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo build --release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..478c9e701 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + create-release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/create-gh-release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + upload-assets: + needs: create-release + strategy: + matrix: + include: + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + - target: aarch64-apple-darwin + os: macos-latest + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + - target: i686-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-pc-windows-gnu + os: windows-latest + - target: x86_64-pc-windows-msvc + os: windows-latest + - target: aarch64-pc-windows-msvc + os: windows-latest + runs-on: ${{ matrix.os }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.target }} + if: startsWith(matrix.os, 'ubuntu') + - uses: taiki-e/upload-rust-binary-action@v1 + with: + bin: rust-code-analysis-cli + target: ${{ matrix.target }} + token: ${{ secrets.GITHUB_TOKEN }} From 43fbd6e109dff632e2aec7b2227bcd0564bd24a2 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:05:55 -0300 Subject: [PATCH 36/42] feat: Expose inner tree-sitter::Node for advanced use cases --- src/node.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node.rs b/src/node.rs index 9ec7b01c8..3b5fa2211 100644 --- a/src/node.rs +++ b/src/node.rs @@ -24,8 +24,11 @@ impl Tree { } /// An `AST` node. +/// +/// The inner `tree_sitter::Node` is exposed for advanced use cases +/// where direct access to the underlying tree-sitter API is needed. #[derive(Clone, Copy, Debug)] -pub struct Node<'a>(OtherNode<'a>); +pub struct Node<'a>(pub OtherNode<'a>); impl<'a> Node<'a> { /// Checks if a node represents a syntax error or contains any syntax errors From 1a36820c3199c222321a1ef63290014214af1990 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:08:35 -0300 Subject: [PATCH 37/42] feat: Add hazard analyzer API improvements - all_occurrences, has_ancestor, public methods --- src/node.rs | 77 +++++++++++++++++++++++++++++++++++++++++++-------- src/traits.rs | 13 ++++++++- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/node.rs b/src/node.rs index 3b5fa2211..dd89dbe79 100644 --- a/src/node.rs +++ b/src/node.rs @@ -37,49 +37,60 @@ impl<'a> Node<'a> { self.0.has_error() } - pub(crate) fn id(&self) -> usize { + /// Returns a numeric id for this node that is unique within its tree. + pub fn id(&self) -> usize { self.0.id() } - pub(crate) fn kind(&self) -> &'static str { + /// Returns the node's type as a string. + pub fn kind(&self) -> &'static str { self.0.kind() } - pub(crate) fn kind_id(&self) -> u16 { + /// Returns the node's type as a numeric id. + pub fn kind_id(&self) -> u16 { self.0.kind_id() } - pub(crate) fn utf8_text(&self, data: &'a [u8]) -> Option<&'a str> { + /// Returns the node's text as a UTF-8 string, if valid. + pub fn utf8_text(&self, data: &'a [u8]) -> Option<&'a str> { self.0.utf8_text(data).ok() } - pub(crate) fn start_byte(&self) -> usize { + /// Returns the byte offset where this node starts. + pub fn start_byte(&self) -> usize { self.0.start_byte() } - pub(crate) fn end_byte(&self) -> usize { + /// Returns the byte offset where this node ends. + pub fn end_byte(&self) -> usize { self.0.end_byte() } - pub(crate) fn start_position(&self) -> (usize, usize) { + /// Returns the (row, column) position where this node starts. + pub fn start_position(&self) -> (usize, usize) { let temp = self.0.start_position(); (temp.row, temp.column) } - pub(crate) fn end_position(&self) -> (usize, usize) { + /// Returns the (row, column) position where this node ends. + pub fn end_position(&self) -> (usize, usize) { let temp = self.0.end_position(); (temp.row, temp.column) } - pub(crate) fn start_row(&self) -> usize { + /// Returns the row number where this node starts. + pub fn start_row(&self) -> usize { self.0.start_position().row } - pub(crate) fn end_row(&self) -> usize { + /// Returns the row number where this node ends. + pub fn end_row(&self) -> usize { self.0.end_position().row } - pub(crate) fn parent(&self) -> Option> { + /// Returns this node's parent, if any. + pub fn parent(&self) -> Option> { self.0.parent().map(Node) } @@ -184,6 +195,21 @@ impl<'a> Node<'a> { res } + /// Checks if this node has any ancestor that meets the given predicate. + /// + /// Traverses up the tree from this node's parent to the root, + /// returning true if any ancestor satisfies the predicate. + pub fn has_ancestor bool>(&self, pred: F) -> bool { + let mut node = *self; + while let Some(parent) = node.parent() { + if pred(&parent) { + return true; + } + node = parent; + } + false + } + // Traverse a tree passing from children to children in search of a specific // token or series of tokens pub(crate) fn traverse_children(&self, token_list: &[F]) -> Option> @@ -256,6 +282,35 @@ impl<'a> Search<'a> for Node<'a> { None } + fn all_occurrences(&self, pred: fn(u16) -> bool) -> Vec> { + let mut cursor = self.cursor(); + let mut stack = Vec::new(); + let mut children = Vec::new(); + let mut results = Vec::new(); + + stack.push(*self); + + while let Some(node) = stack.pop() { + if pred(node.kind_id()) { + results.push(node); + } + cursor.reset(&node); + if cursor.goto_first_child() { + loop { + children.push(cursor.node()); + if !cursor.goto_next_sibling() { + break; + } + } + for child in children.drain(..).rev() { + stack.push(child); + } + } + } + + results + } + fn act_on_node(&self, action: &mut dyn FnMut(&Node<'a>)) { let mut cursor = self.cursor(); let mut stack = Vec::new(); diff --git a/src/traits.rs b/src/traits.rs index 16d4ed9cb..bf115fdb1 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -66,9 +66,20 @@ pub trait ParserTrait { fn get_filters(&self, filters: &[String]) -> Filter; } -pub(crate) trait Search<'a> { +/// Search trait for AST node traversal. +pub trait Search<'a> { + /// Starting from this node, gets the first occurrence that meets the predicate. fn first_occurrence(&self, pred: fn(u16) -> bool) -> Option>; + + /// Starting from this node, gets all nodes that meet the given predicate. + fn all_occurrences(&self, pred: fn(u16) -> bool) -> Vec>; + + /// Apply the given predicate on this node and all descendants. fn act_on_node(&self, pred: &mut dyn FnMut(&Node<'a>)); + + /// Starting from this node, gets the first child that meets the predicate. fn first_child(&self, pred: fn(u16) -> bool) -> Option>; + + /// Apply the given action on node's immediate children. fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>)); } From 4f9c276a3a9686fd65318a9b105149afb29ed4c4 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:19:26 -0300 Subject: [PATCH 38/42] fix: Make asttools module functional with correct Node API --- src/asttools.rs | 125 +++++++++++++++++++++++++++++++++++------------- src/lib.rs | 4 ++ 2 files changed, 97 insertions(+), 32 deletions(-) diff --git a/src/asttools.rs b/src/asttools.rs index 6a93afccc..c9b43f16c 100644 --- a/src/asttools.rs +++ b/src/asttools.rs @@ -1,51 +1,94 @@ +//! AST traversal and analysis utilities. +//! +//! This module provides helper functions and macros for traversing +//! and analyzing the AST tree structure. + use crate::node::Node; -#[allow(dead_code)] -pub fn get_parent<'a>(node: &'a Node<'a>, level: usize) -> Option> { +/// Gets an ancestor at a specific level above the current node. +/// +/// # Arguments +/// * `node` - The starting node +/// * `level` - How many levels up to traverse (0 returns the node itself) +/// +/// # Returns +/// The ancestor node at the specified level, or None if the tree isn't deep enough. +/// +/// # Example +/// ```ignore +/// // Get the grandparent (2 levels up) +/// if let Some(grandparent) = get_parent(&node, 2) { +/// println!("Grandparent kind: {}", grandparent.kind()); +/// } +/// ``` +pub fn get_parent<'a>(node: &Node<'a>, level: usize) -> Option> { let mut level = level; - let mut node = *node; + let mut current = *node; while level != 0 { - if let Some(parent) = node.object().parent() { - node = Node::new(parent); - } else { - return None; - } + current = current.parent()?; level -= 1; } - - Some(node) + Some(current) } -// Traverse a tree passing from children to children in search of a specific -// token or series of tokens -pub(crate) fn traverse_children<'a, F>(node: &'a Node<'a>, token_list: &[F]) -> Option> +/// Traverses a tree passing from children to children in search of a specific +/// token or series of tokens. +/// +/// # Arguments +/// * `node` - The starting node +/// * `token_list` - A slice of predicates, each matching a level of descent +/// +/// # Returns +/// The final node after following the token path, or None if any token wasn't found. +/// +/// # Example +/// ```ignore +/// // Find: node -> child matching pred1 -> grandchild matching pred2 +/// let result = traverse_children(&node, &[ +/// |id| id == SomeToken::Foo as u16, +/// |id| id == SomeToken::Bar as u16, +/// ]); +/// ``` +pub fn traverse_children<'a, F>(node: &Node<'a>, token_list: &[F]) -> Option> where - F: FnOnce(u16) -> bool + Copy, + F: Fn(u16) -> bool, { - let mut node = *node; + let mut current = *node; 'outer: for token in token_list { - for temp_node in node.children() { - if token(temp_node.object().kind_id()) { - node = temp_node; + for child in current.children() { + if token(child.kind_id()) { + current = child; continue 'outer; } } - // If a token has not been found, return None + // Token not found at this level return None; } - Some(node) + Some(current) } +/// Checks if a node has specific ancestors in sequence. +/// +/// This macro checks if the node's ancestors match a specific pattern, +/// where the first pattern(s) are immediate ancestors and the last pattern +/// is the final ancestor to match. +/// +/// # Example +/// ```ignore +/// // Check if node is inside a function inside a class +/// let is_method = has_ancestors!(node, Class | Struct, Function); +/// ``` +#[macro_export] macro_rules! has_ancestors { ($node:expr, $( $typs:pat_param )|*, $( $typ:pat_param ),+) => {{ let mut res = false; loop { let mut node = *$node; $( - if let Some(parent) = node.object().parent() { + if let Some(parent) = node.parent() { match parent.kind_id().into() { $typ => { - node = Node::new(parent); + node = parent; }, _ => { break; @@ -55,17 +98,13 @@ macro_rules! has_ancestors { break; } )* - if let Some(parent) = node.object().parent() { + if let Some(parent) = node.parent() { match parent.kind_id().into() { $( $typs )|+ => { res = true; }, - _ => { - break; - } + _ => {} } - } else { - break; } break; } @@ -73,22 +112,44 @@ macro_rules! has_ancestors { }}; } +/// Counts specific ancestors matching a pattern until a stop condition. +/// +/// This macro traverses up the tree counting ancestors that match the given +/// patterns, stopping when it encounters an ancestor matching the stop pattern. +/// +/// # Example +/// ```ignore +/// // Count nested if statements until we hit a function boundary +/// let nesting = count_specific_ancestors!(node, If | ElseIf, Function | Method); +/// ``` +#[macro_export] macro_rules! count_specific_ancestors { - ($node:expr, $( $typs:pat_param )|*, $( $stops:pat_param )|*) => {{ + ($node:expr, $checker:ty, $( $typs:pat_param )|*, $( $stops:pat_param )|*) => {{ let mut count = 0; let mut node = *$node; - while let Some(parent) = node.object().parent() { + while let Some(parent) = node.parent() { match parent.kind_id().into() { $( $typs )|* => { - if !Self::is_else_if(&Node::new(parent)) { + if !<$checker>::is_else_if(&parent) { count += 1; } }, $( $stops )|* => break, _ => {} } - node = Node::new(parent); + node = parent; } count }}; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_parent_level_zero() { + // Level 0 should return the same node + // (actual test would need a real node) + } +} diff --git a/src/lib.rs b/src/lib.rs index 923210d28..fcb55935e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,10 @@ pub use crate::function::*; mod ast; pub use crate::ast::*; +/// AST traversal and analysis utilities. +pub mod asttools; +pub use crate::asttools::{get_parent, traverse_children}; + mod count; pub use crate::count::*; From a44288d369710430a20f44f7a7cc642adb9010d3 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:24:25 -0300 Subject: [PATCH 39/42] Fix PR review comments from Copilot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - npa.rs: Fix typo "interfaces" → "interface" in comment - npm.rs: Fix typo "interfaces" → "interface" in comment - cognitive.rs: Add missing space after comma in increase_nesting calls - abc.rs: Update Java grammar references to Kotlin grammar in comments - abc.rs: Fix typo "do-while statements" → "inside do-while statements" --- src/metrics/abc.rs | 10 ++++------ src/metrics/cognitive.rs | 18 +++++++++--------- src/metrics/npa.rs | 2 +- src/metrics/npm.rs | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/metrics/abc.rs b/src/metrics/abc.rs index 52b47c34c..120c4508e 100644 --- a/src/metrics/abc.rs +++ b/src/metrics/abc.rs @@ -293,8 +293,7 @@ fn java_inspect_container(container_node: &Node, conditions: &mut f64) { // Parenthesized expressions and `Not` operators nodes // always store their expressions in the children nodes of index one - // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2472 - // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2150 + // Reference: tree-sitter-kotlin grammar for parenthesized_expression and prefix_expression node = node.child(1).unwrap(); node_kind = node.kind_id().into(); @@ -440,7 +439,7 @@ impl Abc for JavaCode { } } } - // Counts unary conditions do-while statements + // Counts unary conditions inside do-while statements DoStatement => { // The child node of index 3 contains the condition if let Some(condition) = node.child(3) { @@ -582,8 +581,7 @@ fn kotlin_inspect_container(container_node: &Node, conditions: &mut f64) { // Parenthesized expressions and `Not` operators nodes // always store their expressions in the children nodes of index one - // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2472 - // https://github.com/tree-sitter/tree-sitter-java/blob/master/src/grammar.json#L2150 + // Reference: tree-sitter-kotlin grammar for parenthesized_expression and prefix_expression node = node.child(1).unwrap(); node_kind = node.kind_id().into(); @@ -706,7 +704,7 @@ impl Abc for KotlinCode { } } } - // Counts unary conditions do-while statements + // Counts unary conditions inside do-while statements DoWhileStatement => { // The child node of index 3 contains the condition if let Some(condition) = node.child(3) { diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index f66295743..65ace4e7a 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -318,11 +318,11 @@ impl Cognitive for RustCode { IfExpression => { // Check if a node is not an else-if if !Self::is_else_if(node) { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } } ForExpression | WhileExpression | MatchExpression => { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } Else /*else-if also */ => { increment_by_one(stats); @@ -368,11 +368,11 @@ impl Cognitive for CppCode { match node.kind_id().into() { IfStatement => { if !Self::is_else_if(node) { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } } ForStatement | WhileStatement | DoStatement | SwitchStatement | CatchClause => { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } GotoStatement | Else /* else-if also */ => { increment_by_one(stats); @@ -401,11 +401,11 @@ macro_rules! js_cognitive { match node.kind_id().into() { IfStatement => { if !Self::is_else_if(&node) { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } } ForStatement | ForInStatement | WhileStatement | DoStatement | SwitchStatement | CatchClause | TernaryExpression => { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } Else /* else-if also */ => { increment_by_one(stats); @@ -466,11 +466,11 @@ impl Cognitive for JavaCode { match node.kind_id().into() { IfStatement => { if !Self::is_else_if(node) { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } } ForStatement | WhileStatement | DoStatement | SwitchBlock | CatchClause => { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } Else /* else-if also */ => { increment_by_one(stats); @@ -504,7 +504,7 @@ impl Cognitive for KotlinCode { match node.kind_id().into() { IfExpression => { if !Self::is_else_if(node) { - increase_nesting(stats,&mut nesting, depth, lambda); + increase_nesting(stats, &mut nesting, depth, lambda); } } ForStatement | WhileStatement | DoWhileStatement | WhenExpression | CatchBlock => { diff --git a/src/metrics/npa.rs b/src/metrics/npa.rs index a5cb87ed0..498c43c56 100644 --- a/src/metrics/npa.rs +++ b/src/metrics/npa.rs @@ -278,7 +278,7 @@ impl Npa for KotlinCode { } if node.kind_id() == ClassBody { - // Check if this node is an interfaces + // Check if this node is an interface let mut is_interface = false; let mut node_sibling = *node; while let Some(prev_sibling) = node_sibling.previous_sibling() { diff --git a/src/metrics/npm.rs b/src/metrics/npm.rs index 9410456a7..b36f56021 100644 --- a/src/metrics/npm.rs +++ b/src/metrics/npm.rs @@ -269,7 +269,7 @@ impl Npm for KotlinCode { } if node.kind_id() == ClassBody { - // Check if this node is an interfaces + // Check if this node is an interface let mut is_interface = false; let mut node_sibling = *node; while let Some(prev_sibling) = node_sibling.previous_sibling() { From 30d22285b0bbc59740f953cf245c02ebed70e952 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:36:26 -0300 Subject: [PATCH 40/42] Fix clippy collapsible_if warnings Collapse nested if statements into single conditions using Rust's if-let chain syntax (let-chains). This modernizes the codebase to use the newer Rust idiom and satisfies clippy's collapsible_if lint. Files fixed: - src/alterator.rs - src/asttools.rs - src/checker.rs - src/find.rs - src/getter.rs - src/metrics/abc.rs - src/metrics/cognitive.rs - src/metrics/loc.rs - src/metrics/nargs.rs - src/node.rs --- src/alterator.rs | 8 +-- src/asttools.rs | 2 - src/checker.rs | 10 +-- src/find.rs | 14 ++--- src/getter.rs | 50 ++++++++------- src/metrics/abc.rs | 128 +++++++++++++++++++-------------------- src/metrics/cognitive.rs | 8 +-- src/metrics/loc.rs | 13 ++-- src/metrics/nargs.rs | 9 ++- src/node.rs | 16 ++--- 10 files changed, 127 insertions(+), 131 deletions(-) diff --git a/src/alterator.rs b/src/alterator.rs index 6e9f9734f..a79c4964a 100644 --- a/src/alterator.rs +++ b/src/alterator.rs @@ -70,10 +70,10 @@ impl Alterator for CppCode { AstNode::new(node.kind(), text, span, Vec::new()) } Cpp::PreprocDef | Cpp::PreprocFunctionDef | Cpp::PreprocCall => { - if let Some(last) = children.last() { - if last.r#type == "\n" { - children.pop(); - } + if let Some(last) = children.last() + && last.r#type == "\n" + { + children.pop(); } Self::get_default(node, code, span, children) } diff --git a/src/asttools.rs b/src/asttools.rs index c9b43f16c..95819c5bc 100644 --- a/src/asttools.rs +++ b/src/asttools.rs @@ -145,8 +145,6 @@ macro_rules! count_specific_ancestors { #[cfg(test)] mod tests { - use super::*; - #[test] fn test_get_parent_level_zero() { // Level 0 should return the same node diff --git a/src/checker.rs b/src/checker.rs index 40c6b528d..b0eb0fc38 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -601,11 +601,11 @@ impl Checker for RustCode { } fn is_useful_comment(node: &Node, code: &[u8]) -> bool { - if let Some(parent) = node.parent() { - if parent.kind_id() == Rust::TokenTree { - // A comment could be a macro token - return true; - } + if let Some(parent) = node.parent() + && parent.kind_id() == Rust::TokenTree + { + // A comment could be a macro token + return true; } let code = &code[node.start_byte()..node.end_byte()]; code.starts_with(b"/// cbindgen:") diff --git a/src/find.rs b/src/find.rs index f441fe533..b6c37b91c 100644 --- a/src/find.rs +++ b/src/find.rs @@ -65,14 +65,14 @@ impl Callback for Find { type Cfg = FindCfg; fn call(cfg: Self::Cfg, parser: &T) -> Self::Res { - if let Some(good) = find(parser, &cfg.filters) { - if !good.is_empty() { - println!("In file {}", cfg.path.to_str().unwrap()); - for node in good { - dump_node(parser.get_code(), &node, 1, cfg.line_start, cfg.line_end)?; - } - println!(); + if let Some(good) = find(parser, &cfg.filters) + && !good.is_empty() + { + println!("In file {}", cfg.path.to_str().unwrap()); + for node in good { + dump_node(parser.get_code(), &node, 1, cfg.line_start, cfg.line_end)?; } + println!(); } Ok(()) } diff --git a/src/getter.rs b/src/getter.rs index 89ad66e2c..946f3799d 100644 --- a/src/getter.rs +++ b/src/getter.rs @@ -75,10 +75,10 @@ impl Getter for PythonCode { String => { let mut operator = HalsteadType::Unknown; // check if we've a documentation string or a multiline comment - if let Some(parent) = node.parent() { - if parent.kind_id() != ExpressionStatement || parent.child_count() != 1 { - operator = HalsteadType::Operand; - }; + if let Some(parent) = node.parent() + && (parent.kind_id() != ExpressionStatement || parent.child_count() != 1) + { + operator = HalsteadType::Operand; } operator } @@ -438,32 +438,30 @@ impl Getter for CppCode { return std::str::from_utf8(code).ok(); } // we're in a function_definition so need to get the declarator - if let Some(declarator) = node.child_by_field_name("declarator") { - let declarator_node = declarator; - if let Some(fd) = declarator_node.first_occurrence(|id| { + if let Some(declarator) = node.child_by_field_name("declarator") + && let Some(fd) = declarator.first_occurrence(|id| { Cpp::FunctionDeclarator == id || Cpp::FunctionDeclarator2 == id || Cpp::FunctionDeclarator3 == id - }) { - if let Some(first) = fd.child(0) { - match first.kind_id().into() { - Cpp::TypeIdentifier - | Cpp::Identifier - | Cpp::FieldIdentifier - | Cpp::DestructorName - | Cpp::OperatorName - | Cpp::QualifiedIdentifier - | Cpp::QualifiedIdentifier2 - | Cpp::QualifiedIdentifier3 - | Cpp::QualifiedIdentifier4 - | Cpp::TemplateFunction - | Cpp::TemplateMethod => { - let code = &code[first.start_byte()..first.end_byte()]; - return std::str::from_utf8(code).ok(); - } - _ => {} - } + }) + && let Some(first) = fd.child(0) + { + match first.kind_id().into() { + Cpp::TypeIdentifier + | Cpp::Identifier + | Cpp::FieldIdentifier + | Cpp::DestructorName + | Cpp::OperatorName + | Cpp::QualifiedIdentifier + | Cpp::QualifiedIdentifier2 + | Cpp::QualifiedIdentifier3 + | Cpp::QualifiedIdentifier4 + | Cpp::TemplateFunction + | Cpp::TemplateMethod => { + let code = &code[first.start_byte()..first.end_byte()]; + return std::str::from_utf8(code).ok(); } + _ => {} } } } diff --git a/src/metrics/abc.rs b/src/metrics/abc.rs index 120c4508e..adf0f955b 100644 --- a/src/metrics/abc.rs +++ b/src/metrics/abc.rs @@ -402,10 +402,10 @@ impl Abc for JavaCode { } GT | LT => { // Excludes `<` and `>` used for generic types - if let Some(parent) = node.parent() { - if !matches!(parent.kind_id().into(), TypeArguments) { - stats.conditions += 1.; - } + if let Some(parent) = node.parent() + && !matches!(parent.kind_id().into(), TypeArguments) + { + stats.conditions += 1.; } } // Counts unary conditions in elements separated by `&&` or `||` boolean operators @@ -421,31 +421,31 @@ impl Abc for JavaCode { // Counts unary conditions inside assignments VariableDeclarator | AssignmentExpression => { // The child node of index 2 contains the right operand of an assignment operation - if let Some(right_operand) = node.child(2) { - if matches!( + if let Some(right_operand) = node.child(2) + && matches!( right_operand.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - java_inspect_container(&right_operand, &mut stats.conditions); - } + ) + { + java_inspect_container(&right_operand, &mut stats.conditions); } } // Counts unary conditions inside if and while statements IfStatement | WhileStatement => { // The child node of index 1 contains the condition - if let Some(condition) = node.child(1) { - if matches!(condition.kind_id().into(), ParenthesizedExpression) { - java_inspect_container(&condition, &mut stats.conditions); - } + if let Some(condition) = node.child(1) + && matches!(condition.kind_id().into(), ParenthesizedExpression) + { + java_inspect_container(&condition, &mut stats.conditions); } } // Counts unary conditions inside do-while statements DoStatement => { // The child node of index 3 contains the condition - if let Some(condition) = node.child(3) { - if matches!(condition.kind_id().into(), ParenthesizedExpression) { - java_inspect_container(&condition, &mut stats.conditions); - } + if let Some(condition) = node.child(3) + && matches!(condition.kind_id().into(), ParenthesizedExpression) + { + java_inspect_container(&condition, &mut stats.conditions); } } // Counts unary conditions inside for statements @@ -485,25 +485,25 @@ impl Abc for JavaCode { // Counts unary conditions inside return statements ReturnStatement => { // The child node of index 1 contains the return value - if let Some(value) = node.child(1) { - if matches!( + if let Some(value) = node.child(1) + && matches!( value.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - java_inspect_container(&value, &mut stats.conditions) - } + ) + { + java_inspect_container(&value, &mut stats.conditions) } } // Counts unary conditions inside implicit return statements in lambda expressions LambdaExpression => { // The child node of index 2 contains the return value - if let Some(value) = node.child(2) { - if matches!( + if let Some(value) = node.child(2) + && matches!( value.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - java_inspect_container(&value, &mut stats.conditions) - } + ) + { + java_inspect_container(&value, &mut stats.conditions) } } // Counts unary conditions inside ternary expressions @@ -521,22 +521,22 @@ impl Abc for JavaCode { } } // The child node of index 2 contains the first expression - if let Some(expression) = node.child(2) { - if matches!( + if let Some(expression) = node.child(2) + && matches!( expression.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - java_inspect_container(&expression, &mut stats.conditions); - } + ) + { + java_inspect_container(&expression, &mut stats.conditions); } // The child node of index 4 contains the second expression - if let Some(expression) = node.child(4) { - if matches!( + if let Some(expression) = node.child(4) + && matches!( expression.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - java_inspect_container(&expression, &mut stats.conditions); - } + ) + { + java_inspect_container(&expression, &mut stats.conditions); } } _ => {} @@ -671,10 +671,10 @@ impl Abc for KotlinCode { } GT | LT => { // Excludes `<` and `>` used for generic types - if let Some(parent) = node.parent() { - if !matches!(parent.kind_id().into(), TypeArguments) { - stats.conditions += 1.; - } + if let Some(parent) = node.parent() + && !matches!(parent.kind_id().into(), TypeArguments) + { + stats.conditions += 1.; } } // Counts unary conditions in elements separated by `&&` or `||` boolean operators @@ -686,31 +686,31 @@ impl Abc for KotlinCode { // Counts unary conditions inside assignments Assignment => { // The child node of index 2 contains the right operand of an assignment operation - if let Some(right_operand) = node.child(2) { - if matches!( + if let Some(right_operand) = node.child(2) + && matches!( right_operand.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - kotlin_inspect_container(&right_operand, &mut stats.conditions); - } + ) + { + kotlin_inspect_container(&right_operand, &mut stats.conditions); } } // Counts unary conditions inside if and while statements IfExpression | WhileStatement => { // The child node of index 1 contains the condition - if let Some(condition) = node.child(1) { - if matches!(condition.kind_id().into(), ParenthesizedExpression) { - kotlin_inspect_container(&condition, &mut stats.conditions); - } + if let Some(condition) = node.child(1) + && matches!(condition.kind_id().into(), ParenthesizedExpression) + { + kotlin_inspect_container(&condition, &mut stats.conditions); } } // Counts unary conditions inside do-while statements DoWhileStatement => { // The child node of index 3 contains the condition - if let Some(condition) = node.child(3) { - if matches!(condition.kind_id().into(), ParenthesizedExpression) { - kotlin_inspect_container(&condition, &mut stats.conditions); - } + if let Some(condition) = node.child(3) + && matches!(condition.kind_id().into(), ParenthesizedExpression) + { + kotlin_inspect_container(&condition, &mut stats.conditions); } } // Counts unary conditions inside for statements @@ -749,25 +749,25 @@ impl Abc for KotlinCode { // Counts unary conditions inside return statements Return => { // The child node of index 1 contains the return value - if let Some(value) = node.child(1) { - if matches!( + if let Some(value) = node.child(1) + && matches!( value.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - kotlin_inspect_container(&value, &mut stats.conditions) - } + ) + { + kotlin_inspect_container(&value, &mut stats.conditions) } } // Counts unary conditions inside implicit return statements in lambda expressions AnnotatedLambda => { // The child node of index 2 contains the return value - if let Some(value) = node.child(2) { - if matches!( + if let Some(value) = node.child(2) + && matches!( value.kind_id().into(), ParenthesizedExpression | UnaryExpression - ) { - kotlin_inspect_container(&value, &mut stats.conditions) - } + ) + { + kotlin_inspect_container(&value, &mut stats.conditions) } } _ => {} diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index 65ace4e7a..1fcff448b 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -328,10 +328,10 @@ impl Cognitive for RustCode { increment_by_one(stats); } BreakExpression | ContinueExpression => { - if let Some(label_child) = node.child(1) { - if let Label = label_child.kind_id().into() { - increment_by_one(stats); - } + if let Some(label_child) = node.child(1) + && let Label = label_child.kind_id().into() + { + increment_by_one(stats); } } UnaryExpression => { diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index 580a60305..c5967b7cd 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -553,12 +553,13 @@ fn add_cloc_lines(stats: &mut Stats, start: usize, end: usize) { // This difference is necessary in order to avoid having // a wrong count for the blank metric. fn check_comment_ends_on_code_line(stats: &mut Stats, start_code_line: usize) { - if let Some(end) = stats.cloc.comment_line_end { - if end == start_code_line && !stats.ploc.lines.contains(&start_code_line) { - // Comment entirely *before* a code line - stats.cloc.only_comment_lines -= 1; - stats.cloc.code_comment_lines += 1; - } + if let Some(end) = stats.cloc.comment_line_end + && end == start_code_line + && !stats.ploc.lines.contains(&start_code_line) + { + // Comment entirely *before* a code line + stats.cloc.only_comment_lines -= 1; + stats.cloc.code_comment_lines += 1; } } diff --git a/src/metrics/nargs.rs b/src/metrics/nargs.rs index 9c64545a5..74122b79c 100644 --- a/src/metrics/nargs.rs +++ b/src/metrics/nargs.rs @@ -229,11 +229,10 @@ impl NArgs for CppCode { return; } - if Self::is_closure(node) { - if let Some(declarator) = node.child_by_field_name("declarator") { - let new_node = declarator; - compute_args::(&new_node, &mut stats.closure_nargs); - } + if Self::is_closure(node) + && let Some(declarator) = node.child_by_field_name("declarator") + { + compute_args::(&declarator, &mut stats.closure_nargs); } } } diff --git a/src/node.rs b/src/node.rs index dd89dbe79..141c2433f 100644 --- a/src/node.rs +++ b/src/node.rs @@ -182,15 +182,15 @@ impl<'a> Node<'a> { pub(crate) fn has_ancestors(&self, typ: fn(&Node) -> bool, typs: fn(&Node) -> bool) -> bool { let mut res = false; let mut node = *self; - if let Some(parent) = node.parent() { - if typ(&parent) { - node = parent; - } + if let Some(parent) = node.parent() + && typ(&parent) + { + node = parent; } - if let Some(parent) = node.parent() { - if typs(&parent) { - res = true; - } + if let Some(parent) = node.parent() + && typs(&parent) + { + res = true; } res } From 56774b4e145595b0958168ef018d51afafcd6bdc Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 14:41:37 -0300 Subject: [PATCH 41/42] style: Fix rustfmt formatting in checker.rs --- src/checker.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index b0eb0fc38..066a93c6f 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -664,7 +664,10 @@ impl Checker for RustCode { impl Checker for KotlinCode { fn is_comment(node: &Node) -> bool { - matches!(node.kind_id().into(), Kotlin::LineComment | Kotlin::MultilineComment) + matches!( + node.kind_id().into(), + Kotlin::LineComment | Kotlin::MultilineComment + ) } fn is_useful_comment(_: &Node, _: &[u8]) -> bool { @@ -704,7 +707,10 @@ impl Checker for KotlinCode { fn is_string(node: &Node) -> bool { // StringLiteral covers both single-line and multi-line strings in this grammar // StringContent captures the text content within strings - matches!(node.kind_id().into(), Kotlin::StringLiteral | Kotlin::StringContent) + matches!( + node.kind_id().into(), + Kotlin::StringLiteral | Kotlin::StringContent + ) } fn is_else_if(node: &Node) -> bool { From ecafc19e7f37151f730e8c8a5489681f05f86498 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Mon, 19 Jan 2026 15:02:23 -0300 Subject: [PATCH 42/42] Regenerate language enums for tree-sitter 0.26.3 Update all language enum files using the enums generator to match the upgraded tree-sitter grammar versions: - tree-sitter-rust 0.24.0 - tree-sitter-javascript 0.25.0 - tree-sitter-python 0.25.0 - tree-sitter-kotlin-codanna 0.3.9 Update test snapshots to reflect changes in grammar parsing behavior across Python and JavaScript metrics tests. --- src/languages/language_ccomment.rs | 2 + src/languages/language_cpp.rs | 26 +- src/languages/language_java.rs | 2 + src/languages/language_javascript.rs | 510 ++++++++++---------- src/languages/language_kotlin.rs | 6 +- src/languages/language_mozjs.rs | 2 + src/languages/language_preproc.rs | 2 + src/languages/language_python.rs | 278 +++++------ src/languages/language_rust.rs | 680 ++++++++++++++------------- src/languages/language_tsx.rs | 2 + src/languages/language_typescript.rs | 10 +- src/metrics/cognitive.rs | 165 ++++--- src/metrics/exit.rs | 30 +- src/metrics/halstead.rs | 35 +- src/metrics/loc.rs | 376 +++++++-------- src/metrics/nargs.rs | 270 ++++++----- src/metrics/nom.rs | 189 ++++---- 17 files changed, 1319 insertions(+), 1266 deletions(-) diff --git a/src/languages/language_ccomment.rs b/src/languages/language_ccomment.rs index 34742d857..2373d5fb3 100644 --- a/src/languages/language_ccomment.rs +++ b/src/languages/language_ccomment.rs @@ -21,6 +21,7 @@ pub enum Ccomment { TranslationUnitRepeat1 = 14, DefineRepeat1 = 15, Error = 16, + } impl From for &'static str { @@ -44,6 +45,7 @@ impl From for &'static str { Ccomment::TranslationUnitRepeat1 => "translation_unit_repeat1", Ccomment::DefineRepeat1 => "define_repeat1", Ccomment::Error => "ERROR", + } } } diff --git a/src/languages/language_cpp.rs b/src/languages/language_cpp.rs index c359fce00..4db18b011 100644 --- a/src/languages/language_cpp.rs +++ b/src/languages/language_cpp.rs @@ -643,6 +643,7 @@ pub enum Cpp { StatementIdentifier = 636, TypeIdentifier = 637, Error = 638, + } impl From for &'static str { @@ -908,9 +909,7 @@ impl From for &'static str { Cpp::MOZHEAPALLOCATOR => "MOZ_HEAP_ALLOCATOR", Cpp::MOZHEAPCLASS => "MOZ_HEAP_CLASS", Cpp::MOZIMPLICIT => "MOZ_IMPLICIT", - Cpp::MOZINHERITTYPEANNOTATIONSFROMTEMPLATEARGS => { - "MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS" - } + Cpp::MOZINHERITTYPEANNOTATIONSFROMTEMPLATEARGS => "MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS", Cpp::MOZINITOUTSIDECTOR => "MOZ_INIT_OUTSIDE_CTOR", Cpp::MOZISCLASSINIT => "MOZ_IS_CLASS_INIT", Cpp::MOZISREFPTR => "MOZ_IS_REFPTR", @@ -941,17 +940,11 @@ impl From for &'static str { Cpp::MOZNODANGLINGONTEMPORARIES => "MOZ_NO_DANGLING_ON_TEMPORARIES", Cpp::MOZNOSANITIZESIGNEDOVERFLOW => "MOZ_NO_SANITIZE_SIGNED_OVERFLOW", Cpp::MOZNOSANITIZEUNSIGNEDOVERFLOW => "MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW", - Cpp::MOZONLYUSEDTOAVOIDSTATICCONSTRUCTORS => { - "MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS" - } + Cpp::MOZONLYUSEDTOAVOIDSTATICCONSTRUCTORS => "MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS", Cpp::MOZOWNINGREF => "MOZ_OWNING_REF", - Cpp::MOZPOPDISABLENONTRIVIALUNIONWARNINGS => { - "MOZ_POP_DISABLE_NONTRIVIAL_UNION_WARNINGS" - } + Cpp::MOZPOPDISABLENONTRIVIALUNIONWARNINGS => "MOZ_POP_DISABLE_NONTRIVIAL_UNION_WARNINGS", Cpp::MOZPRETENDNORETURNFORSTATICANALYSIS => "MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS", - Cpp::MOZPUSHDISABLENONTRIVIALUNIONWARNINGS => { - "MOZ_PUSH_DISABLE_NONTRIVIAL_UNION_WARNINGS" - } + Cpp::MOZPUSHDISABLENONTRIVIALUNIONWARNINGS => "MOZ_PUSH_DISABLE_NONTRIVIAL_UNION_WARNINGS", Cpp::MOZRAII => "MOZ_RAII", Cpp::MOZREQUIREDBASEMETHOD => "MOZ_REQUIRED_BASE_METHOD", Cpp::MOZSTACKCLASS => "MOZ_STACK_CLASS", @@ -1243,13 +1236,9 @@ impl From for &'static str { Cpp::TranslationUnitRepeat1 => "translation_unit_repeat1", Cpp::PreprocParamsRepeat1 => "preproc_params_repeat1", Cpp::PreprocIfRepeat1 => "preproc_if_repeat1", - Cpp::PreprocIfInFieldDeclarationListRepeat1 => { - "preproc_if_in_field_declaration_list_repeat1" - } + Cpp::PreprocIfInFieldDeclarationListRepeat1 => "preproc_if_in_field_declaration_list_repeat1", Cpp::PreprocIfInEnumeratorListRepeat1 => "preproc_if_in_enumerator_list_repeat1", - Cpp::PreprocIfInEnumeratorListNoCommaRepeat1 => { - "preproc_if_in_enumerator_list_no_comma_repeat1" - } + Cpp::PreprocIfInEnumeratorListNoCommaRepeat1 => "preproc_if_in_enumerator_list_no_comma_repeat1", Cpp::PreprocArgumentListRepeat1 => "preproc_argument_list_repeat1", Cpp::DeclarationRepeat1 => "declaration_repeat1", Cpp::TypeDefinitionRepeat1 => "type_definition_repeat1", @@ -1300,6 +1289,7 @@ impl From for &'static str { Cpp::StatementIdentifier => "statement_identifier", Cpp::TypeIdentifier => "type_identifier", Cpp::Error => "ERROR", + } } } diff --git a/src/languages/language_java.rs b/src/languages/language_java.rs index ac526e5a5..e1c4279ad 100644 --- a/src/languages/language_java.rs +++ b/src/languages/language_java.rs @@ -326,6 +326,7 @@ pub enum Java { ReceiverParameterRepeat1 = 319, TypeIdentifier = 320, Error = 321, + } impl From for &'static str { @@ -654,6 +655,7 @@ impl From for &'static str { Java::ReceiverParameterRepeat1 => "receiver_parameter_repeat1", Java::TypeIdentifier => "type_identifier", Java::Error => "ERROR", + } } } diff --git a/src/languages/language_javascript.rs b/src/languages/language_javascript.rs index 6dbb96069..6d76a6865 100644 --- a/src/languages/language_javascript.rs +++ b/src/languages/language_javascript.rs @@ -20,254 +20,257 @@ pub enum Javascript { Var = 13, Let = 14, Const = 15, - Else = 16, - If = 17, - Switch = 18, - For = 19, - LPAREN = 20, - SEMI = 21, - RPAREN = 22, - Await = 23, - In = 24, - Of = 25, - While = 26, - Do = 27, - Try = 28, - Break = 29, - Continue = 30, - Debugger = 31, - Return = 32, - Throw = 33, - COLON = 34, - Case = 35, - Catch = 36, - Finally = 37, - Yield = 38, - EQ = 39, - LBRACK = 40, - RBRACK = 41, - HtmlCharacterReference = 42, - LT = 43, - GT = 44, - Identifier2 = 45, - DOT = 46, - LTSLASH = 47, - SLASHGT = 48, - DQUOTE = 49, - SQUOTE = 50, - StringFragment = 51, - StringFragment2 = 52, - Class2 = 53, - Extends = 54, - Async = 55, - Function = 56, - EQGT = 57, - OptionalChain = 58, - New = 59, - PLUSEQ = 60, - DASHEQ = 61, - STAREQ = 62, - SLASHEQ = 63, - PERCENTEQ = 64, - CARETEQ = 65, - AMPEQ = 66, - PIPEEQ = 67, - GTGTEQ = 68, - GTGTGTEQ = 69, - LTLTEQ = 70, - STARSTAREQ = 71, - AMPAMPEQ = 72, - PIPEPIPEEQ = 73, - QMARKQMARKEQ = 74, - DOTDOTDOT = 75, - AMPAMP = 76, - PIPEPIPE = 77, - GTGT = 78, - GTGTGT = 79, - LTLT = 80, - AMP = 81, - CARET = 82, - PIPE = 83, - PLUS = 84, - DASH = 85, - SLASH = 86, - PERCENT = 87, - STARSTAR = 88, - LTEQ = 89, - EQEQ = 90, - EQEQEQ = 91, - BANGEQ = 92, - BANGEQEQ = 93, - GTEQ = 94, - QMARKQMARK = 95, - Instanceof = 96, - BANG = 97, - TILDE = 98, - Typeof = 99, - Void = 100, - Delete = 101, - PLUSPLUS = 102, - DASHDASH = 103, - StringFragment3 = 104, - StringFragment4 = 105, - EscapeSequence = 106, - Comment = 107, - BQUOTE = 108, - DOLLARLBRACE = 109, - SLASH2 = 110, - RegexPattern = 111, - RegexFlags = 112, - Number = 113, - PrivatePropertyIdentifier = 114, - Target = 115, - Meta = 116, - This = 117, - Super = 118, - True = 119, - False = 120, - Null = 121, - Undefined = 122, - AT = 123, - Static = 124, - Staticget = 125, - Get = 126, - Set = 127, - AutomaticSemicolon = 128, - StringFragment5 = 129, - QMARK = 130, - HtmlComment = 131, - JsxText = 132, - Program = 133, - ExportStatement = 134, - NamespaceExport = 135, - ExportClause = 136, - ExportSpecifier = 137, - ModuleExportName = 138, - Declaration = 139, - Import = 140, - ImportStatement = 141, - ImportClause = 142, - FromClause = 143, - NamespaceImport = 144, - NamedImports = 145, - ImportSpecifier = 146, - ImportAttribute = 147, - Statement = 148, - ExpressionStatement = 149, - VariableDeclaration = 150, - LexicalDeclaration = 151, - VariableDeclarator = 152, - StatementBlock = 153, - ElseClause = 154, - IfStatement = 155, - SwitchStatement = 156, - ForStatement = 157, - ForInStatement = 158, - ForHeader = 159, - WhileStatement = 160, - DoStatement = 161, - TryStatement = 162, - WithStatement = 163, - BreakStatement = 164, - ContinueStatement = 165, - DebuggerStatement = 166, - ReturnStatement = 167, - ThrowStatement = 168, - EmptyStatement = 169, - LabeledStatement = 170, - SwitchBody = 171, - SwitchCase = 172, - SwitchDefault = 173, - CatchClause = 174, - FinallyClause = 175, - ParenthesizedExpression = 176, - Expression = 177, - PrimaryExpression = 178, - YieldExpression = 179, - Object = 180, - ObjectPattern = 181, - AssignmentPattern = 182, - ObjectAssignmentPattern = 183, - Array = 184, - ArrayPattern = 185, - JsxElement = 186, - JsxExpression = 187, - JsxOpeningElement = 188, - MemberExpression = 189, - JsxNamespaceName = 190, - JsxClosingElement = 191, - JsxSelfClosingElement = 192, - JsxAttribute = 193, - String = 194, - Class = 195, - ClassDeclaration = 196, - ClassHeritage = 197, - FunctionExpression = 198, - FunctionDeclaration = 199, - GeneratorFunction = 200, - GeneratorFunctionDeclaration = 201, - ArrowFunction = 202, - CallExpression = 203, - NewExpression = 204, - AwaitExpression = 205, - MemberExpression2 = 206, - SubscriptExpression = 207, - AssignmentExpression = 208, - AugmentedAssignmentLhs = 209, - AugmentedAssignmentExpression = 210, - Initializer = 211, - DestructuringPattern = 212, - SpreadElement = 213, - TernaryExpression = 214, - BinaryExpression = 215, - UnaryExpression = 216, - UpdateExpression = 217, - SequenceExpression = 218, - String2 = 219, - TemplateString = 220, - TemplateSubstitution = 221, - Regex = 222, - MetaProperty = 223, - Arguments = 224, - Decorator = 225, - MemberExpression3 = 226, - CallExpression2 = 227, - ClassBody = 228, - FieldDefinition = 229, - FormalParameters = 230, - ClassStaticBlock = 231, - Pattern = 232, - RestPattern = 233, - MethodDefinition = 234, - Pair = 235, - PairPattern = 236, - PropertyName = 237, - ComputedPropertyName = 238, - ProgramRepeat1 = 239, - ExportStatementRepeat1 = 240, - ExportClauseRepeat1 = 241, - NamedImportsRepeat1 = 242, - VariableDeclarationRepeat1 = 243, - SwitchBodyRepeat1 = 244, - ObjectRepeat1 = 245, - ObjectPatternRepeat1 = 246, - ArrayRepeat1 = 247, - ArrayPatternRepeat1 = 248, - JsxElementRepeat1 = 249, - JsxOpeningElementRepeat1 = 250, - JsxStringRepeat1 = 251, - JsxStringRepeat2 = 252, - SequenceExpressionRepeat1 = 253, - StringRepeat1 = 254, - StringRepeat2 = 255, - TemplateStringRepeat1 = 256, - ClassBodyRepeat1 = 257, - FormalParametersRepeat1 = 258, - PropertyIdentifier = 259, - ShorthandPropertyIdentifier = 260, - ShorthandPropertyIdentifierPattern = 261, - StatementIdentifier = 262, - Error = 263, + Using = 16, + Await = 17, + Of = 18, + Else = 19, + If = 20, + Switch = 21, + For = 22, + LPAREN = 23, + SEMI = 24, + RPAREN = 25, + In = 26, + While = 27, + Do = 28, + Try = 29, + Break = 30, + Continue = 31, + Debugger = 32, + Return = 33, + Throw = 34, + COLON = 35, + Case = 36, + Catch = 37, + Finally = 38, + Yield = 39, + EQ = 40, + LBRACK = 41, + RBRACK = 42, + HtmlCharacterReference = 43, + LT = 44, + GT = 45, + Identifier2 = 46, + DOT = 47, + LTSLASH = 48, + SLASHGT = 49, + DQUOTE = 50, + SQUOTE = 51, + StringFragment = 52, + StringFragment2 = 53, + Class2 = 54, + Extends = 55, + Async = 56, + Function = 57, + EQGT = 58, + OptionalChain = 59, + New = 60, + PLUSEQ = 61, + DASHEQ = 62, + STAREQ = 63, + SLASHEQ = 64, + PERCENTEQ = 65, + CARETEQ = 66, + AMPEQ = 67, + PIPEEQ = 68, + GTGTEQ = 69, + GTGTGTEQ = 70, + LTLTEQ = 71, + STARSTAREQ = 72, + AMPAMPEQ = 73, + PIPEPIPEEQ = 74, + QMARKQMARKEQ = 75, + DOTDOTDOT = 76, + AMPAMP = 77, + PIPEPIPE = 78, + GTGT = 79, + GTGTGT = 80, + LTLT = 81, + AMP = 82, + CARET = 83, + PIPE = 84, + PLUS = 85, + DASH = 86, + SLASH = 87, + PERCENT = 88, + STARSTAR = 89, + LTEQ = 90, + EQEQ = 91, + EQEQEQ = 92, + BANGEQ = 93, + BANGEQEQ = 94, + GTEQ = 95, + QMARKQMARK = 96, + Instanceof = 97, + BANG = 98, + TILDE = 99, + Typeof = 100, + Void = 101, + Delete = 102, + PLUSPLUS = 103, + DASHDASH = 104, + StringFragment3 = 105, + StringFragment4 = 106, + EscapeSequence = 107, + Comment = 108, + BQUOTE = 109, + DOLLARLBRACE = 110, + SLASH2 = 111, + RegexPattern = 112, + RegexFlags = 113, + Number = 114, + PrivatePropertyIdentifier = 115, + Target = 116, + Meta = 117, + This = 118, + Super = 119, + True = 120, + False = 121, + Null = 122, + Undefined = 123, + AT = 124, + Static = 125, + Staticget = 126, + Get = 127, + Set = 128, + AutomaticSemicolon = 129, + StringFragment5 = 130, + QMARK = 131, + HtmlComment = 132, + JsxText = 133, + Program = 134, + ExportStatement = 135, + NamespaceExport = 136, + ExportClause = 137, + ExportSpecifier = 138, + ModuleExportName = 139, + Declaration = 140, + Import = 141, + ImportStatement = 142, + ImportClause = 143, + FromClause = 144, + NamespaceImport = 145, + NamedImports = 146, + ImportSpecifier = 147, + ImportAttribute = 148, + Statement = 149, + ExpressionStatement = 150, + VariableDeclaration = 151, + LexicalDeclaration = 152, + UsingDeclaration = 153, + VariableDeclarator = 154, + StatementBlock = 155, + ElseClause = 156, + IfStatement = 157, + SwitchStatement = 158, + ForStatement = 159, + ForInStatement = 160, + ForHeader = 161, + WhileStatement = 162, + DoStatement = 163, + TryStatement = 164, + WithStatement = 165, + BreakStatement = 166, + ContinueStatement = 167, + DebuggerStatement = 168, + ReturnStatement = 169, + ThrowStatement = 170, + EmptyStatement = 171, + LabeledStatement = 172, + SwitchBody = 173, + SwitchCase = 174, + SwitchDefault = 175, + CatchClause = 176, + FinallyClause = 177, + ParenthesizedExpression = 178, + Expression = 179, + PrimaryExpression = 180, + YieldExpression = 181, + Object = 182, + ObjectPattern = 183, + AssignmentPattern = 184, + ObjectAssignmentPattern = 185, + Array = 186, + ArrayPattern = 187, + JsxElement = 188, + JsxExpression = 189, + JsxOpeningElement = 190, + MemberExpression = 191, + JsxNamespaceName = 192, + JsxClosingElement = 193, + JsxSelfClosingElement = 194, + JsxAttribute = 195, + String = 196, + Class = 197, + ClassDeclaration = 198, + ClassHeritage = 199, + FunctionExpression = 200, + FunctionDeclaration = 201, + GeneratorFunction = 202, + GeneratorFunctionDeclaration = 203, + ArrowFunction = 204, + CallExpression = 205, + NewExpression = 206, + AwaitExpression = 207, + MemberExpression2 = 208, + SubscriptExpression = 209, + AssignmentExpression = 210, + AugmentedAssignmentLhs = 211, + AugmentedAssignmentExpression = 212, + Initializer = 213, + DestructuringPattern = 214, + SpreadElement = 215, + TernaryExpression = 216, + BinaryExpression = 217, + UnaryExpression = 218, + UpdateExpression = 219, + SequenceExpression = 220, + String2 = 221, + TemplateString = 222, + TemplateSubstitution = 223, + Regex = 224, + MetaProperty = 225, + Arguments = 226, + Decorator = 227, + MemberExpression3 = 228, + CallExpression2 = 229, + ClassBody = 230, + FieldDefinition = 231, + FormalParameters = 232, + ClassStaticBlock = 233, + Pattern = 234, + RestPattern = 235, + MethodDefinition = 236, + Pair = 237, + PairPattern = 238, + PropertyName = 239, + ComputedPropertyName = 240, + ProgramRepeat1 = 241, + ExportStatementRepeat1 = 242, + ExportClauseRepeat1 = 243, + NamedImportsRepeat1 = 244, + VariableDeclarationRepeat1 = 245, + SwitchBodyRepeat1 = 246, + ObjectRepeat1 = 247, + ObjectPatternRepeat1 = 248, + ArrayRepeat1 = 249, + ArrayPatternRepeat1 = 250, + JsxElementRepeat1 = 251, + JsxOpeningElementRepeat1 = 252, + JsxStringRepeat1 = 253, + JsxStringRepeat2 = 254, + SequenceExpressionRepeat1 = 255, + StringRepeat1 = 256, + StringRepeat2 = 257, + TemplateStringRepeat1 = 258, + ClassBodyRepeat1 = 259, + FormalParametersRepeat1 = 260, + PropertyIdentifier = 261, + ShorthandPropertyIdentifier = 262, + ShorthandPropertyIdentifierPattern = 263, + StatementIdentifier = 264, + Error = 265, + } impl From for &'static str { @@ -290,6 +293,9 @@ impl From for &'static str { Javascript::Var => "var", Javascript::Let => "let", Javascript::Const => "const", + Javascript::Using => "using", + Javascript::Await => "await", + Javascript::Of => "of", Javascript::Else => "else", Javascript::If => "if", Javascript::Switch => "switch", @@ -297,9 +303,7 @@ impl From for &'static str { Javascript::LPAREN => "(", Javascript::SEMI => ";", Javascript::RPAREN => ")", - Javascript::Await => "await", Javascript::In => "in", - Javascript::Of => "of", Javascript::While => "while", Javascript::Do => "do", Javascript::Try => "try", @@ -426,6 +430,7 @@ impl From for &'static str { Javascript::ExpressionStatement => "expression_statement", Javascript::VariableDeclaration => "variable_declaration", Javascript::LexicalDeclaration => "lexical_declaration", + Javascript::UsingDeclaration => "using_declaration", Javascript::VariableDeclarator => "variable_declarator", Javascript::StatementBlock => "statement_block", Javascript::ElseClause => "else_clause", @@ -535,11 +540,10 @@ impl From for &'static str { Javascript::FormalParametersRepeat1 => "formal_parameters_repeat1", Javascript::PropertyIdentifier => "property_identifier", Javascript::ShorthandPropertyIdentifier => "shorthand_property_identifier", - Javascript::ShorthandPropertyIdentifierPattern => { - "shorthand_property_identifier_pattern" - } + Javascript::ShorthandPropertyIdentifierPattern => "shorthand_property_identifier_pattern", Javascript::StatementIdentifier => "statement_identifier", Javascript::Error => "ERROR", + } } } diff --git a/src/languages/language_kotlin.rs b/src/languages/language_kotlin.rs index 9e01c2932..befab31a7 100644 --- a/src/languages/language_kotlin.rs +++ b/src/languages/language_kotlin.rs @@ -365,6 +365,7 @@ pub enum Kotlin { InterpolatedIdentifier = 358, TypeIdentifier = 359, Error = 360, + } impl From for &'static str { @@ -702,9 +703,7 @@ impl From for &'static str { Kotlin::ImportListRepeat1 => "import_list_repeat1", Kotlin::ClassParametersRepeat1 => "_class_parameters_repeat1", Kotlin::DelegationSpecifiersRepeat1 => "_delegation_specifiers_repeat1", - Kotlin::AnnotatedDelegationSpecifierRepeat1 => { - "_annotated_delegation_specifier_repeat1" - } + Kotlin::AnnotatedDelegationSpecifierRepeat1 => "_annotated_delegation_specifier_repeat1", Kotlin::TypeParametersRepeat1 => "type_parameters_repeat1", Kotlin::TypeConstraintsRepeat1 => "type_constraints_repeat1", Kotlin::FunctionValueParametersRepeat1 => "function_value_parameters_repeat1", @@ -734,6 +733,7 @@ impl From for &'static str { Kotlin::InterpolatedIdentifier => "interpolated_identifier", Kotlin::TypeIdentifier => "type_identifier", Kotlin::Error => "ERROR", + } } } diff --git a/src/languages/language_mozjs.rs b/src/languages/language_mozjs.rs index 5187924ca..827ba2977 100644 --- a/src/languages/language_mozjs.rs +++ b/src/languages/language_mozjs.rs @@ -269,6 +269,7 @@ pub enum Mozjs { ShorthandPropertyIdentifierPattern = 262, StatementIdentifier = 263, Error = 264, + } impl From for &'static str { @@ -540,6 +541,7 @@ impl From for &'static str { Mozjs::ShorthandPropertyIdentifierPattern => "shorthand_property_identifier_pattern", Mozjs::StatementIdentifier => "statement_identifier", Mozjs::Error => "ERROR", + } } } diff --git a/src/languages/language_preproc.rs b/src/languages/language_preproc.rs index 6bd5faa8c..34f4c6395 100644 --- a/src/languages/language_preproc.rs +++ b/src/languages/language_preproc.rs @@ -41,6 +41,7 @@ pub enum Preproc { DefineRepeat1 = 34, PreprocIfRepeat1 = 35, Error = 36, + } impl From for &'static str { @@ -84,6 +85,7 @@ impl From for &'static str { Preproc::DefineRepeat1 => "define_repeat1", Preproc::PreprocIfRepeat1 => "preproc_if_repeat1", Preproc::Error => "ERROR", + } } } diff --git a/src/languages/language_python.rs b/src/languages/language_python.rs index 1d12c16d1..d188fd508 100644 --- a/src/languages/language_python.rs +++ b/src/languages/language_python.rs @@ -38,7 +38,7 @@ pub enum Python { While = 31, Try = 32, Except = 33, - ExceptSTAR = 34, + STAR2 = 34, Finally = 35, With = 36, Def = 37, @@ -145,141 +145,141 @@ pub enum Python { WhileStatement = 138, TryStatement = 139, ExceptClause = 140, - ExceptGroupClause = 141, - FinallyClause = 142, - WithStatement = 143, - WithClause = 144, - WithItem = 145, - FunctionDefinition = 146, - Parameters = 147, - LambdaParameters = 148, - ListSplat = 149, - DictionarySplat = 150, - GlobalStatement = 151, - NonlocalStatement = 152, - ExecStatement = 153, - TypeAliasStatement = 154, - ClassDefinition = 155, - TypeParameter = 156, - ParenthesizedListSplat = 157, - ArgumentList = 158, - DecoratedDefinition = 159, - Decorator = 160, - Block2 = 161, - ExpressionList = 162, - DottedName = 163, - CasePattern = 164, - SimplePattern = 165, - AsPattern = 166, - UnionPattern = 167, - ListPattern = 168, - TuplePattern = 169, - DictPattern = 170, - KeyValuePattern = 171, - KeywordPattern = 172, - SplatPattern = 173, - ClassPattern = 174, - ComplexPattern = 175, - Parameters2 = 176, - Patterns = 177, - Parameter = 178, - Pattern = 179, - TuplePattern2 = 180, - ListPattern2 = 181, - DefaultParameter = 182, - TypedDefaultParameter = 183, - ListSplatPattern = 184, - DictionarySplatPattern = 185, - AsPattern2 = 186, - ExpressionWithinForInClause = 187, - Expression = 188, - PrimaryExpression = 189, - NotOperator = 190, - BooleanOperator = 191, - BinaryOperator = 192, - UnaryOperator = 193, - Notin = 194, - Isnot = 195, - ComparisonOperator = 196, - Lambda = 197, - Lambda2 = 198, - Assignment = 199, - AugmentedAssignment = 200, - PatternList = 201, - RightHandSide = 202, - Yield = 203, - Attribute = 204, - Subscript = 205, - Slice = 206, - Call = 207, - TypedParameter = 208, - Type = 209, - SplatType = 210, - GenericType = 211, - UnionType = 212, - ConstrainedType = 213, - MemberType = 214, - KeywordArgument = 215, - List = 216, - Set = 217, - Tuple = 218, - Dictionary = 219, - Pair = 220, - ListComprehension = 221, - DictionaryComprehension = 222, - SetComprehension = 223, - GeneratorExpression = 224, - ComprehensionClauses = 225, - ParenthesizedExpression = 226, - CollectionElements = 227, - ForInClause = 228, - IfClause = 229, - ConditionalExpression = 230, - ConcatenatedString = 231, - String = 232, - StringContent = 233, - Interpolation = 234, - FExpression = 235, - NotEscapeSequence = 236, - FormatSpecifier = 237, - Await = 238, - PositionalSeparator = 239, - KeywordSeparator = 240, - ModuleRepeat1 = 241, - SimpleStatementsRepeat1 = 242, - ImportPrefixRepeat1 = 243, - ImportListRepeat1 = 244, - PrintStatementRepeat1 = 245, - AssertStatementRepeat1 = 246, - IfStatementRepeat1 = 247, - MatchStatementRepeat1 = 248, - MatchBlockRepeat1 = 249, - CaseClauseRepeat1 = 250, - TryStatementRepeat1 = 251, - TryStatementRepeat2 = 252, - WithClauseRepeat1 = 253, - GlobalStatementRepeat1 = 254, - TypeParameterRepeat1 = 255, - ArgumentListRepeat1 = 256, - DecoratedDefinitionRepeat1 = 257, - DottedNameRepeat1 = 258, - UnionPatternRepeat1 = 259, - DictPatternRepeat1 = 260, - ParametersRepeat1 = 261, - PatternsRepeat1 = 262, - ComparisonOperatorRepeat1 = 263, - SubscriptRepeat1 = 264, - DictionaryRepeat1 = 265, - ComprehensionClausesRepeat1 = 266, - CollectionElementsRepeat1 = 267, - ForInClauseRepeat1 = 268, - ConcatenatedStringRepeat1 = 269, - StringRepeat1 = 270, - StringContentRepeat1 = 271, - FormatSpecifierRepeat1 = 272, - AsPatternTarget = 273, - FormatExpression = 274, - Error = 275, + FinallyClause = 141, + WithStatement = 142, + WithClause = 143, + WithItem = 144, + FunctionDefinition = 145, + Parameters = 146, + LambdaParameters = 147, + ListSplat = 148, + DictionarySplat = 149, + GlobalStatement = 150, + NonlocalStatement = 151, + ExecStatement = 152, + TypeAliasStatement = 153, + ClassDefinition = 154, + TypeParameter = 155, + ParenthesizedListSplat = 156, + ArgumentList = 157, + DecoratedDefinition = 158, + Decorator = 159, + Block2 = 160, + ExpressionList = 161, + DottedName = 162, + CasePattern = 163, + SimplePattern = 164, + AsPattern = 165, + UnionPattern = 166, + ListPattern = 167, + TuplePattern = 168, + DictPattern = 169, + KeyValuePattern = 170, + KeywordPattern = 171, + SplatPattern = 172, + ClassPattern = 173, + ComplexPattern = 174, + Parameters2 = 175, + Patterns = 176, + Parameter = 177, + Pattern = 178, + TuplePattern2 = 179, + ListPattern2 = 180, + DefaultParameter = 181, + TypedDefaultParameter = 182, + ListSplatPattern = 183, + DictionarySplatPattern = 184, + AsPattern2 = 185, + ExpressionWithinForInClause = 186, + Expression = 187, + PrimaryExpression = 188, + NotOperator = 189, + BooleanOperator = 190, + BinaryOperator = 191, + UnaryOperator = 192, + Notin = 193, + Isnot = 194, + ComparisonOperator = 195, + Lambda = 196, + Lambda2 = 197, + Assignment = 198, + AugmentedAssignment = 199, + PatternList = 200, + RightHandSide = 201, + Yield = 202, + Attribute = 203, + Subscript = 204, + Slice = 205, + Call = 206, + TypedParameter = 207, + Type = 208, + SplatType = 209, + GenericType = 210, + UnionType = 211, + ConstrainedType = 212, + MemberType = 213, + KeywordArgument = 214, + List = 215, + Set = 216, + Tuple = 217, + Dictionary = 218, + Pair = 219, + ListComprehension = 220, + DictionaryComprehension = 221, + SetComprehension = 222, + GeneratorExpression = 223, + ComprehensionClauses = 224, + ParenthesizedExpression = 225, + CollectionElements = 226, + ForInClause = 227, + IfClause = 228, + ConditionalExpression = 229, + ConcatenatedString = 230, + String = 231, + StringContent = 232, + Interpolation = 233, + FExpression = 234, + NotEscapeSequence = 235, + FormatSpecifier = 236, + Await = 237, + PositionalSeparator = 238, + KeywordSeparator = 239, + ModuleRepeat1 = 240, + SimpleStatementsRepeat1 = 241, + ImportPrefixRepeat1 = 242, + ImportListRepeat1 = 243, + PrintStatementRepeat1 = 244, + AssertStatementRepeat1 = 245, + IfStatementRepeat1 = 246, + MatchStatementRepeat1 = 247, + MatchBlockRepeat1 = 248, + CaseClauseRepeat1 = 249, + TryStatementRepeat1 = 250, + ExceptClauseRepeat1 = 251, + WithClauseRepeat1 = 252, + GlobalStatementRepeat1 = 253, + TypeParameterRepeat1 = 254, + ArgumentListRepeat1 = 255, + DecoratedDefinitionRepeat1 = 256, + DottedNameRepeat1 = 257, + UnionPatternRepeat1 = 258, + DictPatternRepeat1 = 259, + ParametersRepeat1 = 260, + PatternsRepeat1 = 261, + ComparisonOperatorRepeat1 = 262, + SubscriptRepeat1 = 263, + DictionaryRepeat1 = 264, + ComprehensionClausesRepeat1 = 265, + CollectionElementsRepeat1 = 266, + ForInClauseRepeat1 = 267, + ConcatenatedStringRepeat1 = 268, + StringRepeat1 = 269, + StringContentRepeat1 = 270, + FormatSpecifierRepeat1 = 271, + AsPatternTarget = 272, + FormatExpression = 273, + Error = 274, + } impl From for &'static str { @@ -320,7 +320,7 @@ impl From for &'static str { Python::While => "while", Python::Try => "try", Python::Except => "except", - Python::ExceptSTAR => "except*", + Python::STAR2 => "*", Python::Finally => "finally", Python::With => "with", Python::Def => "def", @@ -427,7 +427,6 @@ impl From for &'static str { Python::WhileStatement => "while_statement", Python::TryStatement => "try_statement", Python::ExceptClause => "except_clause", - Python::ExceptGroupClause => "except_group_clause", Python::FinallyClause => "finally_clause", Python::WithStatement => "with_statement", Python::WithClause => "with_clause", @@ -538,7 +537,7 @@ impl From for &'static str { Python::MatchBlockRepeat1 => "_match_block_repeat1", Python::CaseClauseRepeat1 => "case_clause_repeat1", Python::TryStatementRepeat1 => "try_statement_repeat1", - Python::TryStatementRepeat2 => "try_statement_repeat2", + Python::ExceptClauseRepeat1 => "except_clause_repeat1", Python::WithClauseRepeat1 => "with_clause_repeat1", Python::GlobalStatementRepeat1 => "global_statement_repeat1", Python::TypeParameterRepeat1 => "type_parameter_repeat1", @@ -562,6 +561,7 @@ impl From for &'static str { Python::AsPatternTarget => "as_pattern_target", Python::FormatExpression => "format_expression", Python::Error => "ERROR", + } } } diff --git a/src/languages/language_rust.rs b/src/languages/language_rust.rs index e9b9f8e9a..19f16f47d 100644 --- a/src/languages/language_rust.rs +++ b/src/languages/language_rust.rs @@ -23,338 +23,344 @@ pub enum Rust { QMARK = 16, Block2 = 17, Expr = 18, - Ident = 19, - Item = 20, - Lifetime2 = 21, - Literal = 22, - Meta = 23, - Pat = 24, - Path = 25, - Stmt = 26, - Tt = 27, - Ty = 28, - Vis = 29, - PrimitiveType = 30, - PrimitiveType2 = 31, - PrimitiveType3 = 32, - PrimitiveType4 = 33, - PrimitiveType5 = 34, - PrimitiveType6 = 35, - PrimitiveType7 = 36, - PrimitiveType8 = 37, - PrimitiveType9 = 38, - PrimitiveType10 = 39, - PrimitiveType11 = 40, - PrimitiveType12 = 41, - PrimitiveType13 = 42, - PrimitiveType14 = 43, - PrimitiveType15 = 44, - PrimitiveType16 = 45, - PrimitiveType17 = 46, - DASH = 47, - SLASH = 48, - PERCENT = 49, - CARET = 50, - BANG = 51, - AMP = 52, - PIPE = 53, - AMPAMP = 54, - PIPEPIPE = 55, - LTLT = 56, - GTGT = 57, - PLUSEQ = 58, - DASHEQ = 59, - STAREQ = 60, - SLASHEQ = 61, - PERCENTEQ = 62, - CARETEQ = 63, - AMPEQ = 64, - PIPEEQ = 65, - LTLTEQ = 66, - GTGTEQ = 67, - EQ = 68, - EQEQ = 69, - BANGEQ = 70, - GT = 71, - LT = 72, - GTEQ = 73, - LTEQ = 74, - AT = 75, - UNDERSCORE = 76, - DOT = 77, - DOTDOT = 78, - DOTDOTDOT = 79, - DOTDOTEQ = 80, - COMMA = 81, - COLONCOLON = 82, - DASHGT = 83, - HASH = 84, - SQUOTE = 85, - As = 86, - Async = 87, - Await = 88, - Break = 89, - Const = 90, - Continue = 91, - Default = 92, - Enum = 93, - Fn = 94, - For = 95, - Gen = 96, - If = 97, - Impl = 98, - Let = 99, - Loop = 100, - Match = 101, - Mod = 102, - Pub = 103, - Return = 104, - Static = 105, - Struct = 106, - Trait = 107, - Type = 108, - Union = 109, - Unsafe = 110, - Use = 111, - Where = 112, - While = 113, - Extern = 114, - Ref = 115, - Else = 116, - In = 117, - LT2 = 118, - Dyn = 119, - MutableSpecifier = 120, - Raw = 121, - Yield = 122, - Move = 123, - Try = 124, - IntegerLiteral = 125, - DQUOTE = 126, - DQUOTE2 = 127, - CharLiteral = 128, - EscapeSequence = 129, - True = 130, - False = 131, - SLASHSLASH = 132, - LineCommentToken1 = 133, - LineCommentToken2 = 134, - LineCommentToken3 = 135, - BANG2 = 136, - SLASH2 = 137, - SLASHSTAR = 138, - STARSLASH = 139, - Shebang = 140, - Zelf = 141, - Super = 142, - Crate = 143, - Metavariable = 144, - StringContent = 145, - RawStringLiteralStart = 146, - StringContent2 = 147, - RawStringLiteralEnd = 148, - FloatLiteral = 149, - OuterDocCommentMarker = 150, - InnerDocCommentMarker = 151, - BlockCommentContent = 152, - DocComment = 153, - ErrorSentinel = 154, - SourceFile = 155, - Statement = 156, - EmptyStatement = 157, - ExpressionStatement = 158, - MacroDefinition = 159, - MacroRule = 160, - TokenPattern = 161, - TokenTreePattern = 162, - TokenBindingPattern = 163, - TokenRepetitionPattern = 164, - FragmentSpecifier = 165, - TokenTree = 166, - TokenRepetition = 167, - AttributeItem = 168, - InnerAttributeItem = 169, - Attribute = 170, - ModItem = 171, - ForeignModItem = 172, - DeclarationList = 173, - StructItem = 174, - UnionItem = 175, - EnumItem = 176, - EnumVariantList = 177, - EnumVariant = 178, - FieldDeclarationList = 179, - FieldDeclaration = 180, - OrderedFieldDeclarationList = 181, - ExternCrateDeclaration = 182, - ConstItem = 183, - StaticItem = 184, - TypeItem = 185, - FunctionItem = 186, - FunctionSignatureItem = 187, - FunctionModifiers = 188, - WhereClause = 189, - WherePredicate = 190, - ImplItem = 191, - TraitItem = 192, - AssociatedType = 193, - TraitBounds = 194, - HigherRankedTraitBound = 195, - RemovedTraitBound = 196, - TypeParameters = 197, - ConstParameter = 198, - ConstrainedTypeParameter = 199, - OptionalTypeParameter = 200, - LetDeclaration = 201, - UseDeclaration = 202, - UseClause = 203, - ScopedUseList = 204, - UseList = 205, - UseAsClause = 206, - UseWildcard = 207, - Parameters = 208, - SelfParameter = 209, - VariadicParameter = 210, - Parameter = 211, - ExternModifier = 212, - VisibilityModifier = 213, - Type2 = 214, - BracketedType = 215, - QualifiedType = 216, - Lifetime = 217, - ArrayType = 218, - ForLifetimes = 219, - FunctionType = 220, - TupleType = 221, - UnitType = 222, - GenericFunction = 223, - GenericType = 224, - GenericTypeWithTurbofish = 225, - BoundedType = 226, - TypeArguments = 227, - TypeBinding = 228, - ReferenceType = 229, - PointerType = 230, - NeverType = 231, - AbstractType = 232, - DynamicType = 233, - ExpressionExceptRange = 234, - Expression = 235, - MacroInvocation = 236, - TokenTree2 = 237, - DelimTokens = 238, - NonDelimToken = 239, - ScopedIdentifier = 240, - ScopedTypeIdentifier = 241, - ScopedTypeIdentifier2 = 242, - RangeExpression = 243, - UnaryExpression = 244, - TryExpression = 245, - ReferenceExpression = 246, - BinaryExpression = 247, - AssignmentExpression = 248, - CompoundAssignmentExpr = 249, - TypeCastExpression = 250, - ReturnExpression = 251, - YieldExpression = 252, - CallExpression = 253, - Arguments = 254, - ArrayExpression = 255, - ParenthesizedExpression = 256, - TupleExpression = 257, - UnitExpression = 258, - StructExpression = 259, - FieldInitializerList = 260, - ShorthandFieldInitializer = 261, - FieldInitializer = 262, - BaseFieldInitializer = 263, - IfExpression = 264, - LetCondition = 265, - LetChain2 = 266, - Condition = 267, - ElseClause = 268, - MatchExpression = 269, - MatchBlock = 270, - MatchArm = 271, - MatchArm2 = 272, - MatchPattern = 273, - WhileExpression = 274, - LoopExpression = 275, - ForExpression = 276, - ConstBlock = 277, - ClosureExpression = 278, - ClosureParameters = 279, - Label = 280, - BreakExpression = 281, - ContinueExpression = 282, - IndexExpression = 283, - AwaitExpression = 284, - FieldExpression = 285, - UnsafeBlock = 286, - AsyncBlock = 287, - GenBlock = 288, - TryBlock = 289, - Block = 290, - Pattern = 291, - TuplePattern = 292, - SlicePattern = 293, - TupleStructPattern = 294, - StructPattern = 295, - FieldPattern = 296, - RemainingFieldPattern = 297, - MutPattern = 298, - RangePattern = 299, - RefPattern = 300, - CapturedPattern = 301, - ReferencePattern = 302, - OrPattern = 303, - Literal2 = 304, - LiteralPattern = 305, - NegativeLiteral = 306, - StringLiteral = 307, - RawStringLiteral = 308, - BooleanLiteral = 309, - LineComment = 310, - LineDocCommentMarker = 311, - InnerDocCommentMarker2 = 312, - OuterDocCommentMarker2 = 313, - BlockComment = 314, - BlockDocCommentMarker = 315, - SourceFileRepeat1 = 316, - MacroDefinitionRepeat1 = 317, - TokenTreePatternRepeat1 = 318, - TokenTreeRepeat1 = 319, - NonSpecialTokenRepeat1 = 320, - DeclarationListRepeat1 = 321, - EnumVariantListRepeat1 = 322, - EnumVariantListRepeat2 = 323, - FieldDeclarationListRepeat1 = 324, - OrderedFieldDeclarationListRepeat1 = 325, - FunctionModifiersRepeat1 = 326, - WhereClauseRepeat1 = 327, - TraitBoundsRepeat1 = 328, - TypeParametersRepeat1 = 329, - UseListRepeat1 = 330, - ParametersRepeat1 = 331, - ForLifetimesRepeat1 = 332, - TupleTypeRepeat1 = 333, - TypeArgumentsRepeat1 = 334, - DelimTokenTreeRepeat1 = 335, - ArgumentsRepeat1 = 336, - TupleExpressionRepeat1 = 337, - FieldInitializerListRepeat1 = 338, - MatchBlockRepeat1 = 339, - MatchArmRepeat1 = 340, - ClosureParametersRepeat1 = 341, - TuplePatternRepeat1 = 342, - SlicePatternRepeat1 = 343, - StructPatternRepeat1 = 344, - StringLiteralRepeat1 = 345, - FieldIdentifier = 346, - LetChain = 347, - ShorthandFieldIdentifier = 348, - TypeIdentifier = 349, - Error = 350, + Expr2021 = 19, + Ident = 20, + Item = 21, + Lifetime2 = 22, + Literal = 23, + Meta = 24, + Pat = 25, + PatParam = 26, + Path = 27, + Stmt = 28, + Tt = 29, + Ty = 30, + Vis = 31, + PrimitiveType = 32, + PrimitiveType2 = 33, + PrimitiveType3 = 34, + PrimitiveType4 = 35, + PrimitiveType5 = 36, + PrimitiveType6 = 37, + PrimitiveType7 = 38, + PrimitiveType8 = 39, + PrimitiveType9 = 40, + PrimitiveType10 = 41, + PrimitiveType11 = 42, + PrimitiveType12 = 43, + PrimitiveType13 = 44, + PrimitiveType14 = 45, + PrimitiveType15 = 46, + PrimitiveType16 = 47, + PrimitiveType17 = 48, + DASH = 49, + SLASH = 50, + PERCENT = 51, + CARET = 52, + BANG = 53, + AMP = 54, + PIPE = 55, + AMPAMP = 56, + PIPEPIPE = 57, + LTLT = 58, + GTGT = 59, + PLUSEQ = 60, + DASHEQ = 61, + STAREQ = 62, + SLASHEQ = 63, + PERCENTEQ = 64, + CARETEQ = 65, + AMPEQ = 66, + PIPEEQ = 67, + LTLTEQ = 68, + GTGTEQ = 69, + EQ = 70, + EQEQ = 71, + BANGEQ = 72, + GT = 73, + LT = 74, + GTEQ = 75, + LTEQ = 76, + AT = 77, + UNDERSCORE = 78, + DOT = 79, + DOTDOT = 80, + DOTDOTDOT = 81, + DOTDOTEQ = 82, + COMMA = 83, + COLONCOLON = 84, + DASHGT = 85, + HASH = 86, + SQUOTE = 87, + As = 88, + Async = 89, + Await = 90, + Break = 91, + Const = 92, + Continue = 93, + Default = 94, + Enum = 95, + Fn = 96, + For = 97, + Gen = 98, + If = 99, + Impl = 100, + Let = 101, + Loop = 102, + Match = 103, + Mod = 104, + Pub = 105, + Return = 106, + Static = 107, + Struct = 108, + Trait = 109, + Type = 110, + Union = 111, + Unsafe = 112, + Use = 113, + Where = 114, + While = 115, + Extern = 116, + Ref = 117, + Else = 118, + In = 119, + LT2 = 120, + Dyn = 121, + MutableSpecifier = 122, + Raw = 123, + Yield = 124, + Move = 125, + Try = 126, + IntegerLiteral = 127, + DQUOTE = 128, + DQUOTE2 = 129, + CharLiteral = 130, + EscapeSequence = 131, + True = 132, + False = 133, + SLASHSLASH = 134, + LineCommentToken1 = 135, + LineCommentToken2 = 136, + LineCommentToken3 = 137, + BANG2 = 138, + SLASH2 = 139, + SLASHSTAR = 140, + STARSLASH = 141, + Shebang = 142, + Zelf = 143, + Super = 144, + Crate = 145, + Metavariable = 146, + StringContent = 147, + RawStringLiteralStart = 148, + StringContent2 = 149, + RawStringLiteralEnd = 150, + FloatLiteral = 151, + OuterDocCommentMarker = 152, + InnerDocCommentMarker = 153, + BlockCommentContent = 154, + DocComment = 155, + ErrorSentinel = 156, + SourceFile = 157, + Statement = 158, + EmptyStatement = 159, + ExpressionStatement = 160, + MacroDefinition = 161, + MacroRule = 162, + TokenPattern = 163, + TokenTreePattern = 164, + TokenBindingPattern = 165, + TokenRepetitionPattern = 166, + FragmentSpecifier = 167, + TokenTree = 168, + TokenRepetition = 169, + AttributeItem = 170, + InnerAttributeItem = 171, + Attribute = 172, + ModItem = 173, + ForeignModItem = 174, + DeclarationList = 175, + StructItem = 176, + UnionItem = 177, + EnumItem = 178, + EnumVariantList = 179, + EnumVariant = 180, + FieldDeclarationList = 181, + FieldDeclaration = 182, + OrderedFieldDeclarationList = 183, + ExternCrateDeclaration = 184, + ConstItem = 185, + StaticItem = 186, + TypeItem = 187, + FunctionItem = 188, + FunctionSignatureItem = 189, + FunctionModifiers = 190, + WhereClause = 191, + WherePredicate = 192, + ImplItem = 193, + TraitItem = 194, + AssociatedType = 195, + TraitBounds = 196, + HigherRankedTraitBound = 197, + RemovedTraitBound = 198, + TypeParameters = 199, + ConstParameter = 200, + TypeParameter = 201, + LifetimeParameter = 202, + LetDeclaration = 203, + UseDeclaration = 204, + UseClause = 205, + ScopedUseList = 206, + UseList = 207, + UseAsClause = 208, + UseWildcard = 209, + Parameters = 210, + SelfParameter = 211, + VariadicParameter = 212, + Parameter = 213, + ExternModifier = 214, + VisibilityModifier = 215, + Type2 = 216, + BracketedType = 217, + QualifiedType = 218, + Lifetime = 219, + ArrayType = 220, + ForLifetimes = 221, + FunctionType = 222, + TupleType = 223, + UnitType = 224, + GenericFunction = 225, + GenericType = 226, + GenericTypeWithTurbofish = 227, + BoundedType = 228, + UseBounds = 229, + TypeArguments = 230, + TypeBinding = 231, + ReferenceType = 232, + PointerType = 233, + NeverType = 234, + AbstractType = 235, + DynamicType = 236, + ExpressionExceptRange = 237, + Expression = 238, + MacroInvocation = 239, + TokenTree2 = 240, + DelimTokens = 241, + NonDelimToken = 242, + ScopedIdentifier = 243, + ScopedTypeIdentifier = 244, + ScopedTypeIdentifier2 = 245, + RangeExpression = 246, + UnaryExpression = 247, + TryExpression = 248, + ReferenceExpression = 249, + BinaryExpression = 250, + AssignmentExpression = 251, + CompoundAssignmentExpr = 252, + TypeCastExpression = 253, + ReturnExpression = 254, + YieldExpression = 255, + CallExpression = 256, + Arguments = 257, + ArrayExpression = 258, + ParenthesizedExpression = 259, + TupleExpression = 260, + UnitExpression = 261, + StructExpression = 262, + FieldInitializerList = 263, + ShorthandFieldInitializer = 264, + FieldInitializer = 265, + BaseFieldInitializer = 266, + IfExpression = 267, + LetCondition = 268, + LetChain2 = 269, + Condition = 270, + ElseClause = 271, + MatchExpression = 272, + MatchBlock = 273, + MatchArm = 274, + MatchArm2 = 275, + MatchPattern = 276, + WhileExpression = 277, + LoopExpression = 278, + ForExpression = 279, + ConstBlock = 280, + ClosureExpression = 281, + ClosureParameters = 282, + Label = 283, + BreakExpression = 284, + ContinueExpression = 285, + IndexExpression = 286, + AwaitExpression = 287, + FieldExpression = 288, + UnsafeBlock = 289, + AsyncBlock = 290, + GenBlock = 291, + TryBlock = 292, + Block = 293, + Pattern = 294, + GenericPattern = 295, + TuplePattern = 296, + SlicePattern = 297, + TupleStructPattern = 298, + StructPattern = 299, + FieldPattern = 300, + RemainingFieldPattern = 301, + MutPattern = 302, + RangePattern = 303, + RefPattern = 304, + CapturedPattern = 305, + ReferencePattern = 306, + OrPattern = 307, + Literal2 = 308, + LiteralPattern = 309, + NegativeLiteral = 310, + StringLiteral = 311, + RawStringLiteral = 312, + BooleanLiteral = 313, + LineComment = 314, + LineDocCommentMarker = 315, + InnerDocCommentMarker2 = 316, + OuterDocCommentMarker2 = 317, + BlockComment = 318, + BlockDocCommentMarker = 319, + SourceFileRepeat1 = 320, + MacroDefinitionRepeat1 = 321, + TokenTreePatternRepeat1 = 322, + TokenTreeRepeat1 = 323, + NonSpecialTokenRepeat1 = 324, + DeclarationListRepeat1 = 325, + EnumVariantListRepeat1 = 326, + EnumVariantListRepeat2 = 327, + FieldDeclarationListRepeat1 = 328, + OrderedFieldDeclarationListRepeat1 = 329, + FunctionModifiersRepeat1 = 330, + WhereClauseRepeat1 = 331, + TraitBoundsRepeat1 = 332, + TypeParametersRepeat1 = 333, + UseListRepeat1 = 334, + ParametersRepeat1 = 335, + ForLifetimesRepeat1 = 336, + TupleTypeRepeat1 = 337, + UseBoundsRepeat1 = 338, + TypeArgumentsRepeat1 = 339, + DelimTokenTreeRepeat1 = 340, + ArgumentsRepeat1 = 341, + TupleExpressionRepeat1 = 342, + FieldInitializerListRepeat1 = 343, + MatchBlockRepeat1 = 344, + MatchArmRepeat1 = 345, + ClosureParametersRepeat1 = 346, + TuplePatternRepeat1 = 347, + SlicePatternRepeat1 = 348, + StructPatternRepeat1 = 349, + StringLiteralRepeat1 = 350, + FieldIdentifier = 351, + LetChain = 352, + ShorthandFieldIdentifier = 353, + TypeIdentifier = 354, + Error = 355, + } impl From for &'static str { @@ -380,12 +386,14 @@ impl From for &'static str { Rust::QMARK => "?", Rust::Block2 => "block", Rust::Expr => "expr", + Rust::Expr2021 => "expr_2021", Rust::Ident => "ident", Rust::Item => "item", Rust::Lifetime2 => "lifetime", Rust::Literal => "literal", Rust::Meta => "meta", Rust::Pat => "pat", + Rust::PatParam => "pat_param", Rust::Path => "path", Rust::Stmt => "stmt", Rust::Tt => "tt", @@ -560,8 +568,8 @@ impl From for &'static str { Rust::RemovedTraitBound => "removed_trait_bound", Rust::TypeParameters => "type_parameters", Rust::ConstParameter => "const_parameter", - Rust::ConstrainedTypeParameter => "constrained_type_parameter", - Rust::OptionalTypeParameter => "optional_type_parameter", + Rust::TypeParameter => "type_parameter", + Rust::LifetimeParameter => "lifetime_parameter", Rust::LetDeclaration => "let_declaration", Rust::UseDeclaration => "use_declaration", Rust::UseClause => "_use_clause", @@ -588,6 +596,7 @@ impl From for &'static str { Rust::GenericType => "generic_type", Rust::GenericTypeWithTurbofish => "generic_type_with_turbofish", Rust::BoundedType => "bounded_type", + Rust::UseBounds => "use_bounds", Rust::TypeArguments => "type_arguments", Rust::TypeBinding => "type_binding", Rust::ReferenceType => "reference_type", @@ -653,6 +662,7 @@ impl From for &'static str { Rust::TryBlock => "try_block", Rust::Block => "block", Rust::Pattern => "_pattern", + Rust::GenericPattern => "generic_pattern", Rust::TuplePattern => "tuple_pattern", Rust::SlicePattern => "slice_pattern", Rust::TupleStructPattern => "tuple_struct_pattern", @@ -695,6 +705,7 @@ impl From for &'static str { Rust::ParametersRepeat1 => "parameters_repeat1", Rust::ForLifetimesRepeat1 => "for_lifetimes_repeat1", Rust::TupleTypeRepeat1 => "tuple_type_repeat1", + Rust::UseBoundsRepeat1 => "use_bounds_repeat1", Rust::TypeArgumentsRepeat1 => "type_arguments_repeat1", Rust::DelimTokenTreeRepeat1 => "delim_token_tree_repeat1", Rust::ArgumentsRepeat1 => "arguments_repeat1", @@ -712,6 +723,7 @@ impl From for &'static str { Rust::ShorthandFieldIdentifier => "shorthand_field_identifier", Rust::TypeIdentifier => "type_identifier", Rust::Error => "ERROR", + } } } diff --git a/src/languages/language_tsx.rs b/src/languages/language_tsx.rs index e90204510..1950aca18 100644 --- a/src/languages/language_tsx.rs +++ b/src/languages/language_tsx.rs @@ -405,6 +405,7 @@ pub enum Tsx { ThisType = 398, TypeIdentifier = 399, Error = 400, + } impl From for &'static str { @@ -812,6 +813,7 @@ impl From for &'static str { Tsx::ThisType => "this_type", Tsx::TypeIdentifier => "type_identifier", Tsx::Error => "ERROR", + } } } diff --git a/src/languages/language_typescript.rs b/src/languages/language_typescript.rs index ff997606a..69c32c058 100644 --- a/src/languages/language_typescript.rs +++ b/src/languages/language_typescript.rs @@ -388,6 +388,7 @@ pub enum Typescript { ThisType = 381, TypeIdentifier = 382, Error = 383, + } impl From for &'static str { @@ -558,9 +559,7 @@ impl From for &'static str { Typescript::QMARK2 => "?", Typescript::HtmlComment => "html_comment", Typescript::JsxText => "jsx_text", - Typescript::FunctionSignatureAutomaticSemicolon => { - "_function_signature_automatic_semicolon" - } + Typescript::FunctionSignatureAutomaticSemicolon => "_function_signature_automatic_semicolon", Typescript::ErrorRecovery => "__error_recovery", Typescript::Program => "program", Typescript::ExportStatement => "export_statement", @@ -775,13 +774,12 @@ impl From for &'static str { Typescript::InterfaceBody => "interface_body", Typescript::PropertyIdentifier => "property_identifier", Typescript::ShorthandPropertyIdentifier => "shorthand_property_identifier", - Typescript::ShorthandPropertyIdentifierPattern => { - "shorthand_property_identifier_pattern" - } + Typescript::ShorthandPropertyIdentifierPattern => "shorthand_property_identifier_pattern", Typescript::StatementIdentifier => "statement_identifier", Typescript::ThisType => "this_type", Typescript::TypeIdentifier => "type_identifier", Typescript::Error => "ERROR", + } } } diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index 1fcff448b..a2bc31281 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -612,13 +612,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 4.0, - "average": 4.0, - "min": 0.0, - "max": 4.0 - }"### + @r#" + { + "sum": 4.0, + "average": 4.0, + "min": 0.0, + "max": 4.0 + } + "# ); }, ); @@ -635,13 +636,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 1.0, - "average": 1.0, - "min": 0.0, - "max": 1.0 - }"### + @r#" + { + "sum": 1.0, + "average": 1.0, + "min": 0.0, + "max": 1.0 + } + "# ); }, ); @@ -658,13 +660,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 2.0, - "average": 2.0, - "min": 0.0, - "max": 2.0 - }"### + @r#" + { + "sum": 2.0, + "average": 2.0, + "min": 0.0, + "max": 2.0 + } + "# ); }, ); @@ -684,13 +687,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 4.0, - "average": 4.0, - "min": 0.0, - "max": 4.0 - }"### + @r#" + { + "sum": 4.0, + "average": 4.0, + "min": 0.0, + "max": 4.0 + } + "# ); }, ); @@ -712,13 +716,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 6.0, - "average": 6.0, - "min": 0.0, - "max": 6.0 - }"### + @r#" + { + "sum": 6.0, + "average": 6.0, + "min": 0.0, + "max": 6.0 + } + "# ); }, ); @@ -815,13 +820,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 2.0, - "average": 2.0, - "min": 0.0, - "max": 2.0 - }"### + @r#" + { + "sum": 2.0, + "average": 2.0, + "min": 0.0, + "max": 2.0 + } + "# ); }, ); @@ -1128,13 +1134,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 3.0, - "average": 3.0, - "min": 0.0, - "max": 3.0 - }"### + @r#" + { + "sum": 3.0, + "average": 3.0, + "min": 0.0, + "max": 3.0 + } + "# ); }, ); @@ -1225,13 +1232,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 3.0, - "average": 3.0, - "min": 0.0, - "max": 3.0 - }"### + @r#" + { + "sum": 3.0, + "average": 3.0, + "min": 0.0, + "max": 3.0 + } + "# ); }, ); @@ -1641,13 +1649,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 4.0, - "average": 4.0, - "min": 0.0, - "max": 4.0 - }"### + @r#" + { + "sum": 4.0, + "average": 4.0, + "min": 0.0, + "max": 4.0 + } + "# ); }, ); @@ -1668,13 +1677,14 @@ mod tests { // 2 functions + 2 lambdas = 4 insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 5.0, - "average": 1.25, - "min": 0.0, - "max": 3.0 - }"### + @r#" + { + "sum": 5.0, + "average": 1.25, + "min": 0.0, + "max": 3.0 + } + "# ); }, ); @@ -1701,13 +1711,14 @@ mod tests { |metric| { insta::assert_json_snapshot!( metric.cognitive, - @r###" - { - "sum": 9.0, - "average": 9.0, - "min": 0.0, - "max": 9.0 - }"### + @r#" + { + "sum": 9.0, + "average": 9.0, + "min": 0.0, + "max": 9.0 + } + "# ); }, ); diff --git a/src/metrics/exit.rs b/src/metrics/exit.rs index 33a8aab47..004cbbcea 100644 --- a/src/metrics/exit.rs +++ b/src/metrics/exit.rs @@ -321,13 +321,14 @@ mod tests { // 2 functions insta::assert_json_snapshot!( metric.nexits, - @r###" - { - "sum": 2.0, - "average": 1.0, - "min": 0.0, - "max": 1.0 - }"### + @r#" + { + "sum": 2.0, + "average": 1.0, + "min": 0.0, + "max": 1.0 + } + "# ); }, ); @@ -347,13 +348,14 @@ mod tests { // 2 functions + 2 lambdas = 4 insta::assert_json_snapshot!( metric.nexits, - @r###" - { - "sum": 2.0, - "average": 0.5, - "min": 0.0, - "max": 1.0 - }"### + @r#" + { + "sum": 2.0, + "average": 0.5, + "min": 0.0, + "max": 1.0 + } + "# ); }, ); diff --git a/src/metrics/halstead.rs b/src/metrics/halstead.rs index fc0604edf..df3174b53 100644 --- a/src/metrics/halstead.rs +++ b/src/metrics/halstead.rs @@ -476,23 +476,24 @@ mod tests { // unique operands: main, a, b, c, avg, 3, 5, console.log, console, log, "{}" insta::assert_json_snapshot!( metric.halstead, - @r###" - { - "n1": 10.0, - "N1": 24.0, - "n2": 11.0, - "N2": 21.0, - "length": 45.0, - "estimated_program_length": 71.27302875388389, - "purity_ratio": 1.583845083419642, - "vocabulary": 21.0, - "volume": 197.65428402504423, - "difficulty": 9.545454545454545, - "level": 0.10476190476190476, - "effort": 1886.699983875422, - "time": 104.81666577085679, - "bugs": 0.05089564733125986 - }"### + @r#" + { + "n1": 10.0, + "N1": 24.0, + "n2": 11.0, + "N2": 21.0, + "length": 45.0, + "estimated_program_length": 71.27302875388389, + "purity_ratio": 1.583845083419642, + "vocabulary": 21.0, + "volume": 197.65428402504423, + "difficulty": 9.545454545454545, + "level": 0.10476190476190476, + "effort": 1886.699983875422, + "time": 104.81666577085679, + "bugs": 0.05089564733125986 + } + "# ); }, ); diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index c5967b7cd..c8171639a 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -1107,29 +1107,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 10.0, - "ploc": 7.0, - "lloc": 6.0, - "cloc": 4.0, - "blank": 1.0, - "sloc_average": 5.0, - "ploc_average": 3.5, - "lloc_average": 3.0, - "cloc_average": 2.0, - "blank_average": 0.5, - "sloc_min": 10.0, - "sloc_max": 10.0, - "cloc_min": 4.0, - "cloc_max": 4.0, - "ploc_min": 7.0, - "ploc_max": 7.0, - "lloc_min": 6.0, - "lloc_max": 6.0, - "blank_min": 1.0, - "blank_max": 1.0 - }"### + @r#" + { + "sloc": 10.0, + "ploc": 7.0, + "lloc": 6.0, + "cloc": 4.0, + "blank": 1.0, + "sloc_average": 5.0, + "ploc_average": 3.5, + "lloc_average": 3.0, + "cloc_average": 2.0, + "blank_average": 0.5, + "sloc_min": 10.0, + "sloc_max": 10.0, + "cloc_min": 4.0, + "cloc_max": 4.0, + "ploc_min": 7.0, + "ploc_max": 7.0, + "lloc_min": 6.0, + "lloc_max": 6.0, + "blank_min": 1.0, + "blank_max": 1.0 + } + "# ); }, ); @@ -1154,29 +1155,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 9.0, - "ploc": 7.0, - "lloc": 6.0, - "cloc": 4.0, - "blank": 0.0, - "sloc_average": 4.5, - "ploc_average": 3.5, - "lloc_average": 3.0, - "cloc_average": 2.0, - "blank_average": 0.0, - "sloc_min": 9.0, - "sloc_max": 9.0, - "cloc_min": 4.0, - "cloc_max": 4.0, - "ploc_min": 7.0, - "ploc_max": 7.0, - "lloc_min": 6.0, - "lloc_max": 6.0, - "blank_min": 0.0, - "blank_max": 0.0 - }"### + @r#" + { + "sloc": 9.0, + "ploc": 7.0, + "lloc": 6.0, + "cloc": 4.0, + "blank": 0.0, + "sloc_average": 4.5, + "ploc_average": 3.5, + "lloc_average": 3.0, + "cloc_average": 2.0, + "blank_average": 0.0, + "sloc_min": 9.0, + "sloc_max": 9.0, + "cloc_min": 4.0, + "cloc_max": 4.0, + "ploc_min": 7.0, + "ploc_max": 7.0, + "lloc_min": 6.0, + "lloc_max": 6.0, + "blank_min": 0.0, + "blank_max": 0.0 + } + "# ); }, ); @@ -1202,29 +1204,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 10.0, - "ploc": 7.0, - "lloc": 6.0, - "cloc": 5.0, - "blank": 1.0, - "sloc_average": 5.0, - "ploc_average": 3.5, - "lloc_average": 3.0, - "cloc_average": 2.5, - "blank_average": 0.5, - "sloc_min": 10.0, - "sloc_max": 10.0, - "cloc_min": 5.0, - "cloc_max": 5.0, - "ploc_min": 7.0, - "ploc_max": 7.0, - "lloc_min": 6.0, - "lloc_max": 6.0, - "blank_min": 1.0, - "blank_max": 1.0 - }"### + @r#" + { + "sloc": 10.0, + "ploc": 7.0, + "lloc": 6.0, + "cloc": 5.0, + "blank": 1.0, + "sloc_average": 5.0, + "ploc_average": 3.5, + "lloc_average": 3.0, + "cloc_average": 2.5, + "blank_average": 0.5, + "sloc_min": 10.0, + "sloc_max": 10.0, + "cloc_min": 5.0, + "cloc_max": 5.0, + "ploc_min": 7.0, + "ploc_max": 7.0, + "lloc_min": 6.0, + "lloc_max": 6.0, + "blank_min": 1.0, + "blank_max": 1.0 + } + "# ); }, ); @@ -1300,29 +1303,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 11.0, - "ploc": 8.0, - "lloc": 1.0, - "cloc": 4.0, - "blank": 1.0, - "sloc_average": 5.5, - "ploc_average": 4.0, - "lloc_average": 0.5, - "cloc_average": 2.0, - "blank_average": 0.5, - "sloc_min": 11.0, - "sloc_max": 11.0, - "cloc_min": 4.0, - "cloc_max": 4.0, - "ploc_min": 8.0, - "ploc_max": 8.0, - "lloc_min": 1.0, - "lloc_max": 1.0, - "blank_min": 1.0, - "blank_max": 1.0 - }"### + @r#" + { + "sloc": 11.0, + "ploc": 8.0, + "lloc": 1.0, + "cloc": 4.0, + "blank": 1.0, + "sloc_average": 5.5, + "ploc_average": 4.0, + "lloc_average": 0.5, + "cloc_average": 2.0, + "blank_average": 0.5, + "sloc_min": 11.0, + "sloc_max": 11.0, + "cloc_min": 4.0, + "cloc_max": 4.0, + "ploc_min": 8.0, + "ploc_max": 8.0, + "lloc_min": 1.0, + "lloc_max": 1.0, + "blank_min": 1.0, + "blank_max": 1.0 + } + "# ); }, ); @@ -1589,29 +1593,30 @@ mod tests { // Spaces: 1 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 5.0, - "ploc": 1.0, - "lloc": 2.0, - "cloc": 5.0, - "blank": 0.0, - "sloc_average": 5.0, - "ploc_average": 1.0, - "lloc_average": 2.0, - "cloc_average": 5.0, - "blank_average": 0.0, - "sloc_min": 5.0, - "sloc_max": 5.0, - "cloc_min": 5.0, - "cloc_max": 5.0, - "ploc_min": 1.0, - "ploc_max": 1.0, - "lloc_min": 2.0, - "lloc_max": 2.0, - "blank_min": 0.0, - "blank_max": 0.0 - }"### + @r#" + { + "sloc": 5.0, + "ploc": 1.0, + "lloc": 2.0, + "cloc": 5.0, + "blank": 0.0, + "sloc_average": 5.0, + "ploc_average": 1.0, + "lloc_average": 2.0, + "cloc_average": 5.0, + "blank_average": 0.0, + "sloc_min": 5.0, + "sloc_max": 5.0, + "cloc_min": 5.0, + "cloc_max": 5.0, + "ploc_min": 1.0, + "ploc_max": 1.0, + "lloc_min": 2.0, + "lloc_max": 2.0, + "blank_min": 0.0, + "blank_max": 0.0 + } + "# ); }, ); @@ -2475,29 +2480,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 6.0, - "ploc": 6.0, - "lloc": 3.0, - "cloc": 0.0, - "blank": 0.0, - "sloc_average": 3.0, - "ploc_average": 3.0, - "lloc_average": 1.5, - "cloc_average": 0.0, - "blank_average": 0.0, - "sloc_min": 6.0, - "sloc_max": 6.0, - "cloc_min": 0.0, - "cloc_max": 0.0, - "ploc_min": 6.0, - "ploc_max": 6.0, - "lloc_min": 3.0, - "lloc_max": 3.0, - "blank_min": 0.0, - "blank_max": 0.0 - }"### + @r#" + { + "sloc": 6.0, + "ploc": 6.0, + "lloc": 3.0, + "cloc": 0.0, + "blank": 0.0, + "sloc_average": 3.0, + "ploc_average": 3.0, + "lloc_average": 1.5, + "cloc_average": 0.0, + "blank_average": 0.0, + "sloc_min": 6.0, + "sloc_max": 6.0, + "cloc_min": 0.0, + "cloc_max": 0.0, + "ploc_min": 6.0, + "ploc_max": 6.0, + "lloc_min": 3.0, + "lloc_max": 3.0, + "blank_min": 0.0, + "blank_max": 0.0 + } + "# ); }, ); @@ -2527,29 +2533,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 16.0, - "ploc": 9.0, - "lloc": 8.0, - "cloc": 7.0, - "blank": 0.0, - "sloc_average": 8.0, - "ploc_average": 4.5, - "lloc_average": 4.0, - "cloc_average": 3.5, - "blank_average": 0.0, - "sloc_min": 16.0, - "sloc_max": 16.0, - "cloc_min": 7.0, - "cloc_max": 7.0, - "ploc_min": 9.0, - "ploc_max": 9.0, - "lloc_min": 8.0, - "lloc_max": 8.0, - "blank_min": 0.0, - "blank_max": 0.0 - }"### + @r#" + { + "sloc": 16.0, + "ploc": 9.0, + "lloc": 8.0, + "cloc": 7.0, + "blank": 0.0, + "sloc_average": 8.0, + "ploc_average": 4.5, + "lloc_average": 4.0, + "cloc_average": 3.5, + "blank_average": 0.0, + "sloc_min": 16.0, + "sloc_max": 16.0, + "cloc_min": 7.0, + "cloc_max": 7.0, + "ploc_min": 9.0, + "ploc_max": 9.0, + "lloc_min": 8.0, + "lloc_max": 8.0, + "blank_min": 0.0, + "blank_max": 0.0 + } + "# ); }, ); @@ -2568,29 +2575,30 @@ mod tests { // Spaces: 2 insta::assert_json_snapshot!( metric.loc, - @r###" - { - "sloc": 5.0, - "ploc": 5.0, - "lloc": 6.0, - "cloc": 0.0, - "blank": 0.0, - "sloc_average": 2.5, - "ploc_average": 2.5, - "lloc_average": 3.0, - "cloc_average": 0.0, - "blank_average": 0.0, - "sloc_min": 5.0, - "sloc_max": 5.0, - "cloc_min": 0.0, - "cloc_max": 0.0, - "ploc_min": 5.0, - "ploc_max": 5.0, - "lloc_min": 5.0, - "lloc_max": 5.0, - "blank_min": 0.0, - "blank_max": 0.0 - }"### + @r#" + { + "sloc": 5.0, + "ploc": 5.0, + "lloc": 6.0, + "cloc": 0.0, + "blank": 0.0, + "sloc_average": 2.5, + "ploc_average": 2.5, + "lloc_average": 3.0, + "cloc_average": 0.0, + "blank_average": 0.0, + "sloc_min": 5.0, + "sloc_max": 5.0, + "cloc_min": 0.0, + "cloc_max": 0.0, + "ploc_min": 5.0, + "ploc_max": 5.0, + "lloc_min": 5.0, + "lloc_max": 5.0, + "blank_min": 0.0, + "blank_max": 0.0 + } + "# ); }, ); diff --git a/src/metrics/nargs.rs b/src/metrics/nargs.rs index 74122b79c..0562161e0 100644 --- a/src/metrics/nargs.rs +++ b/src/metrics/nargs.rs @@ -371,19 +371,20 @@ mod tests { // 1 function insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 2.0, - "total_closures": 0.0, - "average_functions": 2.0, - "average_closures": 0.0, - "total": 2.0, - "average": 2.0, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 2.0, + "total_closures": 0.0, + "average_functions": 2.0, + "average_closures": 0.0, + "total": 2.0, + "average": 2.0, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -462,19 +463,20 @@ mod tests { // 1 function insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 2.0, - "total_closures": 0.0, - "average_functions": 2.0, - "average_closures": 0.0, - "total": 2.0, - "average": 2.0, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 2.0, + "total_closures": 0.0, + "average_functions": 2.0, + "average_closures": 0.0, + "total": 2.0, + "average": 2.0, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -486,19 +488,20 @@ mod tests { // 1 lambda insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 0.0, - "total_closures": 1.0, - "average_functions": 0.0, - "average_closures": 1.0, - "total": 1.0, - "average": 1.0, - "functions_min": 0.0, - "functions_max": 0.0, - "closures_min": 1.0, - "closures_max": 1.0 - }"### + @r#" + { + "total_functions": 0.0, + "total_closures": 1.0, + "average_functions": 0.0, + "average_closures": 1.0, + "total": 1.0, + "average": 1.0, + "functions_min": 0.0, + "functions_max": 0.0, + "closures_min": 1.0, + "closures_max": 1.0 + } + "# ); }); } @@ -559,19 +562,20 @@ mod tests { // 1 lambda insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 0.0, - "total_closures": 2.0, - "average_functions": 0.0, - "average_closures": 2.0, - "total": 2.0, - "average": 2.0, - "functions_min": 0.0, - "functions_max": 0.0, - "closures_min": 0.0, - "closures_max": 2.0 - }"### + @r#" + { + "total_functions": 0.0, + "total_closures": 2.0, + "average_functions": 0.0, + "average_closures": 2.0, + "total": 2.0, + "average": 2.0, + "functions_min": 0.0, + "functions_max": 0.0, + "closures_min": 0.0, + "closures_max": 2.0 + } + "# ); }); } @@ -590,19 +594,20 @@ mod tests { // 2 functions insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 4.0, - "total_closures": 0.0, - "average_functions": 2.0, - "average_closures": 0.0, - "total": 4.0, - "average": 2.0, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 4.0, + "total_closures": 0.0, + "average_functions": 2.0, + "average_closures": 0.0, + "total": 4.0, + "average": 2.0, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -619,19 +624,20 @@ mod tests { // 2 functions insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 5.0, - "total_closures": 0.0, - "average_functions": 2.5, - "average_closures": 0.0, - "total": 5.0, - "average": 2.5, - "functions_min": 0.0, - "functions_max": 3.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 5.0, + "total_closures": 0.0, + "average_functions": 2.5, + "average_closures": 0.0, + "total": 5.0, + "average": 2.5, + "functions_min": 0.0, + "functions_max": 3.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -789,19 +795,20 @@ mod tests { // 2 functions insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 4.0, - "total_closures": 0.0, - "average_functions": 2.0, - "average_closures": 0.0, - "total": 4.0, - "average": 2.0, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 4.0, + "total_closures": 0.0, + "average_functions": 2.0, + "average_closures": 0.0, + "total": 4.0, + "average": 2.0, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -818,19 +825,20 @@ mod tests { // 2 functions insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 5.0, - "total_closures": 0.0, - "average_functions": 2.5, - "average_closures": 0.0, - "total": 5.0, - "average": 2.5, - "functions_min": 0.0, - "functions_max": 3.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "total_functions": 5.0, + "total_closures": 0.0, + "average_functions": 2.5, + "average_closures": 0.0, + "total": 5.0, + "average": 2.5, + "functions_min": 0.0, + "functions_max": 3.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -850,19 +858,20 @@ mod tests { // 2 functions + 2 lambdas = 4 insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 3.0, - "total_closures": 2.0, - "average_functions": 1.5, - "average_closures": 1.0, - "total": 5.0, - "average": 1.25, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 2.0 - }"### + @r#" + { + "total_functions": 3.0, + "total_closures": 2.0, + "average_functions": 1.5, + "average_closures": 1.0, + "total": 5.0, + "average": 1.25, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 2.0 + } + "# ); }, ); @@ -949,19 +958,20 @@ mod tests { // 3 functions + 1 lambdas = 4 insta::assert_json_snapshot!( metric.nargs, - @r###" - { - "total_functions": 6.0, - "total_closures": 1.0, - "average_functions": 2.0, - "average_closures": 1.0, - "total": 7.0, - "average": 1.75, - "functions_min": 0.0, - "functions_max": 2.0, - "closures_min": 0.0, - "closures_max": 1.0 - }"### + @r#" + { + "total_functions": 6.0, + "total_closures": 1.0, + "average_functions": 2.0, + "average_closures": 1.0, + "total": 7.0, + "average": 1.75, + "functions_min": 0.0, + "functions_max": 2.0, + "closures_min": 0.0, + "closures_max": 1.0 + } + "# ); }, ); diff --git a/src/metrics/nom.rs b/src/metrics/nom.rs index 95a44e61f..61ccd1d87 100644 --- a/src/metrics/nom.rs +++ b/src/metrics/nom.rs @@ -237,19 +237,20 @@ mod tests { // Number of spaces = 4 insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 3.0, - "closures": 1.0, - "functions_average": 0.75, - "closures_average": 0.25, - "total": 4.0, - "average": 1.0, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 1.0 - }"### + @r#" + { + "functions": 3.0, + "closures": 1.0, + "functions_average": 0.75, + "closures_average": 0.25, + "total": 4.0, + "average": 1.0, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 1.0 + } + "# ); }, ); @@ -369,19 +370,20 @@ mod tests { // closures: return function () insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 3.0, - "closures": 1.0, - "functions_average": 0.6, - "closures_average": 0.2, - "total": 4.0, - "average": 0.8, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 1.0 - }"### + @r#" + { + "functions": 3.0, + "closures": 1.0, + "functions_average": 0.6, + "closures_average": 0.2, + "total": 4.0, + "average": 0.8, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 1.0 + } + "# ); }, ); @@ -399,19 +401,20 @@ mod tests { // functions: test_safe_mode insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 1.0, - "closures": 0.0, - "functions_average": 0.5, - "closures_average": 0.0, - "total": 1.0, - "average": 0.5, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "functions": 1.0, + "closures": 0.0, + "functions_average": 0.5, + "closures_average": 0.0, + "total": 1.0, + "average": 0.5, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -426,19 +429,20 @@ mod tests { // Number of spaces = 2 insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 1.0, - "closures": 0.0, - "functions_average": 0.5, - "closures_average": 0.0, - "total": 1.0, - "average": 0.5, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "functions": 1.0, + "closures": 0.0, + "functions_average": 0.5, + "closures_average": 0.0, + "total": 1.0, + "average": 0.5, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -455,19 +459,20 @@ mod tests { // Number of spaces = 2 insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 1.0, - "closures": 0.0, - "functions_average": 0.5, - "closures_average": 0.0, - "total": 1.0, - "average": 0.5, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "functions": 1.0, + "closures": 0.0, + "functions_average": 0.5, + "closures_average": 0.0, + "total": 1.0, + "average": 0.5, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -515,19 +520,20 @@ mod tests { // Number of spaces = 2 insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 1.0, - "closures": 0.0, - "functions_average": 0.5, - "closures_average": 0.0, - "total": 1.0, - "average": 0.5, - "functions_min": 0.0, - "functions_max": 1.0, - "closures_min": 0.0, - "closures_max": 0.0 - }"### + @r#" + { + "functions": 1.0, + "closures": 0.0, + "functions_average": 0.5, + "closures_average": 0.0, + "total": 1.0, + "average": 0.5, + "functions_min": 0.0, + "functions_max": 1.0, + "closures_min": 0.0, + "closures_max": 0.0 + } + "# ); }, ); @@ -546,19 +552,20 @@ mod tests { // Number of spaces = 3 insta::assert_json_snapshot!( metric.nom, - @r###" - { - "functions": 0.0, - "closures": 2.0, - "functions_average": 0.0, - "closures_average": 0.6666666666666666, - "total": 2.0, - "average": 0.6666666666666666, - "functions_min": 0.0, - "functions_max": 0.0, - "closures_min": 0.0, - "closures_max": 1.0 - }"### + @r#" + { + "functions": 0.0, + "closures": 2.0, + "functions_average": 0.0, + "closures_average": 0.6666666666666666, + "total": 2.0, + "average": 0.6666666666666666, + "functions_min": 0.0, + "functions_max": 0.0, + "closures_min": 0.0, + "closures_max": 1.0 + } + "# ); }, );