Skip to content

Commit 8e332bc

Browse files
committed
fix(purescript): extract exp_apply callees so function applications form CALLS edges
PureScript function application (greet "world", log (...)) is an exp_apply node whose function head is an exp_name child — extract_fp_callee only handled apply/application_expression, and PureScript wasn't routed to it, so the callee was never extracted and no call to greet was found. Route PureScript through extract_fp_callee (like Haskell/OCaml) and teach it exp_apply: the head is an exp_name (its text is the qualified function name), and curried applications nest exp_apply, so descend the function head to recover the leftmost callee. Haskell/OCaml apply handling is unchanged. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 4221316 commit 8e332bc

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎internal/cbm/extract_calls.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,24 @@ static char *extract_callee_from_fields(CBMArena *a, TSNode node, const char *so
322322

323323
// Haskell/OCaml: extract callee from apply/infix nodes.
324324
static char *extract_fp_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
325-
if (strcmp(nk, "apply") == 0 || strcmp(nk, "application_expression") == 0) {
325+
if (strcmp(nk, "apply") == 0 || strcmp(nk, "application_expression") == 0 ||
326+
strcmp(nk, "exp_apply") == 0) {
326327
if (ts_node_child_count(node) > 0) {
327328
TSNode callee = ts_node_child(node, 0);
328329
const char *ck = ts_node_type(callee);
329330
if (strcmp(ck, "identifier") == 0 || strcmp(ck, "variable") == 0 ||
330-
strcmp(ck, "constructor") == 0 || strcmp(ck, "value_path") == 0) {
331+
strcmp(ck, "constructor") == 0 || strcmp(ck, "value_path") == 0 ||
332+
/* PureScript: exp_apply's function head is an `exp_name` whose
333+
* text is the (possibly qualified) function name. */
334+
strcmp(ck, "exp_name") == 0) {
331335
return cbm_node_text(a, callee, source);
332336
}
337+
/* Curried application `f a b` nests exp_apply/apply — descend the
338+
* function head to recover the leftmost callee. */
339+
if (strcmp(ck, "exp_apply") == 0 || strcmp(ck, "apply") == 0 ||
340+
strcmp(ck, "application_expression") == 0) {
341+
return extract_fp_callee(a, callee, source, ck);
342+
}
333343
}
334344
}
335345
if (strcmp(nk, "infix") == 0 || strcmp(nk, "infix_expression") == 0) {
@@ -1081,7 +1091,7 @@ static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *
10811091
if (lang == CBM_LANG_ERLANG) {
10821092
return extract_erlang_callee(a, node, source, nk);
10831093
}
1084-
if (lang == CBM_LANG_HASKELL || lang == CBM_LANG_OCAML) {
1094+
if (lang == CBM_LANG_HASKELL || lang == CBM_LANG_OCAML || lang == CBM_LANG_PURESCRIPT) {
10851095
return extract_fp_callee(a, node, source, nk);
10861096
}
10871097
if (lang == CBM_LANG_WOLFRAM && strcmp(nk, "apply") == 0) {

0 commit comments

Comments
 (0)