-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
syn_highlight.c
184 lines (168 loc) · 6.56 KB
/
syn_highlight.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <string.h>
#include <stdbool.h>
#include "term.h"
#define NELEM(X) (sizeof(X) / sizeof((X)[0]))
// special form token. use in Edlis indentation
static const char *special[] = {
"defun", "defmacro", "defglobal", "defdynamic", "defconstant",
"let", "let*", "plet", "case", "while", "progn", "defmodule",
};
// syntax token
static const char *syntax[] = {
"lambda", "labels", "flet", "let", "let*", "setq", "setf",
"defconstant", "defun", "defmacro", "defglobal", "defdynamic",
"dynamic", "set-dynamic", "function", "function*", "symbol-function",
"class",
"and", "or", "if", "cond", "while", "for", "block", "return-from",
"case", "case-using", "progn", "defclass", "defgeneric", "defgeneric*",
"defmethod", "dynamic-let", "ignore-errors", "catch", "throw",
"tagbody", "go", "unwind-protect", "with-standard-input",
"with-standard-output", "with-error-output", "with-handler",
"convert", "with-open-input-file", "with-open-output-file",
"with-open-io-file", "the", "assure", "time", "trace", "untrace",
"defmodule", "defpublic", "modulesubst",
};
// builtin token
static const char *builtin[] = {
"-", "*", "/=", "+", "<", "<=", "=", ">", ">=",
"abs", "append", "apply", "aref", "arithmetic-error-operands",
"arithmetic-error-operation", "array-dimensions", "assoc", "atan",
"atan2", "atanh", "atom", "basic-array-p", "basic-array*-p",
"basic-vector-p", "call-next-method", "car", "cdr", "ceiling",
"cerror", "char-index", "char/=", "char<", "char<=", "char=",
"char>", "char>=", "characterp", "class-of", "close",
"condition-continuable", "cons", "consp", "continue-condition",
"cos", "cosh", "create-array", "create-list",
"create-string-input-stream",
"create-string-output-stream", "create-string", "create-vector",
"create",
"div", "domain-error-object", "domain-error-expected-class",
"dummyp", "elt", "eq", "eql", "equal", "error-output", "error",
"eval", "exp", "expt", "file-length", "file-position", "finish-output",
"float", "floatp", "floor", "format-char", "format-fresh-line",
"format-float", "format-integer", "format-object", "format-tab",
"format",
"funcall", "functionp", "garef", "gbc", "gcd", "general-array*-p",
"general-vector-p", "generic-function-p", "gensym",
"get-internal-real-time",
"get-internal-run-time",
"get-output-stream-string", "get-universal-time", "hdmp", "identity",
"initialize-object*", "input-stream-p", "instancep", "integerp",
"internal-time-units-per-second", "isqrt", "lcm", "length", "list",
"listp", "load", "log", "map-into", "mapc", "mapcar", "mapcan",
"mapcon", "mapl", "maplist", "max", "member", "min", "mod",
"next-method-p", "not", "nreverse", "null", "numberp",
"open-input-file", "open-io-file", "open-output-file", "open-stream-p",
"output-stream-p", "parse-error-string", "parse-error-expected-class",
"parse-number", "preview-char", "prin1", "print", "probe-file",
"property", "quit", "quotient", "read-byte", "read-char", "read-line",
"read", "reciprocal", "remove-property", "reverse", "round",
"set-aref",
"set-car", "set-cdr", "set-elt", "set-file-position", "set-garef",
"set-property", "signal-condition", "simple-error-format-argument",
"simple-error-format-string", "sin", "sinh", "slot-value", "sqrt",
"standard-input", "standard-output", "stream-error-stream", "streamp",
"stream-ready-p", "string-append", "string-index", "string/=",
"string<", "string<=", "string=", "string>", "string>=", "stringp",
"subclassp",
"subseq", "symbolp", "tan", "tanh", "truncate",
"undefined-entity-name",
"undefined-entity-namespace", "vector", "write-byte", "import",
};
// extended function
static const char *extended[] = {
"random-real", "random", "set-random", "heapdump", "instance",
"nconc", "fast-address", "macroexpand-1", "macroexpand-all",
"backtrace", "subrp", "funcp", "macrop", "fixnump", "longnump",
"bignump", "prof", "create-server-socket", "create-client-socket",
"send-socket", "recv-socket", "close-socket",
"break", "edit", "set-editor", "wiringpi-setup-gpio",
"delay-microseconds", "wiringpi-spi-setup", "digital-write-byte",
"wiringpi-spi-setup-ch-speed", "pwm-set-mode", "pwm-set-range",
"pwm-set-clock", "pin-mode", "digital-write", "digital-read",
"pwm-write", "pull-up-dn-control", "delay-seconds", "compile-file",
"formatter", "line-argument", "getenv", "system",
"c-include", "c-define", "c-lang", "c-option", "try", "read_exp",
"mt-create", "mt-let", "mt-call", "mt-exec", "mt-lock", "mt-close",
"mp-create", "mp-exec", "mp-close", "mp-call", "mp-let", "mp-part",
"mp-report", "mp-eval",
"dp-create", "dp-let", "dp-close", "dp-eval", "dp-transfer",
"dp-load", "dp-compile", "dp-call", "dp-exec", "dp-report", "dp-part",
};
static bool in_syntax_table(const char *str)
{
int i;
for (i = 0; i < (int) NELEM(syntax); i++) {
if (strcmp(syntax[i], str) == 0) {
return true;
}
}
return false;
}
static bool in_builtin_table(const char *str)
{
int i;
for (i = 0; i < (int) NELEM(builtin); i++) {
if (strcmp(builtin[i], str) == 0) {
return true;
}
}
return false;
}
static bool in_extended_table(const char *str)
{
int i;
for (i = 0; i < (int) NELEM(extended); i++) {
if (strcmp(extended[i], str) == 0) {
return true;
}
}
return false;
}
bool in_special_table(const char *str)
{
int i;
for (i = 0; i < (int) NELEM(special); i++) {
if (strcmp(special[i], str) == 0) {
return true;
}
}
return false;
}
enum HighlightToken maybe_match(const char *str)
{
if (in_syntax_table(str)) {
return HIGHLIGHT_SYNTAX;
}
if (in_builtin_table(str)) {
return HIGHLIGHT_BUILTIN;
}
if (in_extended_table(str)) {
return HIGHLIGHT_EXTENDED;
}
return HIGHLIGHT_NONE;
}
void
gather_fuzzy_matches(const char *str, const char *candidates[],
int *candidate_pt)
{
int i;
for (i = 0; i < (int) NELEM(syntax); i++) {
if (strstr(syntax[i], str) != NULL && syntax[i][0] == str[0]) {
candidates[*candidate_pt] = syntax[i];
*candidate_pt = (*candidate_pt) + 1;
}
}
for (i = 0; i < (int) NELEM(builtin); i++) {
if (strstr(builtin[i], str) != NULL && builtin[i][0] == str[0]) {
candidates[*candidate_pt] = builtin[i];
*candidate_pt = (*candidate_pt) + 1;
}
}
for (i = 0; i < (int) NELEM(extended); i++) {
if (strstr(extended[i], str) != NULL && extended[i][0] == str[0]) {
candidates[*candidate_pt] = extended[i];
*candidate_pt = (*candidate_pt) + 1;
}
}
}