Skip to content

Commit 222e97a

Browse files
committed
Add Mojo language wiring
Signed-off-by: Anand Aiyer <aaiyer@gmail.com>
1 parent 5554f8a commit 222e97a

7 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎internal/cbm/cbm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ typedef enum {
170170
CBM_LANG_QML, // Qt QML (Qt Modeling Language — declarative UI + embedded JS)
171171
CBM_LANG_CFSCRIPT, // CFML script dialect (.cfc components — Lucee/ColdFusion)
172172
CBM_LANG_CFML, // CFML tag dialect (.cfm templates — Lucee/ColdFusion)
173+
CBM_LANG_MOJO, // Mojo
173174
CBM_LANG_COUNT
174175
} CBMLanguage;
175176

‎internal/cbm/lang_specs.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ extern const TSLanguage *tree_sitter_apex(void);
164164
extern const TSLanguage *tree_sitter_soql(void);
165165
extern const TSLanguage *tree_sitter_sosl(void);
166166
extern const TSLanguage *tree_sitter_pine(void);
167+
extern const TSLanguage *tree_sitter_mojo(void);
167168

168169
// -- Empty sentinel --
169170
static const char *empty_types[] = {NULL};
@@ -1596,6 +1597,21 @@ static const char *pine_var_types[] = {"variable_definition_statement",
15961597
static const char *pine_branch_types[] = {"if_statement", "switch_statement", "for_statement",
15971598
"for_in_statement", "while_statement", NULL};
15981599
static const char *pine_assign_types[] = {"reassignment_statement", NULL};
1600+
static const char *mojo_func_types[] = {"function_definition", NULL};
1601+
static const char *mojo_class_types[] = {"class_definition", "trait_definition", NULL};
1602+
static const char *mojo_module_types[] = {"module", NULL};
1603+
static const char *mojo_call_types[] = {"call", NULL};
1604+
static const char *mojo_import_types[] = {"import_statement", "import_from_statement",
1605+
"future_import_statement", NULL};
1606+
static const char *mojo_branch_types[] = {"if_statement",
1607+
"match_statement",
1608+
"for_statement",
1609+
"while_statement",
1610+
"try_statement",
1611+
"with_statement",
1612+
NULL};
1613+
static const char *mojo_var_types[] = {"assignment", NULL};
1614+
static const char *mojo_assign_types[] = {"assignment", "augmented_assignment", NULL};
15991615
// ==================== SPEC TABLE ====================
16001616

16011617
static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
@@ -2571,6 +2587,12 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
25712587
pine_branch_types, pine_var_types, pine_assign_types, empty_types, NULL,
25722588
empty_types, NULL, NULL, tree_sitter_pine, NULL},
25732589

2590+
// CBM_LANG_MOJO
2591+
[CBM_LANG_MOJO] = {CBM_LANG_MOJO, mojo_func_types, mojo_class_types, empty_types,
2592+
mojo_module_types, mojo_call_types, mojo_import_types, mojo_import_types,
2593+
mojo_branch_types, mojo_var_types, mojo_assign_types, empty_types, NULL,
2594+
empty_types, NULL, NULL, tree_sitter_mojo, NULL},
2595+
25742596
};
25752597

25762598
_Static_assert(sizeof(lang_specs) / sizeof(lang_specs[0]) == CBM_LANG_COUNT,

‎src/discover/language.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ static const ext_entry_t EXT_TABLE[] = {
187187
/* Meson */
188188
{".meson", CBM_LANG_MESON},
189189

190+
/* Mojo */
191+
{".mojo", CBM_LANG_MOJO},
192+
190193
/* Nix */
191194
{".nix", CBM_LANG_NIX},
192195

@@ -835,6 +838,7 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = {
835838
[CBM_LANG_APEX] = "Apex",
836839
[CBM_LANG_SOQL] = "SOQL",
837840
[CBM_LANG_SOSL] = "SOSL",
841+
[CBM_LANG_MOJO] = "Mojo",
838842

839843
};
840844

‎src/discover/userconfig.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static const lang_name_entry_t LANG_NAME_TABLE[] = {
118118
{"glsl", CBM_LANG_GLSL},
119119
{"ini", CBM_LANG_INI},
120120
{"matlab", CBM_LANG_MATLAB},
121+
{"mojo", CBM_LANG_MOJO},
121122
{"lean", CBM_LANG_LEAN},
122123
{"form", CBM_LANG_FORM},
123124
{"magma", CBM_LANG_MAGMA},

‎tests/test_grammar_labels.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
151151
{"func", "Function:1,Module:1"},
152152
{"lean", "Function:2,Module:1"},
153153
{"move", "Function:1,Module:1"},
154+
{"mojo", "Class:1,Function:1,Method:1,Module:1"},
154155
{"smali", "Class:1,Function:1,Module:1"},
155156
{"systemverilog", "Class:1,Function:1,Module:1"},
156157
{"verilog", "Class:1,Module:1"},

‎tests/test_grammar_regression.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
196196
"module 0x1::m {\n public fun foo() {}\n}\n",
197197
1,
198198
{"foo", NULL}},
199+
{"mojo",
200+
CBM_LANG_MOJO,
201+
"a.mojo",
202+
"fn foo() -> Int:\n return 1\n\nstruct A:\n fn bar(self) -> Int:\n return foo()\n",
203+
2,
204+
{"foo", "A", NULL}},
199205
{"smali",
200206
CBM_LANG_SMALI,
201207
"A.smali",

‎tests/test_language.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,11 @@ TEST(lang_ext_move) {
956956
PASS();
957957
}
958958

959+
TEST(lang_ext_mojo) {
960+
ASSERT_EQ(cbm_language_for_extension(".mojo"), CBM_LANG_MOJO);
961+
PASS();
962+
}
963+
959964
TEST(lang_ext_squirrel) {
960965
ASSERT_EQ(cbm_language_for_extension(".nut"), CBM_LANG_SQUIRREL);
961966
PASS();
@@ -1271,6 +1276,7 @@ SUITE(language) {
12711276
RUN_TEST(lang_ext_ispc);
12721277
RUN_TEST(lang_ext_cairo);
12731278
RUN_TEST(lang_ext_move);
1279+
RUN_TEST(lang_ext_mojo);
12741280
RUN_TEST(lang_ext_squirrel);
12751281
RUN_TEST(lang_ext_func);
12761282
RUN_TEST(lang_ext_rst);

0 commit comments

Comments
 (0)