| 1 |
|
| /* |
| 2 |
|
| * eshu_ts.h — TypeScript indentation scanner |
| 3 |
|
| * |
| 4 |
|
| * TypeScript is a strict superset of JavaScript. The indentation model is |
| 5 |
|
| * identical to eshu_js.h — all JS scanner states, template literal tracking, |
| 6 |
|
| * and regex detection carry over unchanged. This file provides a thin |
| 7 |
|
| * eshu_ts_ctx_t typedef and a dedicated eshu_indent_ts() entry-point. |
| 8 |
|
| */ |
| 9 |
|
| |
| 10 |
|
| #ifndef ESHU_TS_H |
| 11 |
|
| #define ESHU_TS_H |
| 12 |
|
| |
| 13 |
|
| #include "eshu.h" |
| 14 |
|
| #include "eshu_js.h" |
| 15 |
|
| |
| 16 |
|
| /* TypeScript is JS + type annotations; reuse JS context verbatim. */ |
| 17 |
|
| typedef eshu_js_ctx_t eshu_ts_ctx_t; |
| 18 |
|
| |
| 19 |
75 |
| static void eshu_ts_ctx_init(eshu_ts_ctx_t *ctx, const eshu_config_t *cfg) { |
| 20 |
75 |
| eshu_js_ctx_init(ctx, cfg); |
| 21 |
75 |
| } |
| 22 |
|
| |
| 23 |
75 |
| static char *eshu_indent_ts(const char *src, size_t src_len, |
| 24 |
|
| const eshu_config_t *cfg, size_t *out_len) { |
| 25 |
|
| eshu_ts_ctx_t ctx; |
| 26 |
|
| eshu_buf_t out; |
| 27 |
75 |
| const char *p = src; |
| 28 |
75 |
| const char *end = src + src_len; |
| 29 |
75 |
| int line_num = 1; |
| 30 |
|
| |
| 31 |
75 |
| eshu_ts_ctx_init(&ctx, cfg); |
| 32 |
75 |
| ctx.cfg.lang = ESHU_LANG_TS; |
| 33 |
75 |
| eshu_buf_init(&out, src_len + 256); |
| 34 |
|
| |
| 35 |
696 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
621 |
75 |
696 |
|
| 36 |
621 |
| const char *eol = eshu_find_eol(p); |
| 37 |
621 |
▶ | if (eshu_in_range(cfg, line_num)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_in_range(cfg, line_num)) { |
621 |
0 |
621 |
|
| 38 |
621 |
| eshu_js_process_line((eshu_js_ctx_t *)&ctx, &out, p, eol); |
| 39 |
|
| } else { |
| 40 |
0 |
| size_t saved = out.len; |
| 41 |
0 |
| eshu_js_process_line((eshu_js_ctx_t *)&ctx, &out, p, eol); |
| 42 |
0 |
| out.len = saved; |
| 43 |
0 |
| eshu_buf_write_trimmed(&out, p, (int)(eol - p)); |
| 44 |
0 |
| eshu_buf_putc(&out, '\n'); |
| 45 |
|
| } |
| 46 |
621 |
| p = eol; |
| 47 |
621 |
▶ | if (*p == '\n') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\n') p++; |
621 |
0 |
621 |
|
| 48 |
621 |
| line_num++; |
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
75 |
| eshu_buf_putc(&out, '\0'); |
| 52 |
75 |
| out.len--; |
| 53 |
75 |
| *out_len = out.len; |
| 54 |
75 |
| return out.data; |
| 55 |
|
| } |
| 56 |
|
| |
| 57 |
|
| |
| 58 |
|
| #include "eshu_hl_util.h" |
| 59 |
|
| |
| 60 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 61 |
|
| * TypeScript highlighter |
| 62 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 63 |
|
| |
| 64 |
|
| static const char * const eshu_hl_ts_kw[] = { |
| 65 |
|
| /* JS keywords */ |
| 66 |
|
| "async", "await", |
| 67 |
|
| "break", |
| 68 |
|
| "case", "catch", "class", "const", "continue", |
| 69 |
|
| "debugger", "default", "delete", "do", |
| 70 |
|
| "else", "export", "extends", |
| 71 |
|
| "false", "finally", "for", "function", |
| 72 |
|
| "get", |
| 73 |
|
| "if", "import", "in", "instanceof", |
| 74 |
|
| "let", |
| 75 |
|
| "new", "null", |
| 76 |
|
| "of", |
| 77 |
|
| "return", |
| 78 |
|
| "set", "static", "super", "switch", |
| 79 |
|
| "this", "throw", "true", "try", "typeof", |
| 80 |
|
| "undefined", |
| 81 |
|
| "var", "void", |
| 82 |
|
| "while", "with", |
| 83 |
|
| "yield", |
| 84 |
|
| "Infinity", "NaN", |
| 85 |
|
| /* TS-only keywords */ |
| 86 |
|
| "abstract", "any", "as", "asserts", "bigint", "boolean", |
| 87 |
|
| "declare", "enum", "from", "implements", "infer", "interface", |
| 88 |
|
| "is", "keyof", "module", "namespace", "never", "number", "object", |
| 89 |
|
| "override", "private", "protected", "public", "readonly", |
| 90 |
|
| "satisfies", "string", "symbol", "type", "unique", "unknown", |
| 91 |
|
| "defined?", |
| 92 |
|
| NULL |
| 93 |
|
| }; |
| 94 |
|
| |
| 95 |
|
| static const char * const eshu_hl_ts_bi[] = { |
| 96 |
|
| /* JS builtins */ |
| 97 |
|
| "Array", "ArrayBuffer", "Boolean", "DataView", "Date", "Error", |
| 98 |
|
| "Float32Array", "Float64Array", "Function", "Generator", |
| 99 |
|
| "Int8Array", "Int16Array", "Int32Array", |
| 100 |
|
| "Map", "Math", "Number", "Object", "Promise", "Proxy", |
| 101 |
|
| "RangeError", "ReferenceError", "RegExp", "Set", "String", |
| 102 |
|
| "Symbol", "SyntaxError", "TypeError", "Uint8Array", |
| 103 |
|
| "Uint16Array", "Uint32Array", "URIError", "WeakMap", "WeakSet", |
| 104 |
|
| "JSON", "console", "document", "window", "globalThis", |
| 105 |
|
| /* TS utility types */ |
| 106 |
|
| "Partial", "Required", "Readonly", "Record", "Pick", "Omit", |
| 107 |
|
| "Exclude", "Extract", "NonNullable", "ReturnType", "InstanceType", |
| 108 |
|
| "Parameters", "ConstructorParameters", "Awaited", |
| 109 |
|
| NULL |
| 110 |
|
| }; |
| 111 |
|
| |
| 112 |
53 |
| static char *eshu_highlight_ts(const char *src, size_t src_len, size_t *out_len) { |
| 113 |
|
| eshu_buf_t out; |
| 114 |
53 |
| const char *p = src; |
| 115 |
53 |
| const char *end = src + src_len; |
| 116 |
53 |
| const char *plain = p; |
| 117 |
53 |
| int last_val = 0; |
| 118 |
53 |
| int tmpl_depth = 0; |
| 119 |
|
| |
| 120 |
53 |
| eshu_buf_init(&out, src_len * 2 + 64); |
| 121 |
|
| |
| 122 |
|
| #define TS_SPAN(cls, ts, te) do { \ |
| 123 |
|
| eshu_hl_flush(&out, plain, (ts)); \ |
| 124 |
|
| eshu_hl_span(&out, (cls), (ts), (te)); \ |
| 125 |
|
| p = (te); plain = p; \ |
| 126 |
|
| } while(0) |
| 127 |
|
| |
| 128 |
492 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
439 |
53 |
492 |
|
| 129 |
439 |
| char c = *p; |
| 130 |
|
| |
| 131 |
|
| /* line comment */ |
| 132 |
439 |
▶ | if (c == '/' && p+1 < end && *(p+1) == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '/' && p+1 < end && *(p+1) == '/') { |
1 |
438 |
439 |
| if (c == '/' && p+1 < end && *(p+1) == '/') { |
1 |
0 |
1 |
| if (c == '/' && p+1 < end && *(p+1) == '/') { |
1 |
0 |
1 |
|
| 133 |
1 |
| const char *ts = p; |
| 134 |
13 |
▶ | while (p < end && *p != '\n') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\n') p++; |
12 |
1 |
13 |
| while (p < end && *p != '\n') p++; |
12 |
0 |
12 |
|
| 135 |
1 |
| TS_SPAN("esh-c", ts, p); |
| 136 |
1 |
| continue; |
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
|
| /* block comment */ |
| 140 |
438 |
▶ | if (c == '/' && p+1 < end && *(p+1) == '*') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '/' && p+1 < end && *(p+1) == '*') { |
0 |
438 |
438 |
| if (c == '/' && p+1 < end && *(p+1) == '*') { |
0 |
0 |
0 |
| if (c == '/' && p+1 < end && *(p+1) == '*') { |
0 |
0 |
0 |
|
| 141 |
0 |
| const char *ts = p; |
| 142 |
0 |
| p += 2; |
| 143 |
0 |
▶ | while (p+1 < end && !(*p == '*' && *(p+1) == '/')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p+1 < end && !(*p == '*' && *(p+1) == '/')) p++; |
0 |
0 |
0 |
| while (p+1 < end && !(*p == '*' && *(p+1) == '/')) p++; |
0 |
0 |
0 |
| while (p+1 < end && !(*p == '*' && *(p+1) == '/')) p++; |
0 |
0 |
0 |
|
| 144 |
0 |
▶ | if (p+1 < end) p += 2; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p+1 < end) p += 2; |
0 |
0 |
0 |
|
| 145 |
0 |
| TS_SPAN("esh-c", ts, p); |
| 146 |
0 |
| continue; |
| 147 |
|
| } |
| 148 |
|
| |
| 149 |
|
| /* template literal */ |
| 150 |
438 |
▶ | if (c == '`' || (tmpl_depth > 0 && c == '}')) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '`' || (tmpl_depth > 0 && c == '}')) { |
438 |
0 |
438 |
| if (c == '`' || (tmpl_depth > 0 && c == '}')) { |
0 |
438 |
438 |
| if (c == '`' || (tmpl_depth > 0 && c == '}')) { |
0 |
0 |
0 |
|
| 151 |
0 |
| const char *ts = p++; |
| 152 |
0 |
▶ | if (c == '}' && tmpl_depth > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '}' && tmpl_depth > 0) { |
0 |
0 |
0 |
| if (c == '}' && tmpl_depth > 0) { |
0 |
0 |
0 |
|
| 153 |
|
| /* closing ${ interpolation — resume template */ |
| 154 |
0 |
| tmpl_depth--; |
| 155 |
|
| } |
| 156 |
0 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
0 |
0 |
0 |
|
| 157 |
0 |
▶ | if (*p == '\\' && p+1 < end) { p += 2; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\' && p+1 < end) { p += 2; continue; } |
0 |
0 |
0 |
| if (*p == '\\' && p+1 < end) { p += 2; continue; } |
0 |
0 |
0 |
|
| 158 |
0 |
▶ | if (*p == '$' && p+1 < end && *(p+1) == '{') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*p == '$' && p+1 < end && *(p+1) == '{') { |
0 |
0 |
0 |
| if (*p == '$' && p+1 < end && *(p+1) == '{') { |
0 |
0 |
0 |
| if (*p == '$' && p+1 < end && *(p+1) == '{') { |
0 |
0 |
0 |
|
| 159 |
0 |
| p += 2; tmpl_depth++; |
| 160 |
0 |
| break; |
| 161 |
|
| } |
| 162 |
0 |
▶ | if (*p == '`') { p++; break; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '`') { p++; break; } |
0 |
0 |
0 |
|
| 163 |
0 |
| p++; |
| 164 |
|
| } |
| 165 |
0 |
| TS_SPAN("esh-s", ts, p); |
| 166 |
0 |
| last_val = 1; |
| 167 |
0 |
| continue; |
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
|
| /* double-quoted string */ |
| 171 |
438 |
▶ | if (c == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '"') { |
8 |
430 |
438 |
|
| 172 |
8 |
| const char *ts = p++; |
| 173 |
40 |
▶ | while (p < end && *p != '"' && *p != '\n') { |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && *p != '"' && *p != '\n') { |
40 |
0 |
40 |
| while (p < end && *p != '"' && *p != '\n') { |
32 |
8 |
40 |
| while (p < end && *p != '"' && *p != '\n') { |
32 |
0 |
32 |
|
| 174 |
32 |
▶ | if (*p == '\\' && p+1 < end) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\' && p+1 < end) p++; |
0 |
32 |
32 |
| if (*p == '\\' && p+1 < end) p++; |
0 |
0 |
0 |
|
| 175 |
32 |
| p++; |
| 176 |
|
| } |
| 177 |
8 |
▶ | if (p < end && *p == '"') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '"') p++; |
8 |
0 |
8 |
| if (p < end && *p == '"') p++; |
8 |
0 |
8 |
|
| 178 |
8 |
| TS_SPAN("esh-s", ts, p); |
| 179 |
8 |
| last_val = 1; |
| 180 |
8 |
| continue; |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
|
| /* single-quoted string */ |
| 184 |
430 |
▶ | if (c == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '\'') { |
1 |
429 |
430 |
|
| 185 |
1 |
| const char *ts = p++; |
| 186 |
7 |
▶ | while (p < end && *p != '\'' && *p != '\n') { |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && *p != '\'' && *p != '\n') { |
7 |
0 |
7 |
| while (p < end && *p != '\'' && *p != '\n') { |
6 |
1 |
7 |
| while (p < end && *p != '\'' && *p != '\n') { |
6 |
0 |
6 |
|
| 187 |
6 |
▶ | if (*p == '\\' && p+1 < end) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\' && p+1 < end) p++; |
0 |
6 |
6 |
| if (*p == '\\' && p+1 < end) p++; |
0 |
0 |
0 |
|
| 188 |
6 |
| p++; |
| 189 |
|
| } |
| 190 |
1 |
▶ | if (p < end && *p == '\'') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '\'') p++; |
1 |
0 |
1 |
| if (p < end && *p == '\'') p++; |
1 |
0 |
1 |
|
| 191 |
1 |
| TS_SPAN("esh-s", ts, p); |
| 192 |
1 |
| last_val = 1; |
| 193 |
1 |
| continue; |
| 194 |
|
| } |
| 195 |
|
| |
| 196 |
|
| /* regex literal — only when not after a value */ |
| 197 |
429 |
▶ | if (c == '/' && !last_val) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '/' && !last_val) { |
0 |
429 |
429 |
| if (c == '/' && !last_val) { |
0 |
0 |
0 |
|
| 198 |
0 |
| const char *ts = p++; |
| 199 |
0 |
| int in_class = 0; |
| 200 |
0 |
▶ | while (p < end && *p != '\n') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\n') { |
0 |
0 |
0 |
| while (p < end && *p != '\n') { |
0 |
0 |
0 |
|
| 201 |
0 |
▶ | if (*p == '\\' && p+1 < end) { p += 2; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\' && p+1 < end) { p += 2; continue; } |
0 |
0 |
0 |
| if (*p == '\\' && p+1 < end) { p += 2; continue; } |
0 |
0 |
0 |
|
| 202 |
0 |
▶ | if (!in_class && *p == '[') { in_class = 1; p++; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (!in_class && *p == '[') { in_class = 1; p++; continue; } |
0 |
0 |
0 |
| if (!in_class && *p == '[') { in_class = 1; p++; continue; } |
0 |
0 |
0 |
|
| 203 |
0 |
▶ | if (in_class && *p == ']') { in_class = 0; p++; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (in_class && *p == ']') { in_class = 0; p++; continue; } |
0 |
0 |
0 |
| if (in_class && *p == ']') { in_class = 0; p++; continue; } |
0 |
0 |
0 |
|
| 204 |
0 |
▶ | if (!in_class && *p == '/') { p++; break; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (!in_class && *p == '/') { p++; break; } |
0 |
0 |
0 |
| if (!in_class && *p == '/') { p++; break; } |
0 |
0 |
0 |
|
| 205 |
0 |
| p++; |
| 206 |
|
| } |
| 207 |
0 |
▶ | while (p < end && isalpha((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isalpha((unsigned char)*p)) p++; |
0 |
0 |
0 |
| while (p < end && isalpha((unsigned char)*p)) p++; |
0 |
0 |
0 |
|
| 208 |
0 |
| TS_SPAN("esh-r", ts, p); |
| 209 |
0 |
| last_val = 1; |
| 210 |
0 |
| continue; |
| 211 |
|
| } |
| 212 |
|
| |
| 213 |
|
| /* number */ |
| 214 |
429 |
▶ | if (isdigit((unsigned char)c) || |
Branch: 2 branches
| Branch | True | False | Total |
| if (isdigit((unsigned char)c) || |
427 |
2 |
429 |
| if (isdigit((unsigned char)c) || |
0 |
427 |
427 |
|
| 215 |
0 |
▶ | (c == '.' && p+1 < end && isdigit((unsigned char)*(p+1)))) { |
Branch: 2 branches
| Branch | True | False | Total |
| (c == '.' && p+1 < end && isdigit((unsigned char)*(p+1)))) { |
0 |
0 |
0 |
| (c == '.' && p+1 < end && isdigit((unsigned char)*(p+1)))) { |
0 |
0 |
0 |
|
| 216 |
2 |
| const char *ns = p; |
| 217 |
2 |
▶ | if (c == '0' && p+1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (c == '0' && p+1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { |
0 |
2 |
2 |
| if (c == '0' && p+1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { |
0 |
0 |
0 |
| if (c == '0' && p+1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { |
0 |
0 |
0 |
| if (c == '0' && p+1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { |
0 |
0 |
0 |
|
| 218 |
0 |
| p += 2; |
| 219 |
0 |
▶ | while (p < end && isxdigit((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isxdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
| while (p < end && isxdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
|
| 220 |
2 |
▶ | } else if (c == '0' && p+1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { |
Branch: 4 branches
| Branch | True | False | Total |
| } else if (c == '0' && p+1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { |
0 |
2 |
2 |
| } else if (c == '0' && p+1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { |
0 |
0 |
0 |
| } else if (c == '0' && p+1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { |
0 |
0 |
0 |
| } else if (c == '0' && p+1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { |
0 |
0 |
0 |
|
| 221 |
0 |
| p += 2; |
| 222 |
0 |
▶ | while (p < end && (*p == '0' || *p == '1')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (*p == '0' || *p == '1')) p++; |
0 |
0 |
0 |
| while (p < end && (*p == '0' || *p == '1')) p++; |
0 |
0 |
0 |
| while (p < end && (*p == '0' || *p == '1')) p++; |
0 |
0 |
0 |
|
| 223 |
|
| } else { |
| 224 |
5 |
▶ | while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
4 |
1 |
5 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
3 |
1 |
4 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
0 |
1 |
1 |
|
| 225 |
2 |
▶ | if (p < end && *p == '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '.') { |
1 |
1 |
2 |
| if (p < end && *p == '.') { |
1 |
0 |
1 |
|
| 226 |
1 |
| p++; |
| 227 |
3 |
▶ | while (p < end && isdigit((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isdigit((unsigned char)*p)) p++; |
2 |
1 |
3 |
| while (p < end && isdigit((unsigned char)*p)) p++; |
2 |
0 |
2 |
|
| 228 |
|
| } |
| 229 |
2 |
▶ | if (p < end && (*p == 'e' || *p == 'E')) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == 'e' || *p == 'E')) { |
0 |
2 |
2 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
0 |
0 |
0 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
0 |
0 |
0 |
|
| 230 |
0 |
| p++; |
| 231 |
0 |
▶ | if (p < end && (*p == '+' || *p == '-')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
|
| 232 |
0 |
▶ | while (p < end && isdigit((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
|
| 233 |
|
| } |
| 234 |
2 |
▶ | if (p < end && (*p == 'n')) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && (*p == 'n')) p++; |
0 |
2 |
2 |
| if (p < end && (*p == 'n')) p++; |
0 |
0 |
0 |
|
| 235 |
|
| } |
| 236 |
2 |
| TS_SPAN("esh-n", ns, p); |
| 237 |
2 |
| last_val = 1; |
| 238 |
2 |
| continue; |
| 239 |
|
| } |
| 240 |
|
| |
| 241 |
|
| /* decorator: @Identifier */ |
| 242 |
427 |
▶ | if (c == '@' && p+1 < end && (isalpha((unsigned char)*(p+1)) || *(p+1) == '_')) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (c == '@' && p+1 < end && (isalpha((unsigned char)*(p+1)) || *(p+1) == '_')) { |
5 |
422 |
427 |
| if (c == '@' && p+1 < end && (isalpha((unsigned char)*(p+1)) || *(p+1) == '_')) { |
5 |
0 |
5 |
| if (c == '@' && p+1 < end && (isalpha((unsigned char)*(p+1)) || *(p+1) == '_')) { |
0 |
5 |
5 |
| if (c == '@' && p+1 < end && (isalpha((unsigned char)*(p+1)) || *(p+1) == '_')) { |
0 |
0 |
0 |
|
| 243 |
5 |
| const char *ts = p++; |
| 244 |
58 |
▶ | while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == '.')) p++; |
Branch: 4 branches
| Branch | True | False | Total |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == '.')) p++; |
57 |
1 |
58 |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == '.')) p++; |
51 |
6 |
57 |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == '.')) p++; |
1 |
5 |
6 |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == '.')) p++; |
1 |
4 |
5 |
|
| 245 |
5 |
| TS_SPAN("esh-p", ts, p); |
| 246 |
5 |
| last_val = 0; |
| 247 |
5 |
| continue; |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
|
| /* identifier or keyword */ |
| 251 |
422 |
▶ | if (eshu_hl_isalpha_(c)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_hl_isalpha_(c)) { |
158 |
264 |
422 |
|
| 252 |
158 |
| const char *ts = p; |
| 253 |
830 |
▶ | while (p < end && eshu_hl_isalnum_(*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && eshu_hl_isalnum_(*p)) p++; |
815 |
15 |
830 |
| while (p < end && eshu_hl_isalnum_(*p)) p++; |
672 |
143 |
815 |
|
| 254 |
158 |
| eshu_hl_flush(&out, plain, ts); |
| 255 |
158 |
| plain = p; |
| 256 |
158 |
| size_t ilen = (size_t)(p - ts); |
| 257 |
158 |
▶ | if (eshu_hl_kw(ts, ilen, eshu_hl_ts_kw)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_hl_kw(ts, ilen, eshu_hl_ts_kw)) { |
80 |
78 |
158 |
|
| 258 |
80 |
| eshu_hl_span(&out, "esh-k", ts, p); |
| 259 |
80 |
| last_val = 0; |
| 260 |
78 |
▶ | } else if (eshu_hl_kw(ts, ilen, eshu_hl_ts_bi)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (eshu_hl_kw(ts, ilen, eshu_hl_ts_bi)) { |
17 |
61 |
78 |
|
| 261 |
17 |
| eshu_hl_span(&out, "esh-b", ts, p); |
| 262 |
17 |
| last_val = 1; |
| 263 |
|
| } else { |
| 264 |
61 |
| eshu_hl_write_html(&out, ts, ilen); |
| 265 |
61 |
| last_val = 1; |
| 266 |
|
| } |
| 267 |
158 |
| continue; |
| 268 |
|
| } |
| 269 |
|
| |
| 270 |
|
| /* rvalue context tracking */ |
| 271 |
264 |
▶ | if (c == ')' || c == ']') last_val = 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == ')' || c == ']') last_val = 1; |
259 |
5 |
264 |
| if (c == ')' || c == ']') last_val = 1; |
3 |
256 |
259 |
|
| 272 |
256 |
▶ | else if (c == '(' || c == '[' || c == ',' || c == ';' || |
Branch: 5 branches
| Branch | True | False | Total |
| else if (c == '(' || c == '[' || c == ',' || c == ';' || |
251 |
5 |
256 |
| else if (c == '(' || c == '[' || c == ',' || c == ';' || |
248 |
3 |
251 |
| else if (c == '(' || c == '[' || c == ',' || c == ';' || |
241 |
7 |
248 |
| else if (c == '(' || c == '[' || c == ',' || c == ';' || |
237 |
4 |
241 |
| else if (c == '(' || c == '[' || c == ',' || c == ';' || |
216 |
21 |
237 |
|
| 273 |
216 |
▶ | c == '=' || c == '!' || c == ':' || c == '?' || |
Branch: 4 branches
| Branch | True | False | Total |
| c == '=' || c == '!' || c == ':' || c == '?' || |
215 |
1 |
216 |
| c == '=' || c == '!' || c == ':' || c == '?' || |
211 |
4 |
215 |
| c == '=' || c == '!' || c == ':' || c == '?' || |
211 |
0 |
211 |
| c == '=' || c == '!' || c == ':' || c == '?' || |
198 |
13 |
211 |
|
| 274 |
198 |
▶ | c == '{' || c == '&' || c == '|' || c == '^' || |
Branch: 4 branches
| Branch | True | False | Total |
| c == '{' || c == '&' || c == '|' || c == '^' || |
198 |
0 |
198 |
| c == '{' || c == '&' || c == '|' || c == '^' || |
197 |
1 |
198 |
| c == '{' || c == '&' || c == '|' || c == '^' || |
197 |
0 |
197 |
| c == '{' || c == '&' || c == '|' || c == '^' || |
197 |
0 |
197 |
|
| 275 |
197 |
▶ | c == '+' || c == '-' || c == '*' || c == '<' || c == '>') |
Branch: 4 branches
| Branch | True | False | Total |
| c == '+' || c == '-' || c == '*' || c == '<' || c == '>') |
197 |
0 |
197 |
| c == '+' || c == '-' || c == '*' || c == '<' || c == '>') |
197 |
0 |
197 |
| c == '+' || c == '-' || c == '*' || c == '<' || c == '>') |
179 |
18 |
197 |
| c == '+' || c == '-' || c == '*' || c == '<' || c == '>') |
18 |
161 |
179 |
|
| 276 |
95 |
| last_val = 0; |
| 277 |
264 |
▶ | if (c == '\n') last_val = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '\n') last_val = 0; |
0 |
264 |
264 |
|
| 278 |
264 |
| p++; |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
53 |
| eshu_hl_flush(&out, plain, end); |
| 282 |
53 |
| eshu_buf_putc(&out, '\0'); |
| 283 |
53 |
| *out_len = out.len - 1; |
| 284 |
53 |
| return out.data; |
| 285 |
|
| |
| 286 |
|
| #undef TS_SPAN |
| 287 |
|
| } |
| 288 |
|
| |
| 289 |
|
| #endif /* ESHU_TS_H */ |