Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Extract definitions for 22 grammars and resolve remaining CALLS gaps

Martin Vogeld30093aa8ff3
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 190109969..b3c2baf0b 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -395,17 +395,29 @@ static char *extract_ada_callee(CBMArena *a, TSNode node, const char *source, co
return NULL;
}
-// Solidity: a call_expression's first named child is the callee.
+// Solidity: a call_expression's callee is on the `function` field, wrapped in an
+// `expression` node (call_expression -> function:expression -> identifier). Descend
+// left-most through expression wrappers until we reach the identifier/member.
static char *extract_solidity_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
if (strcmp(nk, "call_expression") != 0 && strcmp(nk, "call") != 0) {
return NULL;
}
- if (ts_node_named_child_count(node) > 0) {
- TSNode head = ts_node_named_child(node, 0);
+ TSNode head = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ if (ts_node_is_null(head) && ts_node_named_child_count(node) > 0) {
+ head = ts_node_named_child(node, 0);
+ }
+ // Unwrap nested `expression` wrappers down to the callee identifier/member.
+ for (int depth = 0; depth < 4 && !ts_node_is_null(head); depth++) {
const char *hk = ts_node_type(head);
- if (strcmp(hk, "identifier") == 0 || strcmp(hk, "member_expression") == 0) {
+ if (strcmp(hk, "identifier") == 0 || strcmp(hk, "member_expression") == 0 ||
+ strcmp(hk, "member_access") == 0) {
return cbm_node_text(a, head, source);
}
+ if (strcmp(hk, "expression") == 0 && ts_node_named_child_count(head) > 0) {
+ head = ts_node_named_child(head, 0);
+ continue;
+ }
+ break;
}
return NULL;
}
@@ -418,7 +430,7 @@ static char *extract_groovy_callee(CBMArena *a, TSNode node, const char *source,
}
if (ts_node_named_child_count(node) > 0) {
TSNode head = ts_node_named_child(node, 0);
- if (strcmp(ts_node_type(head), "identifier") == 0) {
+ if (!ts_node_is_null(head) && strcmp(ts_node_type(head), "identifier") == 0) {
return cbm_node_text(a, head, source);
}
}
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index 726820d4e..a13adf62d 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -512,6 +512,36 @@ static TSNode resolve_r_func_name(TSNode node) {
return null_node;
}
+// Max descent for the (System)Verilog name-wrapper search (module/class headers
+// nest the identifier a few levels deep; bounding avoids walking large subtrees
+// like port lists).
+enum { CBM_DESCENDANT_MAX_DEPTH = 6 };
+
+// Verilog/SystemVerilog: find the first descendant node of the given kind in
+// pre-order (depth-bounded). The (System)Verilog grammar has FIELD_COUNT 0, so
+// def names live on nested *_identifier wrappers reachable only by node kind.
+// Tree-sitter trees are acyclic, so the bounded recursion always terminates.
+static TSNode find_first_descendant_by_kind(TSNode node, const char *kind, // NOLINT(misc-no-recursion)
+ int max_depth) {
+ if (max_depth < 0 || ts_node_is_null(node)) {
+ TSNode null_node = {0};
+ return null_node;
+ }
+ uint32_t n = ts_node_named_child_count(node);
+ for (uint32_t i = 0; i < n; i++) {
+ TSNode child = ts_node_named_child(node, i);
+ if (strcmp(ts_node_type(child), kind) == 0) {
+ return child;
+ }
+ TSNode found = find_first_descendant_by_kind(child, kind, max_depth - 1);
+ if (!ts_node_is_null(found)) {
+ return found;
+ }
+ }
+ TSNode null_node = {0};
+ return null_node;
+}
+
// Forward declaration for mutual recursion.
static TSNode resolve_func_name(TSNode node, CBMLanguage lang);
@@ -719,6 +749,178 @@ static TSNode resolve_func_name(TSNode node, CBMLanguage lang) {
}
}
+ /* Groovy: top-level function_definition carries the name on the `function`
+ * field (not `name`); fall back to the first `identifier` child. */
+ if (lang == CBM_LANG_GROOVY && strcmp(kind, "function_definition") == 0) {
+ TSNode fn = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ if (ts_node_is_null(fn)) {
+ fn = cbm_find_child_by_kind(node, "identifier");
+ }
+ if (!ts_node_is_null(fn)) {
+ return fn;
+ }
+ }
+
+ /* Agda (FIELD_COUNT 0): the only `function` carrying the name is the type
+ * signature line, whose lhs holds a `function_name` alias child. The body
+ * line's lhs has no function_name child -> resolves null and is skipped. */
+ if (lang == CBM_LANG_AGDA && strcmp(kind, "function") == 0) {
+ TSNode lhs = cbm_find_child_by_kind(node, "lhs");
+ if (!ts_node_is_null(lhs)) {
+ TSNode fn = cbm_find_child_by_kind(lhs, "function_name");
+ if (!ts_node_is_null(fn)) {
+ return fn;
+ }
+ }
+ }
+
+ /* Pony: def nodes have no `name` field; the name is the first plain
+ * `identifier` child after the keyword/annotation/capability. */
+ if (lang == CBM_LANG_PONY &&
+ (strcmp(kind, "method") == 0 || strcmp(kind, "constructor") == 0 ||
+ strcmp(kind, "ffi_method") == 0)) {
+ TSNode id = cbm_find_child_by_kind(node, "identifier");
+ if (!ts_node_is_null(id)) {
+ return id;
+ }
+ }
+
+ /* COBOL: program_definition has no `name` field; the program name is
+ * identification_division > program_name (a leaf holding the clean name). */
+ if (lang == CBM_LANG_COBOL && strcmp(kind, "program_definition") == 0) {
+ TSNode iddiv = cbm_find_child_by_kind(node, "identification_division");
+ if (!ts_node_is_null(iddiv)) {
+ TSNode pname = cbm_find_child_by_kind(iddiv, "program_name");
+ if (!ts_node_is_null(pname)) {
+ return pname;
+ }
+ }
+ }
+
+ /* Pine Script: function_declaration_statement carries the name on the
+ * `function` field (or `method` field for the method form), not `name`. */
+ if (lang == CBM_LANG_PINE && strcmp(kind, "function_declaration_statement") == 0) {
+ TSNode nm = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ if (ts_node_is_null(nm)) {
+ nm = ts_node_child_by_field_name(node, TS_FIELD("method"));
+ }
+ if (!ts_node_is_null(nm)) {
+ return nm;
+ }
+ }
+
+ /* Smali (no `name` field): method_definition > method_signature >
+ * method_identifier holds the method name. */
+ if (lang == CBM_LANG_SMALI && strcmp(kind, "method_definition") == 0) {
+ TSNode sig = cbm_find_child_by_kind(node, "method_signature");
+ if (!ts_node_is_null(sig)) {
+ TSNode mid = cbm_find_child_by_kind(sig, "method_identifier");
+ if (!ts_node_is_null(mid)) {
+ return mid;
+ }
+ }
+ }
+
+ /* Verilog/SystemVerilog (FIELD_COUNT 0): function/task names live on a
+ * nested *_identifier wrapper; the function name is the first
+ * simple_identifier descendant (params/returns come after the name). */
+ if ((lang == CBM_LANG_VERILOG || lang == CBM_LANG_SYSTEMVERILOG) &&
+ (strcmp(kind, "function_declaration") == 0 ||
+ strcmp(kind, "task_declaration") == 0)) {
+ TSNode si = find_first_descendant_by_kind(node, "simple_identifier", CBM_DESCENDANT_MAX_DEPTH);
+ if (!ts_node_is_null(si)) {
+ return si;
+ }
+ }
+
+ /* VHDL: subprogram_declaration/_definition carry the name on a nested
+ * function_specification/procedure_specification child, via the
+ * `function`/`procedure` field. */
+ if (lang == CBM_LANG_VHDL && (strcmp(kind, "subprogram_declaration") == 0 ||
+ strcmp(kind, "subprogram_definition") == 0)) {
+ TSNode spec = cbm_find_child_by_kind(node, "function_specification");
+ if (ts_node_is_null(spec)) {
+ spec = cbm_find_child_by_kind(node, "procedure_specification");
+ }
+ if (!ts_node_is_null(spec)) {
+ TSNode nm = ts_node_child_by_field_name(spec, TS_FIELD("function"));
+ if (ts_node_is_null(nm)) {
+ nm = ts_node_child_by_field_name(spec, TS_FIELD("procedure"));
+ }
+ if (!ts_node_is_null(nm)) {
+ return nm;
+ }
+ }
+ }
+
+ /* Thrift / Cap'n Proto / Smithy (no `name` field): the def name is a
+ * plain visible `identifier` child of the statement/definition node. */
+ if (lang == CBM_LANG_THRIFT || lang == CBM_LANG_SMITHY) {
+ TSNode id = cbm_find_child_by_kind(node, "identifier");
+ if (!ts_node_is_null(id)) {
+ return id;
+ }
+ }
+
+ /* Cap'n Proto (FIELD_COUNT 0): name is an aliased *_identifier child. */
+ if (lang == CBM_LANG_CAPNP) {
+ const char *name_kind = NULL;
+ if (strcmp(kind, "struct") == 0 || strcmp(kind, "interface") == 0) {
+ name_kind = "type_identifier";
+ } else if (strcmp(kind, "enum") == 0) {
+ name_kind = "enum_identifier";
+ } else if (strcmp(kind, "method") == 0) {
+ name_kind = "method_identifier";
+ }
+ if (name_kind) {
+ TSNode id = cbm_find_child_by_kind(node, name_kind);
+ if (!ts_node_is_null(id)) {
+ return id;
+ }
+ }
+ }
+
+ /* CMake (FIELD_COUNT 0): function(foo)/macro(foo) — the name is nested as
+ * *_command > argument_list > argument > unquoted_argument. */
+ if (lang == CBM_LANG_CMAKE &&
+ (strcmp(kind, "function_def") == 0 || strcmp(kind, "macro_def") == 0)) {
+ const char *cmd_kind =
+ strcmp(kind, "function_def") == 0 ? "function_command" : "macro_command";
+ TSNode cmd = cbm_find_child_by_kind(node, cmd_kind);
+ if (!ts_node_is_null(cmd)) {
+ TSNode alist = cbm_find_child_by_kind(cmd, "argument_list");
+ if (!ts_node_is_null(alist)) {
+ TSNode arg = cbm_find_child_by_kind(alist, "argument");
+ if (!ts_node_is_null(arg)) {
+ TSNode uq = cbm_find_child_by_kind(arg, "unquoted_argument");
+ return ts_node_is_null(uq) ? arg : uq;
+ }
+ }
+ }
+ }
+
+ /* Puppet: function_declaration name is a plain identifier/class_identifier
+ * child (no `name` field). */
+ if (lang == CBM_LANG_PUPPET &&
+ (strcmp(kind, "function_declaration") == 0 || strcmp(kind, "lambda") == 0)) {
+ TSNode id = cbm_find_child_by_kind(node, "identifier");
+ if (ts_node_is_null(id)) {
+ id = cbm_find_child_by_kind(node, "class_identifier");
+ }
+ if (!ts_node_is_null(id)) {
+ return id;
+ }
+ }
+
+ /* Assembly (GAS): a bare `label` (`foo:`) reduces with no `name` field;
+ * its name child is aliased to `ident`. */
+ if (lang == CBM_LANG_ASSEMBLY && strcmp(kind, "label") == 0) {
+ TSNode id = cbm_find_child_by_kind(node, "ident");
+ if (!ts_node_is_null(id)) {
+ return id;
+ }
+ }
+
{
TSNode r = resolve_toplevel_arrow_name(node, kind);
if (!ts_node_is_null(r)) {
@@ -2092,6 +2294,83 @@ static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
name_node = cbm_find_child_by_kind(node, "enum_name");
}
}
+ // Thrift / Smithy / Pony (no `name` field): class-type defs carry the name on
+ // a plain `identifier` child.
+ if (ts_node_is_null(name_node) &&
+ (ctx->language == CBM_LANG_THRIFT || ctx->language == CBM_LANG_SMITHY ||
+ ctx->language == CBM_LANG_PONY)) {
+ name_node = cbm_find_child_by_kind(node, "identifier");
+ }
+ // Cap'n Proto (FIELD_COUNT 0): struct/interface name is type_identifier, enum
+ // name is enum_identifier (aliased identifier children).
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_CAPNP) {
+ if (strcmp(kind, "enum") == 0) {
+ name_node = cbm_find_child_by_kind(node, "enum_identifier");
+ } else {
+ name_node = cbm_find_child_by_kind(node, "type_identifier");
+ }
+ }
+ // Agda (FIELD_COUNT 0): data > data_name, record > record_name (direct child).
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_AGDA) {
+ if (strcmp(kind, "data") == 0) {
+ name_node = cbm_find_child_by_kind(node, "data_name");
+ } else if (strcmp(kind, "record") == 0) {
+ name_node = cbm_find_child_by_kind(node, "record_name");
+ }
+ }
+ // GraphQL / Prisma (FIELD_COUNT 0): the type name is a plain direct `name`
+ // (GraphQL) or `identifier` (Prisma) child of the type-definition node.
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_GRAPHQL) {
+ name_node = cbm_find_child_by_kind(node, "name");
+ }
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_PRISMA) {
+ name_node = cbm_find_child_by_kind(node, "identifier");
+ }
+ // Puppet: class_definition / type_declaration name is a plain identifier or
+ // class_identifier child (no `name` field).
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_PUPPET) {
+ name_node = cbm_find_child_by_kind(node, "identifier");
+ if (ts_node_is_null(name_node)) {
+ name_node = cbm_find_child_by_kind(node, "class_identifier");
+ }
+ }
+ // Smali (no `name` field): class_definition > class_directive > class_identifier.
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_SMALI) {
+ TSNode dir = cbm_find_child_by_kind(node, "class_directive");
+ if (!ts_node_is_null(dir)) {
+ name_node = cbm_find_child_by_kind(dir, "class_identifier");
+ }
+ }
+ // VHDL: name lives on a declaration-keyword-named field whose value is an
+ // `identifier`. Map node kind -> field name.
+ if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_VHDL) {
+ if (strcmp(kind, "entity_declaration") == 0) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("entity"));
+ } else if (strcmp(kind, "architecture_definition") == 0) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("architecture"));
+ } else if (strcmp(kind, "package_declaration") == 0) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("package"));
+ } else if (strcmp(kind, "component_declaration") == 0) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("component"));
+ } else if (strcmp(kind, "type_declaration") == 0) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("type"));
+ }
+ }
+ // Verilog/SystemVerilog (FIELD_COUNT 0): module/class/interface/package use a
+ // nested simple_identifier (first descendant); type_declaration must use the
+ // DIRECT-child simple_identifier (member/enum idents precede the typedef name).
+ if (ts_node_is_null(name_node) &&
+ (ctx->language == CBM_LANG_VERILOG || ctx->language == CBM_LANG_SYSTEMVERILOG)) {
+ if (strcmp(kind, "type_declaration") == 0) {
+ name_node = cbm_find_child_by_kind(node, "simple_identifier");
+ } else if (strcmp(kind, "module_declaration") == 0 ||
+ strcmp(kind, "class_declaration") == 0 ||
+ strcmp(kind, "interface_declaration") == 0 ||
+ strcmp(kind, "program_declaration") == 0 ||
+ strcmp(kind, "package_declaration") == 0) {
+ name_node = find_first_descendant_by_kind(node, "simple_identifier", CBM_DESCENDANT_MAX_DEPTH);
+ }
+ }
if (ts_node_is_null(name_node)) {
return;
}
@@ -3774,7 +4053,12 @@ static void push_class_body_children(TSNode node, const CBMLangSpec *spec, walk_
const char *ck = ts_node_type(child);
if (strcmp(ck, "field_declaration_list") == 0 || strcmp(ck, "class_body") == 0 ||
strcmp(ck, "declaration_list") == 0 || strcmp(ck, "body") == 0 ||
- strcmp(ck, "block") == 0 || strcmp(ck, "suite") == 0) {
+ strcmp(ck, "block") == 0 || strcmp(ck, "suite") == 0 ||
+ // Groovy class bodies are a `closure` node; routing through the
+ // nested-class path keeps methods from being re-walked (and thus
+ // double-extracted) as top-level functions. Gated to Groovy so other
+ // grammars that also name a node "closure" are unaffected.
+ (strcmp(ck, "closure") == 0 && spec->language == CBM_LANG_GROOVY)) {
push_nested_class_nodes(child, spec, stack, top, new_enclosing, arena);
return;
}
@@ -3880,6 +4164,62 @@ static void extract_gotemplate_define(CBMExtractCtx *ctx, TSNode node) {
cbm_defs_push(&ctx->result->defs, a, def);
}
+// Janet (janet-simple S-expression grammar): definitions are generic `par_tup_lit`
+// forms whose head `sym_lit` is a def keyword — `(defn foo [] 1)` -> "foo". There
+// is no dedicated def node type, so gate on the head keyword and pull the name
+// from the second named child (also a `sym_lit`).
+static bool janet_is_def_head(const char *t) {
+ if (!t) {
+ return false;
+ }
+ static const char *heads[] = {
+ "defn", "defn-", "defmacro", "defmacro-", "varfn",
+ "fn", "def", "def-", "var", "var-",
+ "defstruct", "deftype", "defprotocol", NULL};
+ for (int i = 0; heads[i]; i++) {
+ if (strcmp(t, heads[i]) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static void extract_janet_def(CBMExtractCtx *ctx, TSNode node) {
+ CBMArena *a = ctx->arena;
+ if (ts_node_named_child_count(node) < 2) {
+ return;
+ }
+ TSNode head = ts_node_named_child(node, 0);
+ if (strcmp(ts_node_type(head), "sym_lit") != 0) {
+ return;
+ }
+ char *head_text = cbm_node_text(a, head, ctx->source);
+ if (!janet_is_def_head(head_text)) {
+ return;
+ }
+ TSNode name_node = ts_node_named_child(node, 1);
+ if (strcmp(ts_node_type(name_node), "sym_lit") != 0) {
+ return;
+ }
+ char *name = cbm_node_text(a, name_node, ctx->source);
+ if (!name || !name[0]) {
+ return;
+ }
+ bool is_class = strcmp(head_text, "defstruct") == 0 || strcmp(head_text, "deftype") == 0 ||
+ strcmp(head_text, "defprotocol") == 0;
+ CBMDefinition def;
+ memset(&def, 0, sizeof(def));
+ def.name = name;
+ def.qualified_name = cbm_fqn_compute(a, ctx->project, ctx->rel_path, name);
+ def.label = is_class ? "Class" : "Function";
+ def.file_path = ctx->rel_path;
+ def.start_line = ts_node_start_point(node).row + TS_LINE_OFFSET;
+ def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET;
+ def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);
+ def.is_exported = true;
+ cbm_defs_push(&ctx->result->defs, a, def);
+}
+
// Languages that use the C preprocessor and therefore have #define macros.
static bool is_c_preprocessor_lang(CBMLanguage lang) {
return lang == CBM_LANG_C || lang == CBM_LANG_CPP || lang == CBM_LANG_CUDA ||
@@ -4025,6 +4365,11 @@ static void walk_defs(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec,
// fall through: descend into children so nested defs are captured too
}
+ if (ctx->language == CBM_LANG_JANET && strcmp(kind, "par_tup_lit") == 0) {
+ extract_janet_def(ctx, node);
+ // fall through: descend so nested defs inside the form are captured too
+ }
+
if (cbm_kind_in_set(node, spec->function_node_types)) {
if (!is_template_class_node(node, ctx->language)) {
extract_func_def(ctx, node, spec);
@@ -4033,9 +4378,13 @@ static void walk_defs(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec,
// e.g. arrow methods of an object literal returned from a factory
// (the Zustand actions-slice pattern, #341). Anonymous nested
// arrows have no resolvable name and are skipped.
+ // Ada subprograms nest (a procedure body's declarative part can
+ // contain inner subprogram bodies); descend so the nested defs
+ // are captured and same-file calls to them resolve to a CALLS edge.
bool descend_into_func =
(ctx->language == CBM_LANG_WOLFRAM || ctx->language == CBM_LANG_TYPESCRIPT ||
- ctx->language == CBM_LANG_JAVASCRIPT || ctx->language == CBM_LANG_TSX);
+ ctx->language == CBM_LANG_JAVASCRIPT || ctx->language == CBM_LANG_TSX ||
+ ctx->language == CBM_LANG_ADA);
if (!descend_into_func) {
continue;
}
diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c
index 4f5539c79..7628090bb 100644
--- a/internal/cbm/lang_specs.c
+++ b/internal/cbm/lang_specs.c
@@ -823,6 +823,7 @@ static const char *makefile_import_types[] = {"include_directive", "include", NU
static const char *makefile_var_types[] = {"variable_assignment", NULL};
// ==================== CMAKE ====================
+static const char *cmake_func_types[] = {"function_def", "macro_def", NULL};
static const char *cmake_module_types[] = {"source_file", NULL};
static const char *cmake_call_types[] = {"normal_command", NULL};
@@ -1210,7 +1211,8 @@ static const char *hare_branch_types[] = {"if_statement", "for_statement", "swit
static const char *hare_var_types[] = {"let_declaration", "const_declaration", NULL};
static const char *hare_assign_types[] = {"assignment_expression", NULL};
static const char *hare_module_types[] = {"source_file", NULL};
-static const char *pony_func_types[] = {"fun", "be", "new", "lambda_expression", NULL};
+static const char *pony_func_types[] = {"method", "constructor", "ffi_method",
+ "lambda_expression", NULL};
static const char *pony_class_types[] = {
"actor_definition", "class_definition", "struct_definition", "trait_definition",
"interface_definition", "primitive_definition", "type_alias", NULL};
@@ -1246,11 +1248,13 @@ static const char *sway_branch_types[] = {"if_expression", "match_expression", "
static const char *sway_var_types[] = {"let_declaration", "const_item", NULL};
static const char *sway_assign_types[] = {"assignment_expression", NULL};
static const char *sway_module_types[] = {"source_file", NULL};
+static const char *nasm_func_types[] = {"label", "preproc_def", "preproc_multiline_macro", NULL};
static const char *nasm_class_types[] = {"struc_declaration", NULL};
static const char *nasm_call_types[] = {"call_syntax_expression", NULL};
static const char *nasm_import_types[] = {"preproc_include", NULL};
static const char *nasm_var_types[] = {"label", NULL};
static const char *nasm_module_types[] = {"source_file", NULL};
+static const char *assembly_func_types[] = {"label", NULL};
static const char *assembly_var_types[] = {"label", NULL};
static const char *assembly_module_types[] = {"program", NULL};
static const char *astro_module_types[] = {"document", NULL};
@@ -1317,8 +1321,10 @@ static const char *thrift_import_types[] = {"include_statement", "extends", "inc
static const char *thrift_var_types[] = {"const_definition", NULL};
static const char *thrift_module_types[] = {"document", NULL};
static const char *capnp_func_types[] = {"method", NULL};
-static const char *capnp_class_types[] = {"struct", "enum", "interface", "custom_type",
- "type_definition", NULL};
+/* custom_type (a type REFERENCE inside field_type) and type_definition (LHS of a
+ * `using X = ...` directive) are not top-level type defs — including them would
+ * mint spurious Class nodes for every typed field/return. */
+static const char *capnp_class_types[] = {"struct", "enum", "interface", NULL};
static const char *capnp_field_types[] = {"field", NULL};
static const char *capnp_import_types[] = {"import", "extends", "using_directive", NULL};
static const char *capnp_var_types[] = {"const", NULL};
@@ -1372,7 +1378,7 @@ static const char *vhdl_branch_types[] = {"if_statement", "case_statement", "loo
static const char *vhdl_var_types[] = {"variable_declaration", "signal_declaration",
"constant_declaration", NULL};
static const char *vhdl_assign_types[] = {"variable_assignment", "signal_assignment", NULL};
-static const char *vhdl_func_types[] = {"subprogram_declaration", NULL};
+static const char *vhdl_func_types[] = {"subprogram_declaration", "subprogram_definition", NULL};
static const char *vhdl_module_types[] = {"design_file", NULL};
static const char *systemverilog_func_types[] = {"function_declaration", "task_declaration",
"function_body_declaration", "function_statement",
@@ -1421,6 +1427,8 @@ static const char *smali_class_types[] = {"class_definition", NULL};
static const char *smali_field_types[] = {"field_definition", NULL};
static const char *smali_import_types[] = {"super_directive", "implements_directive", NULL};
static const char *smali_module_types[] = {"source_file", NULL};
+static const char *tablegen_func_types[] = {"def", "multiclass", "defm", NULL};
+static const char *tablegen_class_types[] = {"class", NULL};
static const char *tablegen_import_types[] = {"include", "include_directive", NULL};
static const char *tablegen_module_types[] = {"source_file", NULL};
static const char *ispc_func_types[] = {"function_definition", NULL};
@@ -1445,7 +1453,9 @@ static const char *cairo_var_types[] = {"let_declaration", "const_item", NULL};
static const char *cairo_assign_types[] = {"assignment_expression", NULL};
static const char *cairo_module_types[] = {"source_file", NULL};
static const char *move_func_types[] = {"function_item", NULL};
-static const char *move_class_types[] = {"struct", "enum", NULL};
+/* This vendored move grammar models only function_item + module as named defs;
+ * "struct"/"enum" exist only as anonymous keyword tokens, never as parent nodes,
+ * so there is no class/struct/enum definition node to match. */
static const char *move_call_types[] = {"call_expression", NULL};
static const char *move_import_types[] = {"use_declaration", NULL};
static const char *move_branch_types[] = {"if_expression", "while_expression", "loop_expression",
@@ -1508,7 +1518,8 @@ static const char *smithy_field_types[] = {"shape_member", NULL};
static const char *smithy_import_types[] = {"use_statement", NULL};
static const char *smithy_module_types[] = {"source_file", NULL};
static const char *wit_func_types[] = {"func_item", "resource_method", NULL};
-static const char *wit_class_types[] = {"record_item", "resource_item", NULL};
+static const char *wit_class_types[] = {"record_item", "resource_item", "enum_items",
+ "variant_items", "flags_items", NULL};
static const char *wit_field_types[] = {"record_field", NULL};
static const char *wit_import_types[] = {
"import_item", "toplevel_use_item", "export_item", "import", "include", "include_item", NULL};
@@ -1549,7 +1560,6 @@ static const char *soql_module_types[] = {"source_file", NULL};
static const char *sosl_import_types[] = {"with_clause", NULL};
static const char *sosl_module_types[] = {"source_file", NULL};
-static const char *make_func_types[] = {"recipe", NULL};
static const char *make_import_types[] = {"include", "include_directive", NULL};
// ==================== PINE SCRIPT ====================
@@ -1888,7 +1898,7 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
NULL, empty_types, NULL, NULL, tree_sitter_make, NULL},
// CBM_LANG_CMAKE
- [CBM_LANG_CMAKE] = {CBM_LANG_CMAKE, make_func_types, empty_types, empty_types,
+ [CBM_LANG_CMAKE] = {CBM_LANG_CMAKE, cmake_func_types, empty_types, empty_types,
cmake_module_types, cmake_call_types, make_import_types, empty_types,
empty_types, empty_types, empty_types, empty_types, NULL, empty_types, NULL,
NULL, tree_sitter_cmake, NULL},
@@ -2162,13 +2172,13 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
empty_types, NULL, NULL, tree_sitter_sway, NULL},
// CBM_LANG_NASM
- [CBM_LANG_NASM] = {CBM_LANG_NASM, empty_types, nasm_class_types, empty_types, nasm_module_types,
+ [CBM_LANG_NASM] = {CBM_LANG_NASM, nasm_func_types, nasm_class_types, empty_types, nasm_module_types,
nasm_call_types, nasm_import_types, empty_types, empty_types, nasm_var_types,
empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_nasm,
NULL},
// CBM_LANG_ASSEMBLY
- [CBM_LANG_ASSEMBLY] = {CBM_LANG_ASSEMBLY, empty_types, empty_types, empty_types,
+ [CBM_LANG_ASSEMBLY] = {CBM_LANG_ASSEMBLY, assembly_func_types, empty_types, empty_types,
assembly_module_types, empty_types, empty_types, empty_types,
empty_types, assembly_var_types, empty_types, empty_types, NULL,
empty_types, NULL, NULL, tree_sitter_asm, NULL},
@@ -2379,7 +2389,7 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
NULL, tree_sitter_smali, NULL},
// CBM_LANG_TABLEGEN
- [CBM_LANG_TABLEGEN] = {CBM_LANG_TABLEGEN, empty_types, empty_types, empty_types,
+ [CBM_LANG_TABLEGEN] = {CBM_LANG_TABLEGEN, tablegen_func_types, tablegen_class_types, empty_types,
tablegen_module_types, empty_types, tablegen_import_types, empty_types,
empty_types, empty_types, empty_types, empty_types, NULL, empty_types,
NULL, NULL, tree_sitter_tablegen, NULL},
@@ -2397,7 +2407,7 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
empty_types, NULL, NULL, tree_sitter_cairo, NULL},
// CBM_LANG_MOVE
- [CBM_LANG_MOVE] = {CBM_LANG_MOVE, move_func_types, move_class_types, empty_types,
+ [CBM_LANG_MOVE] = {CBM_LANG_MOVE, move_func_types, empty_types, empty_types,
move_module_types, move_call_types, move_import_types, empty_types,
move_branch_types, move_var_types, move_assign_types, empty_types, NULL,
empty_types, NULL, NULL, tree_sitter_move, NULL},
diff --git a/tests/test_grammar_labels.c b/tests/test_grammar_labels.c
index 952d03a1f..36af84c37 100644
--- a/tests/test_grammar_labels.c
+++ b/tests/test_grammar_labels.c
@@ -110,7 +110,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"julia", "Function:1,Module:1"},
{"matlab", "Function:2,Module:1"},
{"ada", "Function:1,Module:1"},
- {"agda", "Module:1"},
+ {"agda", "Function:1,Module:1"},
{"apex", "Class:1,Method:1,Module:1"},
{"awk", "Function:2,Module:1"},
{"cairo", "Function:2,Module:1"},
@@ -135,7 +135,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"ocaml", "Function:2,Module:1"},
{"odin", "Function:2,Module:1"},
{"pascal", "Function:1,Module:1"},
- {"pony", "Module:1"},
+ {"pony", "Class:1,Function:1,Module:1"},
{"purescript", "Function:1,Module:1"},
{"racket", "Function:2,Module:1"},
{"rescript", "Function:2,Module:1"},
@@ -149,28 +149,28 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"elm", "Class:1,Function:1,Module:1"},
{"func", "Function:1,Module:1"},
{"lean", "Function:2,Module:1"},
- {"move", "Module:1"},
- {"smali", "Module:1"},
- {"systemverilog", "Module:1"},
- {"verilog", "Module:1"},
- {"vhdl", "Module:1"},
+ {"move", "Function:1,Module:1"},
+ {"smali", "Class:1,Function:1,Module:1"},
+ {"systemverilog", "Class:1,Function:1,Module:1"},
+ {"verilog", "Class:1,Module:1"},
+ {"vhdl", "Class:1,Module:1"},
{"wgsl", "Function:2,Module:1"},
{"tlaplus", "Function:1,Module:1"},
{"llvm", "Function:1,Module:1"},
- {"tablegen", "Module:1"},
- {"puppet", "Module:1"},
- {"assembly", "Module:1"},
- {"nasm", "Module:1"},
+ {"tablegen", "Function:1,Module:1"},
+ {"puppet", "Class:1,Module:1"},
+ {"assembly", "Function:1,Module:1"},
+ {"nasm", "Function:1,Module:1"},
{"cfml", "Function:1,Module:1"},
{"cfscript", "Function:1,Module:1"},
- {"cobol", "Module:1"},
- {"janet", "Module:1"},
+ {"cobol", "Function:1,Module:1"},
+ {"janet", "Function:2,Module:1"},
{"magma", "Function:1,Module:1"},
{"qml", "Function:1,Module:1"},
{"wolfram", "Function:1,Module:1"},
- {"pine", "Module:1"},
+ {"pine", "Function:1,Module:1"},
{"form", "Module:1,Variable:1"},
- {"protobuf", "Module:1"},
+ {"protobuf", "Class:1,Module:1"},
{"soql", "Module:1"},
{"sosl", "Module:1"},
{"dotenv", "Module:1"},
@@ -193,7 +193,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"rst", "Module:1"},
{"dockerfile", "Module:1"},
{"makefile", "Function:1,Module:1"},
- {"cmake", "Module:1"},
+ {"cmake", "Function:1,Module:1"},
{"meson", "Module:1"},
{"gn", "Module:1"},
{"just", "Module:1"},
@@ -201,12 +201,12 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"nix", "Module:1"},
{"gomod", "Module:1"},
{"gotemplate", "Module:1"},
- {"graphql", "Module:1"},
- {"prisma", "Module:1"},
- {"thrift", "Module:1"},
- {"capnp", "Module:1"},
- {"smithy", "Module:1"},
- {"wit", "Module:1"},
+ {"graphql", "Class:1,Module:1"},
+ {"prisma", "Class:1,Module:1"},
+ {"thrift", "Function:1,Module:1"},
+ {"capnp", "Class:1,Module:1"},
+ {"smithy", "Class:1,Module:1"},
+ {"wit", "Class:2,Function:1,Module:1"},
{"kdl", "Module:1"},
{"ron", "Module:1"},
{"nickel", "Module:1"},
diff --git a/tests/test_grammar_regression.c b/tests/test_grammar_regression.c
index 528d662f2..4a284984e 100644
--- a/tests/test_grammar_regression.c
+++ b/tests/test_grammar_regression.c
@@ -92,7 +92,7 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
{"ocaml", CBM_LANG_OCAML, "a.ml", "let foo () = 1\nlet bar () = 2\n", 1, {NULL}},
{"odin", CBM_LANG_ODIN, "a.odin", "foo :: proc() {}\nbar :: proc() {}\n", 1, {NULL}},
{"pascal", CBM_LANG_PASCAL, "a.pas", "procedure Foo;\nbegin\nend;\n", 1, {NULL}},
- {"pony", CBM_LANG_PONY, "a.pony", "actor Main\n fun foo(): U32 => 1\n", 0, {NULL}},
+ {"pony", CBM_LANG_PONY, "a.pony", "actor Main\n fun foo(): U32 => 1\n", 2, {"Main", "foo", NULL}},
{"purescript", CBM_LANG_PURESCRIPT, "a.purs", "foo :: Int\nfoo = 1\n", 0, {NULL}},
{"racket", CBM_LANG_RACKET, "a.rkt", "(define (foo) 1)\n(define (bar) 2)\n", 1, {NULL}},
{"rescript", CBM_LANG_RESCRIPT, "a.res", "let foo = () => 1\nlet bar = () => 2\n", 1, {NULL}},
@@ -106,8 +106,8 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
{"elm", CBM_LANG_ELM, "a.elm", "module M exposing (..)\nfoo = 1\n", 0, {NULL}},
{"func", CBM_LANG_FUNC, "a.fc", "() foo() {\n}\n", 0, {NULL}},
{"lean", CBM_LANG_LEAN, "a.lean", "def foo : Nat := 1\ndef bar : Nat := 2\n", 0, {NULL}},
- {"move", CBM_LANG_MOVE, "a.move", "module a::m {\n fun foo() {}\n}\n", 0, {NULL}},
- {"smali", CBM_LANG_SMALI, "A.smali", ".class public LA;\n.method public foo()V\n.end method\n", 0, {NULL}},
+ {"move", CBM_LANG_MOVE, "a.move", "module 0x1::m {\n public fun foo() {}\n}\n", 1, {"foo", NULL}},
+ {"smali", CBM_LANG_SMALI, "A.smali", ".class public LA;\n.super Ljava/lang/Object;\n.method public foo()V\n.end method\n", 2, {"foo", NULL}},
{"systemverilog", CBM_LANG_SYSTEMVERILOG, "a.sv", "module m;\n function int foo(); return 0; endfunction\nendmodule\n", 0, {NULL}},
{"verilog", CBM_LANG_VERILOG, "a.v", "module m;\nendmodule\n", 0, {NULL}},
{"vhdl", CBM_LANG_VHDL, "a.vhd", "entity foo is\nend foo;\n", 0, {NULL}},
@@ -122,14 +122,14 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
{"nasm", CBM_LANG_NASM, "a.asm", "global foo\nfoo:\n ret\n", 0, {NULL}},
{"cfml", CBM_LANG_CFML, "a.cfm", "<cffunction name=\"foo\"></cffunction>\n", 0, {NULL}},
{"cfscript", CBM_LANG_CFSCRIPT, "a.cfc", "component {\n function foo() {}\n}\n", 0, {NULL}},
- {"cobol", CBM_LANG_COBOL, "a.cob", "IDENTIFICATION DIVISION.\nPROGRAM-ID. FOO.\n", 0, {NULL}},
+ {"cobol", CBM_LANG_COBOL, "a.cob", " IDENTIFICATION DIVISION.\n PROGRAM-ID. FOO.\n PROCEDURE DIVISION.\n MAIN-PARA.\n STOP RUN.\n", 1, {"FOO", NULL}},
{"janet", CBM_LANG_JANET, "a.janet", "(defn foo [] 1)\n(defn bar [] 2)\n", 0, {NULL}},
{"magma", CBM_LANG_MAGMA, "a.magma", "function foo()\n return 1;\nend function;\n", 0, {NULL}},
{"qml", CBM_LANG_QML, "a.qml", "import QtQuick\nItem {\n function foo() {}\n}\n", 0, {NULL}},
{"wolfram", CBM_LANG_WOLFRAM, "a.wl", "foo[x_] := x + 1\n", 0, {NULL}},
{"pine", CBM_LANG_PINE, "a.pine", "foo() =>\n 1\n", 0, {NULL}},
{"form", CBM_LANG_FORM, "a.frm", "Symbol x;\nLocal F = x;\n", 0, {NULL}},
- {"protobuf", CBM_LANG_PROTOBUF, "a.proto", "message Foo {\n int32 id = 1;\n}\n", 0, {NULL}},
+ {"protobuf", CBM_LANG_PROTOBUF, "a.proto", "syntax = \"proto3\";\n\nmessage Foo {\n int32 id = 1;\n}\n", 1, {"Foo", NULL}},
{"soql", CBM_LANG_SOQL, "a.soql", "SELECT Id FROM Account\n", 0, {NULL}},
{"sosl", CBM_LANG_SOSL, "a.sosl", "FIND {test} IN ALL FIELDS\n", 0, {NULL}},
{"dotenv", CBM_LANG_DOTENV, "a.env", "FOO=bar\nBAZ=qux\n", 0, {NULL}},
@@ -166,8 +166,8 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
{"prisma", CBM_LANG_PRISMA, "a.prisma", "model Foo {\n id Int @id\n}\n", 0, {NULL}},
{"thrift", CBM_LANG_THRIFT, "a.thrift", "service Foo {\n void ping()\n}\n", 0, {NULL}},
{"capnp", CBM_LANG_CAPNP, "a.capnp", "struct Foo {\n id @0 :Int32;\n}\n", 0, {NULL}},
- {"smithy", CBM_LANG_SMITHY, "a.smithy", "structure Foo {\n id: Integer\n}\n", 0, {NULL}},
- {"wit", CBM_LANG_WIT, "a.wit", "interface foo {\n}\n", 0, {NULL}},
+ {"smithy", CBM_LANG_SMITHY, "a.smithy", "namespace example\n\nstructure Foo {\n id: Integer\n}\n", 1, {"Foo", NULL}},
+ {"wit", CBM_LANG_WIT, "a.wit", "interface i {\n record r { x: u32 }\n enum e { a, b }\n f: func() -> u32;\n}\n", 3, {"r", "e", "f", NULL}},
{"kdl", CBM_LANG_KDL, "a.kdl", "node \"x\" {\n}\n", 0, {NULL}},
{"ron", CBM_LANG_RON, "a.ron", "(a: 1, b: 2)\n", 0, {NULL}},
{"nickel", CBM_LANG_NICKEL, "a.ncl", "{ foo = 1, bar = 2 }\n", 0, {NULL}},