Skip to content

Commit 621a2af

Browse files
committed
add some zig highlighting
1 parent 66b7d81 commit 621a2af

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Diff for: ce.c

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static struct {
4444
{ ".tex", CE_FILE_TYPE_LATEX },
4545
{ ".latex", CE_FILE_TYPE_LATEX },
4646
{ ".lua", CE_FILE_TYPE_LUA },
47+
{ ".zig", CE_FILE_TYPE_ZIG },
4748
{ NULL, 0 },
4849
};
4950

Diff for: ce.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
#define CE_FILE_TYPE_GO 12
9696
#define CE_FILE_TYPE_LATEX 13
9797
#define CE_FILE_TYPE_LUA 14
98+
#define CE_FILE_TYPE_ZIG 15
9899

99100
#define CE_TAB_WIDTH_DEFAULT 8
100101
#define CE_TAB_EXPAND_DEFAULT 0

Diff for: syntax.c

+38
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static int syntax_highlight_c_label(struct state *);
9191
static int syntax_highlight_c_comment(struct state *);
9292
static int syntax_highlight_c_preproc(struct state *);
9393

94+
static void syntax_highlight_zig(struct state *);
95+
9496
static void syntax_highlight_lua(struct state *);
9597
static int syntax_highlight_lua_comment(struct state *);
9698

@@ -233,6 +235,20 @@ static const char *go_kw[] = {
233235
"for", "import", "return", "var", NULL
234236
};
235237

238+
/* I really should add macro support to my editor.... */
239+
static const char *zig_kw[] = {
240+
"addrspace", "align", "and", "asm", "async",
241+
"await", "break", "catch", "comptime", "const",
242+
"continue", "defer", "else", "enum", "errdefer",
243+
"error", "export", "extern", "for", "if", "inline",
244+
"noalias", "noinline", "nosuspend", "opaque", "or",
245+
"orelse", "packed", "anyframe", "pub", "resume", "return",
246+
"linksection", "callconv", "struct", "suspend", "switch",
247+
"test", "threadlocal", "try", "union", "unreachable", "usingnamespace",
248+
"var", "volatile", "allowzero", "while", "anytype", "fn",
249+
NULL
250+
};
251+
236252
enum {
237253
SYNTAX_COLOR_BLACK = 0,
238254
SYNTAX_COLOR_RED,
@@ -400,6 +416,9 @@ ce_syntax_write(struct cebuf *buf, struct celine *line, size_t index,
400416
case CE_FILE_TYPE_LUA:
401417
syntax_highlight_lua(&syntax_state);
402418
break;
419+
case CE_FILE_TYPE_ZIG:
420+
syntax_highlight_zig(&syntax_state);
421+
break;
403422
default:
404423
syntax_state_color_clear(&syntax_state);
405424
syntax_write(&syntax_state, 1);
@@ -1132,6 +1151,25 @@ syntax_highlight_lua_comment(struct state *state)
11321151
return (-1);
11331152
}
11341153

1154+
static void
1155+
syntax_highlight_zig(struct state *state)
1156+
{
1157+
if (syntax_highlight_c_comment(state) == 0)
1158+
return;
1159+
1160+
if (syntax_highlight_numeric(state) == 0)
1161+
return;
1162+
1163+
if (syntax_highlight_string(state) == 0)
1164+
return;
1165+
1166+
if (syntax_highlight_word(state, zig_kw) == 0)
1167+
return;
1168+
1169+
syntax_state_color_clear(state);
1170+
syntax_write(state, 1);
1171+
}
1172+
11351173
static void
11361174
syntax_highlight_shell(struct state *state)
11371175
{

0 commit comments

Comments
 (0)