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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cbm/cbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ typedef enum {
CBM_LANG_QML, // Qt QML (Qt Modeling Language — declarative UI + embedded JS)
CBM_LANG_CFSCRIPT, // CFML script dialect (.cfc components — Lucee/ColdFusion)
CBM_LANG_CFML, // CFML tag dialect (.cfm templates — Lucee/ColdFusion)
CBM_LANG_MOJO, // Mojo
CBM_LANG_COUNT
} CBMLanguage;

Expand Down
22 changes: 22 additions & 0 deletions internal/cbm/lang_specs.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ extern const TSLanguage *tree_sitter_apex(void);
extern const TSLanguage *tree_sitter_soql(void);
extern const TSLanguage *tree_sitter_sosl(void);
extern const TSLanguage *tree_sitter_pine(void);
extern const TSLanguage *tree_sitter_mojo(void);

// -- Empty sentinel --
static const char *empty_types[] = {NULL};
Expand Down Expand Up @@ -1596,6 +1597,21 @@ static const char *pine_var_types[] = {"variable_definition_statement",
static const char *pine_branch_types[] = {"if_statement", "switch_statement", "for_statement",
"for_in_statement", "while_statement", NULL};
static const char *pine_assign_types[] = {"reassignment_statement", NULL};
static const char *mojo_func_types[] = {"function_definition", NULL};
static const char *mojo_class_types[] = {"class_definition", "trait_definition", NULL};
static const char *mojo_module_types[] = {"module", NULL};
static const char *mojo_call_types[] = {"call", NULL};
static const char *mojo_import_types[] = {"import_statement", "import_from_statement",
"future_import_statement", NULL};
static const char *mojo_branch_types[] = {"if_statement",
"match_statement",
"for_statement",
"while_statement",
"try_statement",
"with_statement",
NULL};
static const char *mojo_var_types[] = {"assignment", NULL};
static const char *mojo_assign_types[] = {"assignment", "augmented_assignment", NULL};
// ==================== SPEC TABLE ====================

static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
Expand Down Expand Up @@ -2571,6 +2587,12 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
pine_branch_types, pine_var_types, pine_assign_types, empty_types, NULL,
empty_types, NULL, NULL, tree_sitter_pine, NULL},

// CBM_LANG_MOJO
[CBM_LANG_MOJO] = {CBM_LANG_MOJO, mojo_func_types, mojo_class_types, empty_types,
mojo_module_types, mojo_call_types, mojo_import_types, mojo_import_types,
mojo_branch_types, mojo_var_types, mojo_assign_types, empty_types, NULL,
empty_types, NULL, NULL, tree_sitter_mojo, NULL},

};

_Static_assert(sizeof(lang_specs) / sizeof(lang_specs[0]) == CBM_LANG_COUNT,
Expand Down
4 changes: 4 additions & 0 deletions src/discover/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ static const ext_entry_t EXT_TABLE[] = {
/* Meson */
{".meson", CBM_LANG_MESON},

/* Mojo */
{".mojo", CBM_LANG_MOJO},

/* Nix */
{".nix", CBM_LANG_NIX},

Expand Down Expand Up @@ -835,6 +838,7 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = {
[CBM_LANG_APEX] = "Apex",
[CBM_LANG_SOQL] = "SOQL",
[CBM_LANG_SOSL] = "SOSL",
[CBM_LANG_MOJO] = "Mojo",

};

Expand Down
1 change: 1 addition & 0 deletions src/discover/userconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static const lang_name_entry_t LANG_NAME_TABLE[] = {
{"glsl", CBM_LANG_GLSL},
{"ini", CBM_LANG_INI},
{"matlab", CBM_LANG_MATLAB},
{"mojo", CBM_LANG_MOJO},
{"lean", CBM_LANG_LEAN},
{"form", CBM_LANG_FORM},
{"magma", CBM_LANG_MAGMA},
Expand Down
1 change: 1 addition & 0 deletions tests/test_grammar_labels.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"func", "Function:1,Module:1"},
{"lean", "Function:2,Module:1"},
{"move", "Function:1,Module:1"},
{"mojo", "Class:1,Function:1,Method:1,Module:1"},
{"smali", "Class:1,Function:1,Module:1"},
{"systemverilog", "Class:1,Function:1,Module:1"},
{"verilog", "Class:1,Module:1"},
Expand Down
6 changes: 6 additions & 0 deletions tests/test_grammar_regression.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
"module 0x1::m {\n public fun foo() {}\n}\n",
1,
{"foo", NULL}},
{"mojo",
CBM_LANG_MOJO,
"a.mojo",
"fn foo() -> Int:\n return 1\n\nstruct A:\n fn bar(self) -> Int:\n return foo()\n",
2,
{"foo", "A", NULL}},
{"smali",
CBM_LANG_SMALI,
"A.smali",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_language.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ TEST(lang_ext_move) {
PASS();
}

TEST(lang_ext_mojo) {
ASSERT_EQ(cbm_language_for_extension(".mojo"), CBM_LANG_MOJO);
PASS();
}

TEST(lang_ext_squirrel) {
ASSERT_EQ(cbm_language_for_extension(".nut"), CBM_LANG_SQUIRREL);
PASS();
Expand Down Expand Up @@ -1271,6 +1276,7 @@ SUITE(language) {
RUN_TEST(lang_ext_ispc);
RUN_TEST(lang_ext_cairo);
RUN_TEST(lang_ext_move);
RUN_TEST(lang_ext_mojo);
RUN_TEST(lang_ext_squirrel);
RUN_TEST(lang_ext_func);
RUN_TEST(lang_ext_rst);
Expand Down
Loading