Skip to content

Commit 1e1d408

Browse files
author
Martin Vogel
committed
feat(lang): add CFML / ColdFusion support (cfscript + tag dialects)
Vendor the MIT-licensed cfmleditor/tree-sitter-cfml grammars and wire both CFML dialects through the pipeline: - .cfc components -> cfscript grammar (CBM_LANG_CFSCRIPT): a JS-like grammar, so function/method declarations, calls and imports extract with the shared JS/TS arrays. Components' functions become Function nodes. - .cfm templates -> cfml tag grammar (CBM_LANG_CFML): tag-based (HTML-derived). Embedded <cfscript> functions extract via function_declaration; tag-based <cffunction name="..."> nodes are handled by a dedicated walker branch that reads the name attribute (cf_function_tag has no name field). Shared scanner headers are vendored at vendored/common/ so the grammar's ../../common/ includes resolve without editing vendored sources. Adds an ASCII case-insensitive compare for CFML's case-insensitive attributes. Tests cover both dialects and the extension mapping. LICENSEs vendored. Closes #38
1 parent f16f9dc commit 1e1d408

26 files changed

Lines changed: 674358 additions & 0 deletions

File tree

‎internal/cbm/cbm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ typedef enum {
168168
CBM_LANG_K8S, // Generic Kubernetes manifest (apiVersion: detected)
169169
CBM_LANG_PINE, // Pine Script (TradingView indicator / strategy language)
170170
CBM_LANG_QML, // Qt QML (Qt Modeling Language — declarative UI + embedded JS)
171+
CBM_LANG_CFSCRIPT, // CFML script dialect (.cfc components — Lucee/ColdFusion)
172+
CBM_LANG_CFML, // CFML tag dialect (.cfm templates — Lucee/ColdFusion)
171173
CBM_LANG_COUNT
172174
} CBMLanguage;
173175

‎internal/cbm/extract_defs.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,67 @@ static void push_class_body_children(TSNode node, const CBMLangSpec *spec, walk_
36133613
}
36143614
}
36153615

3616+
// ASCII case-insensitive equality vs a lowercase literal (CFML attribute names
3617+
// are case-insensitive, e.g. NAME / Name / name).
3618+
static bool ascii_ci_equals(const char *s, const char *lower_lit) {
3619+
if (!s) {
3620+
return false;
3621+
}
3622+
for (; *s && *lower_lit; s++, lower_lit++) {
3623+
if (tolower((unsigned char)*s) != (unsigned char)*lower_lit) {
3624+
return false;
3625+
}
3626+
}
3627+
return *s == '\0' && *lower_lit == '\0';
3628+
}
3629+
3630+
// CFML tag function: <cffunction name="foo" ...> ... </cffunction> (#38). The
3631+
// cf_function_tag node has no `name` field — the name lives in a cf_attribute
3632+
// child (name="foo"). Emit a Function node named after that attribute value.
3633+
static void extract_cfml_function_tag(CBMExtractCtx *ctx, TSNode node) {
3634+
CBMArena *a = ctx->arena;
3635+
char *name = NULL;
3636+
uint32_t cc = ts_node_named_child_count(node);
3637+
for (uint32_t i = 0; i < cc && !name; i++) {
3638+
TSNode ch = ts_node_named_child(node, i);
3639+
if (strcmp(ts_node_type(ch), "cf_attribute") != 0) {
3640+
continue;
3641+
}
3642+
TSNode an = cbm_find_child_by_kind(ch, "cf_attribute_name");
3643+
if (ts_node_is_null(an)) {
3644+
continue;
3645+
}
3646+
char *aname = cbm_node_text(a, an, ctx->source);
3647+
if (!ascii_ci_equals(aname, "name")) {
3648+
continue;
3649+
}
3650+
TSNode val = cbm_find_child_by_kind(ch, "quoted_cf_attribute_value");
3651+
if (ts_node_is_null(val)) {
3652+
val = cbm_find_child_by_kind(ch, "cf_attribute_value");
3653+
}
3654+
if (ts_node_is_null(val)) {
3655+
continue;
3656+
}
3657+
TSNode inner = cbm_find_child_by_kind(val, "attribute_value");
3658+
name = cbm_node_text(a, ts_node_is_null(inner) ? val : inner, ctx->source);
3659+
}
3660+
if (!name || !name[0]) {
3661+
return;
3662+
}
3663+
3664+
CBMDefinition def;
3665+
memset(&def, 0, sizeof(def));
3666+
def.name = name;
3667+
def.qualified_name = cbm_fqn_compute(a, ctx->project, ctx->rel_path, name);
3668+
def.label = "Function";
3669+
def.file_path = ctx->rel_path;
3670+
def.start_line = ts_node_start_point(node).row + TS_LINE_OFFSET;
3671+
def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET;
3672+
def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);
3673+
def.is_exported = true;
3674+
cbm_defs_push(&ctx->result->defs, a, def);
3675+
}
3676+
36163677
// Languages that use the C preprocessor and therefore have #define macros.
36173678
static bool is_c_preprocessor_lang(CBMLanguage lang) {
36183679
return lang == CBM_LANG_C || lang == CBM_LANG_CPP || lang == CBM_LANG_CUDA ||
@@ -3677,6 +3738,11 @@ static void walk_defs(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec,
36773738
continue; // the macro body is a preproc_arg — nothing more to extract
36783739
}
36793740

3741+
if (ctx->language == CBM_LANG_CFML && strcmp(kind, "cf_function_tag") == 0) {
3742+
extract_cfml_function_tag(ctx, node);
3743+
// fall through: descend into the body for nested tags / calls
3744+
}
3745+
36803746
if (cbm_kind_in_set(node, spec->function_node_types)) {
36813747
if (!is_template_class_node(node, ctx->language)) {
36823748
extract_func_def(ctx, node, spec);

‎internal/cbm/grammar_cfml.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Vendored tree-sitter grammar: cfml (CFML tag dialect — .cfm templates)
2+
// Each grammar compiled as separate unit (conflicting static symbols).
3+
// scanner.c pulls in the shared ../../common/scanner.h (and tag.h), which is
4+
// all-static; tag.c is therefore NOT included here (it would redefine it).
5+
#include "vendored/grammars/cfml/parser.c"
6+
#include "vendored/grammars/cfml/scanner.c"

‎internal/cbm/grammar_cfscript.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Vendored tree-sitter grammar: cfscript (CFML script dialect — .cfc components)
2+
// Each grammar compiled as separate unit (conflicting static symbols).
3+
#include "vendored/grammars/cfscript/parser.c"
4+
#include "vendored/grammars/cfscript/scanner.c"

‎internal/cbm/lang_specs.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ extern const TSLanguage *tree_sitter_hare(void);
9999
extern const TSLanguage *tree_sitter_pony(void);
100100
extern const TSLanguage *tree_sitter_luau(void);
101101
extern const TSLanguage *tree_sitter_qmljs(void);
102+
extern const TSLanguage *tree_sitter_cfscript(void);
103+
extern const TSLanguage *tree_sitter_cfml(void);
102104
extern const TSLanguage *tree_sitter_janet_simple(void);
103105
extern const TSLanguage *tree_sitter_sway(void);
104106
extern const TSLanguage *tree_sitter_nasm(void);
@@ -264,6 +266,26 @@ static const char *qml_field_types[] = {"ui_property", "ui_signal", "public_fiel
264266
NULL};
265267
static const char *qml_import_types[] = {"import_statement", "import", "ui_import", NULL};
266268

269+
// ==================== CFScript (CFML .cfc script dialect) ====================
270+
// JS-like grammar: components contain function/method declarations. Reuses the
271+
// JS call/branch/var/module arrays.
272+
static const char *cfscript_func_types[] = {"function_declaration", "function_expression",
273+
"arrow_function", "method_definition", NULL};
274+
static const char *cfscript_field_types[] = {"property_declaration", NULL};
275+
static const char *cfscript_import_types[] = {"import_statement", "import", NULL};
276+
277+
// ==================== CFML (tag dialect — .cfm templates) ====================
278+
// Tag-based grammar (HTML-derived). Embedded <cfscript> functions appear as
279+
// function_declaration/function_expression; tag <cffunction> nodes
280+
// (cf_function_tag) are handled separately in the definition walker because
281+
// their name lives in a cf_attribute rather than a `name` field.
282+
static const char *cfml_func_types[] = {"function_declaration", "function_expression", NULL};
283+
static const char *cfml_call_types[] = {"call_expression", NULL};
284+
static const char *cfml_branch_types[] = {
285+
"cf_if_tag", "cf_elseif_tag", "cf_else_tag", "if_statement",
286+
"for_statement", "while_statement", "switch_statement", NULL};
287+
static const char *cfml_module_types[] = {"program", "component_file", NULL};
288+
267289
// ==================== RUST ====================
268290
static const char *rust_func_types[] = {"function_item", "function_signature_item",
269291
"closure_expression", NULL};
@@ -1960,6 +1982,19 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
19601982
(const char *[]){"assignment_expression", "augmented_assignment_expression", NULL},
19611983
js_throw_types, NULL, ts_decorator_types, NULL, NULL, tree_sitter_qmljs, NULL},
19621984

1985+
// CBM_LANG_CFSCRIPT
1986+
[CBM_LANG_CFSCRIPT] =
1987+
{CBM_LANG_CFSCRIPT, cfscript_func_types, empty_types, cfscript_field_types, js_module_types,
1988+
js_call_types, cfscript_import_types, cfscript_import_types, js_branch_types, js_var_types,
1989+
(const char *[]){"assignment_expression", "augmented_assignment_expression", NULL},
1990+
js_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_cfscript, NULL},
1991+
1992+
// CBM_LANG_CFML
1993+
[CBM_LANG_CFML] = {CBM_LANG_CFML, cfml_func_types, empty_types, empty_types, cfml_module_types,
1994+
cfml_call_types, empty_types, empty_types, cfml_branch_types, empty_types,
1995+
empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_cfml,
1996+
NULL},
1997+
19631998
// CBM_LANG_GLEAM
19641999
[CBM_LANG_GLEAM] = {CBM_LANG_GLEAM, gleam_func_types, gleam_class_types, gleam_field_types,
19652000
gleam_module_types, gleam_call_types, gleam_import_types, empty_types,

0 commit comments

Comments
 (0)