include/eshu_ruby.h

filter: Statementstmt 68.8% 351 / 510 Branchbran 51.9% 460 / 886 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 58.0% 811 / 1396 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/eshu_ts.h ↑ Summary include/eshu_php.h »
1 /*
2 * eshu_ruby.h — Ruby language indentation scanner
3 *
4 * Ruby uses keyword-based block delimiters (def/end, class/end, do/end, etc.)
5 * plus braces { } for single-line blocks and hashes.
6 *
7 * Pure C, no Perl dependencies, header-only.
8 */
9  
10 #ifndef ESHU_RUBY_H
11 #define ESHU_RUBY_H
12  
13 #include "eshu.h"
14  
15 /* ══════════════════════════════════════════════════════════════════
16 * Word-boundary helper
17 * ══════════════════════════════════════════════════════════════════ */
18  
19 0 static int eshu_rb_word_end(const char *p, const char *end) {
20 0 ▶ if (p >= end) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (p >= end) return 1; 0 0 0
21 0 char c = *p;
22 0 ▶ return !(isalnum((unsigned char)c) || c == '_' || c == '?' || c == '!');
Branch: 4 branches
BranchTrueFalseTotal
return !(isalnum((unsigned char)c) || c == '_' || c == '?' || c == '!'); 0 0 0
return !(isalnum((unsigned char)c) || c == '_' || c == '?' || c == '!'); 0 0 0
return !(isalnum((unsigned char)c) || c == '_' || c == '?' || c == '!'); 0 0 0
return !(isalnum((unsigned char)c) || c == '_' || c == '?' || c == '!'); 0 0 0
23 }
24  
25 0 static int eshu_rb_kw_at(const char *p, const char *end, const char *kw, int kwlen) {
26 0 ▶ if (p + kwlen > end) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (p + kwlen > end) return 0; 0 0 0
27 0 ▶ if (strncmp(p, kw, (size_t)kwlen) != 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp(p, kw, (size_t)kwlen) != 0) return 0; 0 0 0
28 0 return eshu_rb_word_end(p + kwlen, end);
29 }
30  
31 /* ══════════════════════════════════════════════════════════════════
32 * String/literal scanning helpers
33 * ══════════════════════════════════════════════════════════════════ */
34  
35 /* Scan DQ string starting just after opening '"'. */
36 60 static const char *eshu_rb_scan_dq(const char *p, const char *end) {
37 60 int interp = 0;
38 865 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 865 0 865
39 865 char c = *p;
40 865 ▶ if (c == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { p += 2; continue; } 0 865 865
if (c == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
41 865 ▶ if (c == '#' && p + 1 < end && *(p+1) == '{') { interp++; p += 2; continue; }
Branch: 3 branches
BranchTrueFalseTotal
if (c == '#' && p + 1 < end && *(p+1) == '{') { interp++; p += 2; continue; } 39 826 865
if (c == '#' && p + 1 < end && *(p+1) == '{') { interp++; p += 2; continue; } 39 0 39
if (c == '#' && p + 1 < end && *(p+1) == '{') { interp++; p += 2; continue; } 38 1 39
42 827 ▶ if (interp > 0 && c == '}') { interp--; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (interp > 0 && c == '}') { interp--; p++; continue; } 276 551 827
if (interp > 0 && c == '}') { interp--; p++; continue; } 38 238 276
43 789 ▶ if (interp == 0 && c == '"') return p + 1;
Branch: 2 branches
BranchTrueFalseTotal
if (interp == 0 && c == '"') return p + 1; 551 238 789
if (interp == 0 && c == '"') return p + 1; 60 491 551
44 729 p++;
45 }
46 0 return end;
47 }
48  
49 /* Scan SQ string starting just after opening '\''. */
50 18 static const char *eshu_rb_scan_sq(const char *p, const char *end) {
51 84 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 84 0 84
52 84 char c = *p;
53 84 ▶ if (c == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { p += 2; continue; } 1 83 84
if (c == '\\' && p + 1 < end) { p += 2; continue; } 1 0 1
54 83 ▶ if (c == '\'') return p + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\'') return p + 1; 18 65 83
55 65 p++;
56 }
57 0 return end;
58 }
59  
60 /* Scan backtick starting just after opening '`'. */
61 0 static const char *eshu_rb_scan_bt(const char *p, const char *end) {
62 0 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 0 0 0
63 0 char c = *p;
64 0 ▶ if (c == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
if (c == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
65 0 ▶ if (c == '`') return p + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '`') return p + 1; 0 0 0
66 0 p++;
67 }
68 0 return end;
69 }
70  
71 /* Scan % literal starting just AFTER the type char (or '%' for no type).
72 * open = the opening delimiter char. Returns pointer past the closing delim. */
73 8 static const char *eshu_rb_scan_pct(const char *p, const char *end, char open) {
74 char close;
75 8 int depth = 1;
76 8 switch (open) {
77 1 case '(': close = ')'; break;
78 6 case '[': close = ']'; break;
79 1 case '{': close = '}'; break;
80 0 case '<': close = '>'; break;
81 0 default: close = open; break;
82 }
83 132 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 132 0 132
84 132 char c = *p;
85 132 ▶ if (c == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { p += 2; continue; } 2 130 132
if (c == '\\' && p + 1 < end) { p += 2; continue; } 2 0 2
86 130 ▶ if (close != open) {
Branch: 1 branch
BranchTrueFalseTotal
if (close != open) { 130 0 130
87 130 ▶ if (c == open) { depth++; p++; continue; }
Branch: 1 branch
BranchTrueFalseTotal
if (c == open) { depth++; p++; continue; } 0 130 130
88 130 ▶ if (c == close) { depth--; p++; if (depth == 0) return p; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == close) { depth--; p++; if (depth == 0) return p; continue; } 8 122 130
if (c == close) { depth--; p++; if (depth == 0) return p; continue; } 8 0 8
89 } else {
90 0 ▶ if (c == close) return p + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (c == close) return p + 1; 0 0 0
91 }
92 122 p++;
93 }
94 0 return end;
95 }
96  
97 /* Scan regex starting just after opening '/'.
98 * Returns pointer past closing '/' and flags. */
99 7 static const char *eshu_rb_scan_regex(const char *p, const char *end) {
100 7 int in_class = 0;
101 54 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 50 4 54
102 50 char c = *p;
103 50 ▶ if (c == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { p += 2; continue; } 2 48 50
if (c == '\\' && p + 1 < end) { p += 2; continue; } 2 0 2
104 48 ▶ if (!in_class && c == '[') { in_class = 1; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (!in_class && c == '[') { in_class = 1; p++; continue; } 40 8 48
if (!in_class && c == '[') { in_class = 1; p++; continue; } 1 39 40
105 47 ▶ if (in_class && c == ']') { in_class = 0; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (in_class && c == ']') { in_class = 0; p++; continue; } 8 39 47
if (in_class && c == ']') { in_class = 0; p++; continue; } 1 7 8
106 46 ▶ if (!in_class && c == '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (!in_class && c == '/') { 39 7 46
if (!in_class && c == '/') { 3 36 39
107 3 p++;
108 3 ▶ while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' ||
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 1 2 3
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 1 1
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 1 1
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 1 1
109 1 ▶ *p == 's' || *p == 'u' || *p == 'e'))
Branch: 3 branches
BranchTrueFalseTotal
*p == 's' || *p == 'u' || *p == 'e')) 0 1 1
*p == 's' || *p == 'u' || *p == 'e')) 0 1 1
*p == 's' || *p == 'u' || *p == 'e')) 0 1 1
110 0 p++;
111 3 return p;
112 }
113 43 ▶ if (c == '\n') return p;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\n') return p; 0 43 43
114 43 p++;
115 }
116 4 return end;
117 }
118  
119 /* Detect <<HEREDOC or <<~HEREDOC at some position on a line.
120 * Fills ctx->heredoc_tag, sets ctx->heredoc_squig.
121 * Returns 1 if found. */
122 636 static int eshu_rb_detect_heredoc(eshu_rb_ctx_t *ctx,
123 const char *p, const char *end) {
124 9626 ▶ while (p + 1 < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p + 1 < end) { 8991 635 9626
125 8991 ▶ if (*p == '<' && *(p+1) == '<') {
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '<' && *(p+1) == '<') { 31 8960 8991
if (*p == '<' && *(p+1) == '<') { 9 22 31
126 9 const char *h = p + 2;
127 9 int squig = 0;
128 9 ▶ if (h < end && *h == '~') { squig = 1; h++; }
Branch: 2 branches
BranchTrueFalseTotal
if (h < end && *h == '~') { squig = 1; h++; } 9 0 9
if (h < end && *h == '~') { squig = 1; h++; } 1 8 9
129 9 char q = 0;
130 9 ▶ if (h < end && (*h == '\'' || *h == '"' || *h == '`')) q = *h++;
Branch: 4 branches
BranchTrueFalseTotal
if (h < end && (*h == '\'' || *h == '"' || *h == '`')) q = *h++; 9 0 9
if (h < end && (*h == '\'' || *h == '"' || *h == '`')) q = *h++; 9 0 9
if (h < end && (*h == '\'' || *h == '"' || *h == '`')) q = *h++; 9 0 9
if (h < end && (*h == '\'' || *h == '"' || *h == '`')) q = *h++; 0 9 9
131 9 int i = 0;
132 24 ▶ while (h < end && *h != '\n' && *h != '\r' &&
Branch: 2 branches
BranchTrueFalseTotal
while (h < end && *h != '\n' && *h != '\r' && 15 0 15
while (h < end && *h != '\n' && *h != '\r' && 15 0 15
133 31 ▶ (isalnum((unsigned char)*h) || *h == '_') && i < 63) {
Branch: 4 branches
BranchTrueFalseTotal
(isalnum((unsigned char)*h) || *h == '_') && i < 63) { 15 1 16
(isalnum((unsigned char)*h) || *h == '_') && i < 63) { 8 7 15
(isalnum((unsigned char)*h) || *h == '_') && i < 63) { 0 8 8
(isalnum((unsigned char)*h) || *h == '_') && i < 63) { 7 0 7
134 7 ctx->heredoc_tag[i++] = *h++;
135 }
136 9 ▶ if (i == 0) { p++; continue; }
Branch: 1 branch
BranchTrueFalseTotal
if (i == 0) { p++; continue; } 8 1 9
137 1 ctx->heredoc_tag[i] = '\0';
138 1 ▶ if (q && h < end && *h == q) h++;
Branch: 3 branches
BranchTrueFalseTotal
if (q && h < end && *h == q) h++; 0 1 1
if (q && h < end && *h == q) h++; 0 0 0
if (q && h < end && *h == q) h++; 0 0 0
139 1 ctx->heredoc_squig = squig;
140 1 ▶ ctx->state = squig ? ESHU_RB_HEREDOC_SQUIG : ESHU_RB_HEREDOC;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state = squig ? ESHU_RB_HEREDOC_SQUIG : ESHU_RB_HEREDOC; 1 0 1
141 1 return 1;
142 }
143 8982 p++;
144 }
145 635 return 0;
146 }
147  
148 /* ══════════════════════════════════════════════════════════════════
149 * Single-pass line analyzer
150 *
151 * Scans [content, content+len) in ONE pass, tracking string/regex
152 * state and counting:
153 * - opens: block-opening keywords/{ (modifier forms excluded)
154 * - closes: block-closing end/}
155 * - is_mid: 1 if line starts with rescue/ensure/else/elsif/when
156 * ══════════════════════════════════════════════════════════════════ */
157  
158 typedef struct {
159 int opens;
160 int closes;
161 int is_mid;
162 } eshu_rb_info_t;
163  
164 636 static eshu_rb_info_t eshu_rb_analyze(const char *content, int len) {
165 636 eshu_rb_info_t info = {0, 0, 0};
166 636 const char *p = content;
167 636 const char *end = content + len;
168 636 int can_regex = 1; /* 1 when next '/' is a regex */
169 636 int first_tok = 1; /* 1 before first significant non-ws token */
170 636 int content_before = 0; /* 1 if we saw non-ws, non-comment before current kw */
171  
172 3437 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 2811 626 3437
173 /* skip whitespace */
174 3796 ▶ while (p < end && (*p == ' ' || *p == '\t')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (*p == ' ' || *p == '\t')) p++; 3796 0 3796
while (p < end && (*p == ' ' || *p == '\t')) p++; 985 2811 3796
while (p < end && (*p == ' ' || *p == '\t')) p++; 0 2811 2811
175 2811 ▶ if (p >= end) break;
Branch: 1 branch
BranchTrueFalseTotal
if (p >= end) break; 0 2811 2811
176  
177 2811 char c = *p;
178  
179 /* # comment — stop */
180 2811 ▶ if (c == '#') break;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '#') break; 1 2810 2811
181  
182 /* double-quoted string */
183 2810 ▶ if (c == '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '"') { 60 2750 2810
184 60 p = eshu_rb_scan_dq(p + 1, end);
185 60 can_regex = 0; first_tok = 0; content_before = 1;
186 60 continue;
187 }
188  
189 /* single-quoted string */
190 2750 ▶ if (c == '\'' && (can_regex || first_tok ||
Branch: 4 branches
BranchTrueFalseTotal
if (c == '\'' && (can_regex || first_tok || 18 2732 2750
if (c == '\'' && (can_regex || first_tok || 0 18 18
if (c == '\'' && (can_regex || first_tok || 0 0 0
if (c == '\'' && (can_regex || first_tok || 0 0 0
191 0 ▶ (p > content && *(p-1) == ' '))) {
Branch: 1 branch
BranchTrueFalseTotal
(p > content && *(p-1) == ' '))) { 0 0 0
192 /* simple heuristic: ' is string when preceded by space/operator */
193 18 p = eshu_rb_scan_sq(p + 1, end);
194 18 can_regex = 0; first_tok = 0; content_before = 1;
195 18 continue;
196 }
197  
198 /* backtick */
199 2732 ▶ if (c == '`') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '`') { 0 2732 2732
200 0 p = eshu_rb_scan_bt(p + 1, end);
201 0 can_regex = 0; first_tok = 0; content_before = 1;
202 0 continue;
203 }
204  
205 /* % literal */
206 2732 ▶ if (c == '%' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '%' && p + 1 < end) { 8 2724 2732
if (c == '%' && p + 1 < end) { 8 0 8
207 8 char nx = *(p+1);
208 8 int is_pct = 0;
209 8 char delim = 0;
210 8 int skip = 2; /* default: skip '%' + type char, delim is p[2] */
211 8 ▶ if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' ||
Branch: 5 branches
BranchTrueFalseTotal
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' || 3 5 8
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' || 3 0 3
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' || 2 1 3
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' || 2 0 2
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I' || 2 0 2
212 2 ▶ nx == 'q' || nx == 'Q' || nx == 'r' || nx == 's' || nx == 'x') {
Branch: 4 branches
BranchTrueFalseTotal
nx == 'q' || nx == 'Q' || nx == 'r' || nx == 's' || nx == 'x') { 1 1 2
nx == 'q' || nx == 'Q' || nx == 'r' || nx == 's' || nx == 'x') { 0 1 1
nx == 'q' || nx == 'Q' || nx == 'r' || nx == 's' || nx == 'x') { 0 0 0
nx == 'q' || nx == 'Q' || nx == 'r' || nx == 's' || nx == 'x') { 0 0 0
213 8 ▶ if (p + 2 < end) { delim = *(p+2); skip = 3; is_pct = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (p + 2 < end) { delim = *(p+2); skip = 3; is_pct = 1; } 8 0 8
214 0 ▶ } else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') {
Branch: 5 branches
BranchTrueFalseTotal
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
215 0 delim = nx; skip = 2; is_pct = 1;
216 }
217 8 ▶ if (is_pct) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pct) { 8 0 8
218 8 p = eshu_rb_scan_pct(p + skip, end, delim);
219 8 can_regex = 0; first_tok = 0; content_before = 1;
220 8 continue;
221 }
222 }
223  
224 /* heredoc << — skip to end of line */
225 2724 ▶ if (c == '<' && p + 1 < end && *(p+1) == '<') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '<' && p + 1 < end && *(p+1) == '<') { 23 2701 2724
if (c == '<' && p + 1 < end && *(p+1) == '<') { 23 0 23
if (c == '<' && p + 1 < end && *(p+1) == '<') { 9 14 23
226 /* just advance past everything; heredoc body handled across lines */
227 101 ▶ while (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) p++; 92 9 101
228 9 break;
229 }
230  
231 /* regex */
232 2715 ▶ if (c == '/' && can_regex) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '/' && can_regex) { 8 2707 2715
if (c == '/' && can_regex) { 7 1 8
233 7 p = eshu_rb_scan_regex(p + 1, end);
234 7 can_regex = 0; first_tok = 0; content_before = 1;
235 7 continue;
236 }
237  
238 /* opening brace */
239 2708 ▶ if (c == '{') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '{') { 69 2639 2708
240 69 info.opens++;
241 69 can_regex = 1; first_tok = 0; content_before = 1;
242 69 p++;
243 69 continue;
244 }
245  
246 /* closing brace */
247 2639 ▶ if (c == '}') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '}') { 64 2575 2639
248 64 info.closes++;
249 64 can_regex = 0; first_tok = 0; content_before = 1;
250 64 p++;
251 64 continue;
252 }
253  
254 /* keywords: must start an identifier */
255 2575 ▶ if (isalpha((unsigned char)c) || c == '_') {
Branch: 2 branches
BranchTrueFalseTotal
if (isalpha((unsigned char)c) || c == '_') { 1247 1328 2575
if (isalpha((unsigned char)c) || c == '_') { 3 1244 1247
256 1331 const char *ts = p;
257 7183 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 6836 347 7183
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 5762 1074 6836
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 90 984 1074
258 /* Ruby allows ? and ! at end of method names */
259 1331 ▶ if (p < end && (*p == '?' || *p == '!') &&
Branch: 3 branches
BranchTrueFalseTotal
if (p < end && (*p == '?' || *p == '!') && 984 347 1331
if (p < end && (*p == '?' || *p == '!') && 968 16 984
if (p < end && (*p == '?' || *p == '!') && 1 967 968
260 17 ▶ !(p + 1 < end && *(p+1) == '='))
Branch: 2 branches
BranchTrueFalseTotal
!(p + 1 < end && *(p+1) == '=')) 10 7 17
!(p + 1 < end && *(p+1) == '=')) 10 0 10
261 17 p++;
262 1331 int kwlen = (int)(p - ts);
263  
264 /* check for block-opening keywords */
265 1331 ▶ if ((kwlen == 3 && strncmp(ts, "def", 3) == 0) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((kwlen == 3 && strncmp(ts, "def", 3) == 0) || 358 973 1331
if ((kwlen == 3 && strncmp(ts, "def", 3) == 0) || 263 95 358
if ((kwlen == 3 && strncmp(ts, "def", 3) == 0) || 203 1033 1236
266 1236 ▶ (kwlen == 5 && strncmp(ts, "class", 5) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 5 && strncmp(ts, "class", 5) == 0) || 180 23 203
(kwlen == 5 && strncmp(ts, "class", 5) == 0) || 102 1111 1213
267 102 ▶ (kwlen == 6 && strncmp(ts, "module", 6) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
(kwlen == 6 && strncmp(ts, "module", 6) == 0)) { 8 94 102
268 /* opener only if not a method call (no content before on line) */
269 126 ▶ if (!content_before) {
Branch: 1 branch
BranchTrueFalseTotal
if (!content_before) { 126 0 126
270 126 info.opens++;
271 }
272 126 can_regex = 0; first_tok = 0; content_before = 1;
273 126 continue;
274 }
275  
276 1205 ▶ if (kwlen == 2 && strncmp(ts, "do", 2) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (kwlen == 2 && strncmp(ts, "do", 2) == 0) { 58 1147 1205
if (kwlen == 2 && strncmp(ts, "do", 2) == 0) { 8 50 58
277 8 info.opens++;
278 8 can_regex = 1; first_tok = 0; content_before = 1;
279 8 continue;
280 }
281  
282 1197 ▶ if ((kwlen == 2 && strncmp(ts, "if", 2) == 0) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((kwlen == 2 && strncmp(ts, "if", 2) == 0) || 50 1147 1197
if ((kwlen == 2 && strncmp(ts, "if", 2) == 0) || 39 11 50
if ((kwlen == 2 && strncmp(ts, "if", 2) == 0) || 94 1092 1186
283 1186 ▶ (kwlen == 6 && strncmp(ts, "unless", 6) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 6 && strncmp(ts, "unless", 6) == 0) || 89 5 94
(kwlen == 6 && strncmp(ts, "unless", 6) == 0) || 180 1001 1181
284 1181 ▶ (kwlen == 5 && strncmp(ts, "while", 5) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 5 && strncmp(ts, "while", 5) == 0) || 177 3 180
(kwlen == 5 && strncmp(ts, "while", 5) == 0) || 177 1001 1178
285 1178 ▶ (kwlen == 5 && strncmp(ts, "until", 5) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 5 && strncmp(ts, "until", 5) == 0) || 176 1 177
(kwlen == 5 && strncmp(ts, "until", 5) == 0) || 263 914 1177
286 263 ▶ (kwlen == 3 && strncmp(ts, "for", 3) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
(kwlen == 3 && strncmp(ts, "for", 3) == 0)) { 2 261 263
287 /* only open if NOT a modifier (no non-ws content before it) */
288 22 ▶ if (!content_before) {
Branch: 1 branch
BranchTrueFalseTotal
if (!content_before) { 13 9 22
289 13 info.opens++;
290 }
291 22 can_regex = 1; first_tok = 0; content_before = 1;
292 22 continue;
293 }
294  
295 1175 ▶ if ((kwlen == 5 && strncmp(ts, "begin", 5) == 0) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((kwlen == 5 && strncmp(ts, "begin", 5) == 0) || 176 999 1175
if ((kwlen == 5 && strncmp(ts, "begin", 5) == 0) || 172 4 176
if ((kwlen == 5 && strncmp(ts, "begin", 5) == 0) || 241 930 1171
296 241 ▶ (kwlen == 4 && strncmp(ts, "case", 4) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
(kwlen == 4 && strncmp(ts, "case", 4) == 0)) { 6 235 241
297 10 ▶ if (!content_before) {
Branch: 1 branch
BranchTrueFalseTotal
if (!content_before) { 10 0 10
298 10 info.opens++;
299 }
300 10 can_regex = 1; first_tok = 0; content_before = 1;
301 10 continue;
302 }
303  
304 /* block-closing keyword */
305 1165 ▶ if (kwlen == 3 && strncmp(ts, "end", 3) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (kwlen == 3 && strncmp(ts, "end", 3) == 0) { 261 904 1165
if (kwlen == 3 && strncmp(ts, "end", 3) == 0) { 157 104 261
306 157 info.closes++;
307 157 can_regex = 0; first_tok = 0; content_before = 1;
308 157 continue;
309 }
310  
311 /* middle keywords (dedent before, same depth after) */
312 1008 ▶ if (first_tok || !content_before) {
Branch: 2 branches
BranchTrueFalseTotal
if (first_tok || !content_before) { 780 228 1008
if (first_tok || !content_before) { 0 780 780
313 228 ▶ if ((kwlen == 6 && strncmp(ts, "rescue", 6) == 0) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((kwlen == 6 && strncmp(ts, "rescue", 6) == 0) || 28 200 228
if ((kwlen == 6 && strncmp(ts, "rescue", 6) == 0) || 20 8 28
if ((kwlen == 6 && strncmp(ts, "rescue", 6) == 0) || 20 200 220
314 220 ▶ (kwlen == 6 && strncmp(ts, "ensure", 6) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 6 && strncmp(ts, "ensure", 6) == 0) || 18 2 20
(kwlen == 6 && strncmp(ts, "ensure", 6) == 0) || 64 154 218
315 218 ▶ (kwlen == 4 && strncmp(ts, "else", 4) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 4 && strncmp(ts, "else", 4) == 0) || 55 9 64
(kwlen == 4 && strncmp(ts, "else", 4) == 0) || 34 175 209
316 209 ▶ (kwlen == 5 && strncmp(ts, "elsif", 5) == 0) ||
Branch: 2 branches
BranchTrueFalseTotal
(kwlen == 5 && strncmp(ts, "elsif", 5) == 0) || 30 4 34
(kwlen == 5 && strncmp(ts, "elsif", 5) == 0) || 55 150 205
317 55 ▶ (kwlen == 4 && strncmp(ts, "when", 4) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
(kwlen == 4 && strncmp(ts, "when", 4) == 0)) { 15 40 55
318 38 info.is_mid = 1;
319 }
320 }
321  
322 1008 can_regex = 1; /* after keyword, / can be regex */
323 1008 first_tok = 0; content_before = 1;
324 1008 continue;
325 }
326  
327 /* update can_regex based on operator chars */
328 1244 ▶ if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' ||
Branch: 6 branches
BranchTrueFalseTotal
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 1122 122 1244
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 982 140 1122
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 868 114 982
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 823 45 868
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 823 0 823
if (c == '=' || c == '(' || c == ',' || c == '[' || c == ';' || 810 13 823
329 810 ▶ c == '+' || c == '-' || c == '*' || c == '<' || c == '>' ||
Branch: 5 branches
BranchTrueFalseTotal
c == '+' || c == '-' || c == '*' || c == '<' || c == '>' || 799 11 810
c == '+' || c == '-' || c == '*' || c == '<' || c == '>' || 766 33 799
c == '+' || c == '-' || c == '*' || c == '<' || c == '>' || 752 14 766
c == '+' || c == '-' || c == '*' || c == '<' || c == '>' || 733 19 752
c == '+' || c == '-' || c == '*' || c == '<' || c == '>' || 733 0 733
330 733 ▶ c == '!' || c == '|' || c == '&' || c == '^' || c == '~' ||
Branch: 5 branches
BranchTrueFalseTotal
c == '!' || c == '|' || c == '&' || c == '^' || c == '~' || 629 104 733
c == '!' || c == '|' || c == '&' || c == '^' || c == '~' || 608 21 629
c == '!' || c == '|' || c == '&' || c == '^' || c == '~' || 608 0 608
c == '!' || c == '|' || c == '&' || c == '^' || c == '~' || 606 2 608
c == '!' || c == '|' || c == '&' || c == '^' || c == '~' || 88 518 606
331 c == ':') {
332 726 can_regex = 1;
333 518 ▶ } else if (c == ')' || c == ']') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == ')' || c == ']') { 378 140 518
} else if (c == ')' || c == ']') { 45 333 378
334 185 can_regex = 0;
335 }
336  
337 1244 ▶ if (c != ' ' && c != '\t') {
Branch: 2 branches
BranchTrueFalseTotal
if (c != ' ' && c != '\t') { 1244 0 1244
if (c != ' ' && c != '\t') { 1244 0 1244
338 1244 first_tok = 0;
339 1244 content_before = 1;
340 }
341 1244 p++;
342 }
343  
344 636 return info;
345 }
346  
347 /* ══════════════════════════════════════════════════════════════════
348 * Process a single line
349 * ══════════════════════════════════════════════════════════════════ */
350  
351 685 static void eshu_rb_process_line(eshu_rb_ctx_t *ctx, eshu_buf_t *out,
352 const char *line_start, const char *eol) {
353 685 const char *content = eshu_skip_leading_ws(line_start);
354 int len;
355  
356 /* empty line */
357 685 ▶ if (content >= eol) {
Branch: 1 branch
BranchTrueFalseTotal
if (content >= eol) { 46 639 685
358 46 eshu_buf_putc(out, '\n');
359 49 return;
360 }
361  
362 639 len = (int)(eol - content);
363  
364 /* ── heredoc body ────────────────────────────────────────────── */
365 639 ▶ if (ctx->state == ESHU_RB_HEREDOC || ctx->state == ESHU_RB_HEREDOC_SQUIG) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->state == ESHU_RB_HEREDOC || ctx->state == ESHU_RB_HEREDOC_SQUIG) { 639 0 639
if (ctx->state == ESHU_RB_HEREDOC || ctx->state == ESHU_RB_HEREDOC_SQUIG) { 3 636 639
366 3 size_t tlen = strlen(ctx->heredoc_tag);
367 /* for squiggly: compare against stripped content;
368 * for classic: compare against stripped content (end marker can be indented
369 * for <<~ or at col 0 for <<) */
370 3 size_t check_len = (size_t)len;
371 /* strip trailing ws from check */
372 3 ▶ while (check_len > 0 && (content[check_len-1] == ' ' ||
Branch: 2 branches
BranchTrueFalseTotal
while (check_len > 0 && (content[check_len-1] == ' ' || 3 0 3
while (check_len > 0 && (content[check_len-1] == ' ' || 0 3 3
373 3 ▶ content[check_len-1] == '\t')) check_len--;
Branch: 1 branch
BranchTrueFalseTotal
content[check_len-1] == '\t')) check_len--; 0 3 3
374  
375 3 ▶ if (check_len == tlen && strncmp(content, ctx->heredoc_tag, tlen) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (check_len == tlen && strncmp(content, ctx->heredoc_tag, tlen) == 0) { 1 2 3
if (check_len == tlen && strncmp(content, ctx->heredoc_tag, tlen) == 0) { 1 0 1
376 /* end marker: emit at current depth 0 (traditional) */
377 1 eshu_buf_write_trimmed(out, content, (int)check_len);
378 1 eshu_buf_putc(out, '\n');
379 1 ctx->state = ESHU_CODE;
380 } else {
381 /* body: verbatim */
382 2 eshu_buf_write(out, line_start, (size_t)(eol - line_start));
383 2 eshu_buf_putc(out, '\n');
384 }
385 3 return;
386 }
387  
388 /* ── =begin block comment ────────────────────────────────────── */
389 636 ▶ if (ctx->state == ESHU_COMMENT_BLOCK) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state == ESHU_COMMENT_BLOCK) { 0 636 636
390 0 eshu_buf_write(out, line_start, (size_t)(eol - line_start));
391 0 eshu_buf_putc(out, '\n');
392 0 ▶ if (len >= 4 && strncmp(content, "=end", 4) == 0 &&
Branch: 3 branches
BranchTrueFalseTotal
if (len >= 4 && strncmp(content, "=end", 4) == 0 && 0 0 0
if (len >= 4 && strncmp(content, "=end", 4) == 0 && 0 0 0
if (len >= 4 && strncmp(content, "=end", 4) == 0 && 0 0 0
393 0 ▶ (len == 4 || content[4] == ' ' || content[4] == '\n'))
Branch: 2 branches
BranchTrueFalseTotal
(len == 4 || content[4] == ' ' || content[4] == '\n')) 0 0 0
(len == 4 || content[4] == ' ' || content[4] == '\n')) 0 0 0
394 0 ctx->state = ESHU_CODE;
395 0 return;
396 }
397  
398 /* ── =begin detection ───────────────────────────────────────── */
399 636 ▶ if (content[0] == '=' && len >= 6 && strncmp(content, "=begin", 6) == 0 &&
Branch: 4 branches
BranchTrueFalseTotal
if (content[0] == '=' && len >= 6 && strncmp(content, "=begin", 6) == 0 && 4 632 636
if (content[0] == '=' && len >= 6 && strncmp(content, "=begin", 6) == 0 && 2 2 4
if (content[0] == '=' && len >= 6 && strncmp(content, "=begin", 6) == 0 && 0 2 2
if (content[0] == '=' && len >= 6 && strncmp(content, "=begin", 6) == 0 && 0 0 0
400 0 ▶ (len == 6 || content[6] == ' ')) {
Branch: 1 branch
BranchTrueFalseTotal
(len == 6 || content[6] == ' ')) { 0 0 0
401 0 ctx->state = ESHU_COMMENT_BLOCK;
402 0 eshu_buf_write(out, line_start, (size_t)(eol - line_start));
403 0 eshu_buf_putc(out, '\n');
404 0 return;
405 }
406  
407 /* ── normal Ruby code ────────────────────────────────────────── */
408 636 eshu_rb_info_t info = eshu_rb_analyze(content, len);
409  
410 int indent_depth;
411  
412 636 ▶ if (info.is_mid) {
Branch: 1 branch
BranchTrueFalseTotal
if (info.is_mid) { 38 598 636
413 /* middle keyword (rescue, else, etc.): emit at depth-1, depth unchanged */
414 38 indent_depth = ctx->depth - 1;
415 38 ▶ if (indent_depth < 0) indent_depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (indent_depth < 0) indent_depth = 0; 0 38 38
416 } else {
417 /* For the line's own indent: only dedent by the NET number of extra closers.
418 * A balanced {}/end on one line doesn't change the line's indent. */
419 598 int net_close = info.closes - info.opens;
420 598 ▶ if (net_close > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (net_close > 0) { 160 438 598
421 160 indent_depth = ctx->depth - net_close;
422 160 ▶ if (indent_depth < 0) indent_depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (indent_depth < 0) indent_depth = 0; 0 160 160
423 } else {
424 438 indent_depth = ctx->depth;
425 }
426 }
427  
428 636 eshu_emit_indent(out, indent_depth, &ctx->cfg);
429 636 eshu_buf_write_trimmed(out, content, len);
430 636 eshu_buf_putc(out, '\n');
431  
432 /* update depth for next line */
433 636 ▶ if (!info.is_mid) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info.is_mid) { 598 38 636
434 598 ctx->depth += info.opens - info.closes;
435 598 ▶ if (ctx->depth < 0) ctx->depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->depth < 0) ctx->depth = 0; 0 598 598
436 }
437 /* is_mid: depth is unchanged (body of next clause at same depth as before) */
438  
439 /* detect heredoc on this line */
440 636 ▶ if (ctx->state == ESHU_CODE)
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state == ESHU_CODE) 636 0 636
441 636 eshu_rb_detect_heredoc(ctx, content, eol);
442 }
443  
444 /* ══════════════════════════════════════════════════════════════════
445 * Public API
446 * ══════════════════════════════════════════════════════════════════ */
447  
448 84 static char *eshu_indent_ruby(const char *src, size_t src_len,
449 const eshu_config_t *cfg, size_t *out_len) {
450 eshu_rb_ctx_t ctx;
451 eshu_buf_t out;
452 84 const char *p = src;
453 84 const char *end = src + src_len;
454 char *result;
455  
456 84 memset(&ctx, 0, sizeof(ctx));
457 84 ctx.state = ESHU_CODE;
458 84 ctx.can_regex = 1;
459 84 ctx.cfg = *cfg;
460  
461 84 eshu_buf_init(&out, src_len + 256);
462  
463 {
464 84 int line_num = 1;
465 769 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 685 84 769
466 685 const char *eol = eshu_find_eol(p);
467  
468 685 ▶ if (eshu_in_range(cfg, line_num)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_in_range(cfg, line_num)) { 685 0 685
469 685 eshu_rb_process_line(&ctx, &out, p, eol);
470 } else {
471 0 size_t saved = out.len;
472 0 eshu_rb_process_line(&ctx, &out, p, eol);
473 0 out.len = saved;
474 0 eshu_buf_write_trimmed(&out, p, (int)(eol - p));
475 0 eshu_buf_putc(&out, '\n');
476 }
477  
478 685 p = eol;
479 685 ▶ if (*p == '\n') p++;
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '\n') p++; 685 0 685
480 685 line_num++;
481 }
482 }
483  
484 84 eshu_buf_putc(&out, '\0');
485 84 out.len--;
486 84 *out_len = out.len;
487 84 result = out.data;
488 84 return result;
489 }
490  
491  
492 #include "eshu_hl_util.h"
493  
494 /* ══════════════════════════════════════════════════════════════════
495 * Ruby highlighting
496 * ══════════════════════════════════════════════════════════════════ */
497  
498 static const char * const eshu_hl_rb_kw[] = {
499 "BEGIN", "END",
500 "alias", "and", "begin", "break", "case", "class",
501 "def", "defined?", "do", "else", "elsif", "end",
502 "ensure", "false", "for", "if", "in", "module",
503 "next", "nil", "not", "or", "redo", "rescue",
504 "retry", "return", "self", "super", "then", "true",
505 "undef", "unless", "until", "when", "while", "yield",
506 "__FILE__", "__LINE__", "__method__", "__dir__",
507 NULL
508 };
509  
510 static const char * const eshu_hl_rb_bi[] = {
511 "puts", "print", "p", "pp", "warn", "raise", "fail",
512 "require", "require_relative", "load", "include", "extend", "prepend",
513 "attr_reader", "attr_writer", "attr_accessor",
514 "private", "protected", "public",
515 "lambda", "proc", "block_given?", "Array", "Hash", "String",
516 "Integer", "Float", "Symbol", "Regexp", "Range",
517 "nil?", "frozen?", "dup", "clone", "freeze", "tap",
518 NULL
519 };
520  
521 47 static char *eshu_highlight_ruby(const char *src, size_t src_len, size_t *out_len) {
522 eshu_buf_t out;
523 47 const char *p = src;
524 47 const char *end = src + src_len;
525 const char *plain;
526 /* in_string: 0=code, 1=dq, 2=sq, 3=backtick, 4=regex */
527 47 int in_string = 0;
528 47 int in_block_comment = 0; /* =begin...=end */
529 47 int in_heredoc = 0;
530 char heredoc_tag[64];
531 47 int heredoc_squig = 0;
532 47 int can_regex = 1; /* can the next / be a regex? */
533  
534 #define RB_SPAN(cls, s, n) do { \
535 eshu_hl_flush(&out, plain, (s)); \
536 eshu_hl_span(&out, (cls), (s), (s) + (n)); \
537 plain = (s) + (n); \
538 } while (0)
539  
540 47 eshu_buf_init(&out, src_len * 2);
541 47 plain = p;
542  
543 354 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 307 47 354
544 307 unsigned char c = (unsigned char)*p;
545  
546 /* ── heredoc body ──────────────────────────────────────────── */
547 307 ▶ if (in_heredoc) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_heredoc) { 0 307 307
548 0 const char *ls = p;
549 /* find EOL */
550 0 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 0 0 0
while (p < end && *p != '\n') p++; 0 0 0
551 0 const char *le = p;
552 /* strip trailing ws */
553 0 const char *ct = ls;
554 0 ▶ if (heredoc_squig)
Branch: 1 branch
BranchTrueFalseTotal
if (heredoc_squig) 0 0 0
555 0 ▶ while (ct < le && (*ct == ' ' || *ct == '\t')) ct++;
Branch: 3 branches
BranchTrueFalseTotal
while (ct < le && (*ct == ' ' || *ct == '\t')) ct++; 0 0 0
while (ct < le && (*ct == ' ' || *ct == '\t')) ct++; 0 0 0
while (ct < le && (*ct == ' ' || *ct == '\t')) ct++; 0 0 0
556 0 size_t tlen = strlen(heredoc_tag);
557 0 size_t clen = (size_t)(le - ct);
558 0 ▶ while (clen > 0 && (ct[clen-1] == ' ' || ct[clen-1] == '\t')) clen--;
Branch: 3 branches
BranchTrueFalseTotal
while (clen > 0 && (ct[clen-1] == ' ' || ct[clen-1] == '\t')) clen--; 0 0 0
while (clen > 0 && (ct[clen-1] == ' ' || ct[clen-1] == '\t')) clen--; 0 0 0
while (clen > 0 && (ct[clen-1] == ' ' || ct[clen-1] == '\t')) clen--; 0 0 0
559 0 ▶ if (clen == tlen && strncmp(ct, heredoc_tag, tlen) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (clen == tlen && strncmp(ct, heredoc_tag, tlen) == 0) { 0 0 0
if (clen == tlen && strncmp(ct, heredoc_tag, tlen) == 0) { 0 0 0
560 /* end marker: emit as-is (plain) */
561 0 in_heredoc = 0;
562 } else {
563 /* body: span as string */
564 0 RB_SPAN("esh-s", ls, le - ls);
565 }
566 0 ▶ if (p < end && *p == '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '\n') p++; 0 0 0
if (p < end && *p == '\n') p++; 0 0 0
567 0 continue;
568 }
569  
570 /* ── =begin block comment ────────────────────────────────── */
571 307 ▶ if (in_block_comment) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_block_comment) { 0 307 307
572 0 const char *bs = p;
573 0 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 0 0 0
while (p < end && *p != '\n') p++; 0 0 0
574 0 const char *be = p;
575 /* check for =end */
576 0 size_t llen = (size_t)(be - bs);
577 0 ▶ if (llen >= 4 && strncmp(bs, "=end", 4) == 0 &&
Branch: 3 branches
BranchTrueFalseTotal
if (llen >= 4 && strncmp(bs, "=end", 4) == 0 && 0 0 0
if (llen >= 4 && strncmp(bs, "=end", 4) == 0 && 0 0 0
if (llen >= 4 && strncmp(bs, "=end", 4) == 0 && 0 0 0
578 0 ▶ (llen == 4 || bs[4] == ' '))
Branch: 1 branch
BranchTrueFalseTotal
(llen == 4 || bs[4] == ' ')) 0 0 0
579 0 in_block_comment = 0;
580 0 RB_SPAN("esh-c", bs, be - bs);
581 0 ▶ if (p < end && *p == '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '\n') p++; 0 0 0
if (p < end && *p == '\n') p++; 0 0 0
582 0 continue;
583 }
584  
585 /* ── =begin detection ────────────────────────────────────── */
586 307 ▶ if (c == '=' && p == plain &&
Branch: 2 branches
BranchTrueFalseTotal
if (c == '=' && p == plain && 7 300 307
if (c == '=' && p == plain && 0 7 7
587 0 ▶ (size_t)(end - p) >= 6 && strncmp(p, "=begin", 6) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
(size_t)(end - p) >= 6 && strncmp(p, "=begin", 6) == 0 && 0 0 0
(size_t)(end - p) >= 6 && strncmp(p, "=begin", 6) == 0 && 0 0 0
588 0 ▶ (end - p == 6 || p[6] == ' ' || p[6] == '\n')) {
Branch: 3 branches
BranchTrueFalseTotal
(end - p == 6 || p[6] == ' ' || p[6] == '\n')) { 0 0 0
(end - p == 6 || p[6] == ' ' || p[6] == '\n')) { 0 0 0
(end - p == 6 || p[6] == ' ' || p[6] == '\n')) { 0 0 0
589 0 in_block_comment = 1;
590 0 const char *bs = p;
591 0 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 0 0 0
while (p < end && *p != '\n') p++; 0 0 0
592 0 RB_SPAN("esh-c", bs, p - bs);
593 0 ▶ if (p < end && *p == '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '\n') p++; 0 0 0
if (p < end && *p == '\n') p++; 0 0 0
594 0 continue;
595 }
596  
597 /* ── # comment ───────────────────────────────────────────── */
598 307 ▶ if (c == '#') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '#') { 1 306 307
599 1 const char *cs = p;
600 12 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 11 1 12
while (p < end && *p != '\n') p++; 11 0 11
601 1 RB_SPAN("esh-c", cs, p - cs);
602 1 can_regex = 1;
603 1 continue;
604 }
605  
606 /* ── double-quoted string ────────────────────────────────── */
607 306 ▶ if (c == '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '"') { 7 299 306
608 7 const char *qs = p;
609 7 p++;
610 7 int interp = 0;
611 47 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 47 0 47
612 47 char ch = *p;
613 47 ▶ if (ch == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 47 47
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
614 47 ▶ if (ch == '#' && p + 1 < end && *(p+1) == '{') {
Branch: 3 branches
BranchTrueFalseTotal
if (ch == '#' && p + 1 < end && *(p+1) == '{') { 0 47 47
if (ch == '#' && p + 1 < end && *(p+1) == '{') { 0 0 0
if (ch == '#' && p + 1 < end && *(p+1) == '{') { 0 0 0
615 0 interp++; p += 2; continue;
616 }
617 47 ▶ if (interp > 0 && ch == '}') { interp--; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (interp > 0 && ch == '}') { interp--; p++; continue; } 0 47 47
if (interp > 0 && ch == '}') { interp--; p++; continue; } 0 0 0
618 47 ▶ if (interp == 0 && ch == '"') { p++; break; }
Branch: 2 branches
BranchTrueFalseTotal
if (interp == 0 && ch == '"') { p++; break; } 47 0 47
if (interp == 0 && ch == '"') { p++; break; } 7 40 47
619 40 p++;
620 }
621 7 RB_SPAN("esh-s", qs, p - qs);
622 7 can_regex = 0;
623 7 continue;
624 }
625  
626 /* ── single-quoted string ────────────────────────────────── */
627 299 ▶ if (c == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\'') { 1 298 299
628 /* check it's not a char-like: 'x' — treat uniformly as string */
629 1 const char *qs = p;
630 1 p++;
631 7 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 7 0 7
632 7 char ch = *p;
633 7 ▶ if (ch == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 7 7
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
634 7 ▶ if (ch == '\'') { p++; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (ch == '\'') { p++; break; } 1 6 7
635 6 p++;
636 }
637 1 RB_SPAN("esh-s", qs, p - qs);
638 1 can_regex = 0;
639 1 continue;
640 }
641  
642 /* ── backtick string ─────────────────────────────────────── */
643 298 ▶ if (c == '`') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '`') { 0 298 298
644 0 const char *qs = p;
645 0 p++;
646 0 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 0 0 0
647 0 char ch = *p;
648 0 ▶ if (ch == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
649 0 ▶ if (ch == '`') { p++; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (ch == '`') { p++; break; } 0 0 0
650 0 p++;
651 }
652 0 RB_SPAN("esh-s", qs, p - qs);
653 0 can_regex = 0;
654 0 continue;
655 }
656  
657 /* ── % literals: %w %i %q %Q %r %x ─────────────────────── */
658 298 ▶ if (c == '%' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '%' && p + 1 < end) { 0 298 298
if (c == '%' && p + 1 < end) { 0 0 0
659 0 char nx = (unsigned char)*(p+1);
660 0 char delim = 0;
661 0 int is_pct = 0;
662 0 const char *cls = "esh-s";
663 0 ▶ if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I') {
Branch: 4 branches
BranchTrueFalseTotal
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I') { 0 0 0
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I') { 0 0 0
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I') { 0 0 0
if (nx == 'w' || nx == 'W' || nx == 'i' || nx == 'I') { 0 0 0
664 /* word/symbol arrays */
665 0 ▶ if (p + 2 < end) { delim = *(p+2); is_pct = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (p + 2 < end) { delim = *(p+2); is_pct = 1; } 0 0 0
666 0 ▶ } else if (nx == 'q' || nx == 'Q') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (nx == 'q' || nx == 'Q') { 0 0 0
} else if (nx == 'q' || nx == 'Q') { 0 0 0
667 0 ▶ if (p + 2 < end) { delim = *(p+2); is_pct = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (p + 2 < end) { delim = *(p+2); is_pct = 1; } 0 0 0
668 0 ▶ } else if (nx == 'r') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (nx == 'r') { 0 0 0
669 0 cls = "esh-r";
670 0 ▶ if (p + 2 < end) { delim = *(p+2); is_pct = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (p + 2 < end) { delim = *(p+2); is_pct = 1; } 0 0 0
671 0 ▶ } else if (nx == 'x') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (nx == 'x') { 0 0 0
672 0 ▶ if (p + 2 < end) { delim = *(p+2); is_pct = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (p + 2 < end) { delim = *(p+2); is_pct = 1; } 0 0 0
673 0 ▶ } else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') {
Branch: 5 branches
BranchTrueFalseTotal
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
} else if (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') { 0 0 0
674 0 delim = nx; is_pct = 1;
675 }
676 0 ▶ if (is_pct) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pct) { 0 0 0
677 0 const char *ps = p;
678 0 ▶ int offset = (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|')
Branch: 4 branches
BranchTrueFalseTotal
int offset = (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') 0 0 0
int offset = (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') 0 0 0
int offset = (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') 0 0 0
int offset = (nx == '(' || nx == '[' || nx == '{' || nx == '<' || nx == '|') 0 0 0
679 0 ▶ ? 2 : 3;
Branch: 1 branch
BranchTrueFalseTotal
? 2 : 3; 0 0 0
680 0 p = (const char *)eshu_rb_scan_pct(ps + offset, end, delim);
681 0 RB_SPAN(cls, ps, p - ps);
682 0 can_regex = 0;
683 0 continue;
684 }
685 }
686  
687 /* ── heredoc << ──────────────────────────────────────────── */
688 298 ▶ if (c == '<' && p + 1 < end && *(p+1) == '<') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '<' && p + 1 < end && *(p+1) == '<') { 2 296 298
if (c == '<' && p + 1 < end && *(p+1) == '<') { 2 0 2
if (c == '<' && p + 1 < end && *(p+1) == '<') { 0 2 2
689 0 const char *hs = p;
690 0 p += 2;
691 0 int squig = 0;
692 0 ▶ if (p < end && *p == '~') { squig = 1; p++; }
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '~') { squig = 1; p++; } 0 0 0
if (p < end && *p == '~') { squig = 1; p++; } 0 0 0
693 0 char q = 0;
694 0 ▶ if (p < end && (*p == '\'' || *p == '"' || *p == '`')) q = *p++;
Branch: 4 branches
BranchTrueFalseTotal
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) q = *p++; 0 0 0
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) q = *p++; 0 0 0
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) q = *p++; 0 0 0
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) q = *p++; 0 0 0
695 0 int i = 0;
696 0 ▶ while (p < end && *p != '\n' && *p != '\r' &&
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n' && *p != '\r' && 0 0 0
while (p < end && *p != '\n' && *p != '\r' && 0 0 0
697 0 ▶ (isalnum((unsigned char)*p) || *p == '_') && i < 63) {
Branch: 4 branches
BranchTrueFalseTotal
(isalnum((unsigned char)*p) || *p == '_') && i < 63) { 0 0 0
(isalnum((unsigned char)*p) || *p == '_') && i < 63) { 0 0 0
(isalnum((unsigned char)*p) || *p == '_') && i < 63) { 0 0 0
(isalnum((unsigned char)*p) || *p == '_') && i < 63) { 0 0 0
698 0 heredoc_tag[i++] = *p++;
699 }
700 0 ▶ if (i > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i > 0) { 0 0 0
701 0 heredoc_tag[i] = '\0';
702 0 ▶ if (q && p < end && *p == q) p++;
Branch: 3 branches
BranchTrueFalseTotal
if (q && p < end && *p == q) p++; 0 0 0
if (q && p < end && *p == q) p++; 0 0 0
if (q && p < end && *p == q) p++; 0 0 0
703 0 heredoc_squig = squig;
704 0 in_heredoc = 1;
705 /* span the opening line */
706 0 RB_SPAN("esh-s", hs, p - hs);
707 /* advance to EOL */
708 0 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 0 0 0
while (p < end && *p != '\n') p++; 0 0 0
709 0 can_regex = 1;
710 0 continue;
711 }
712 /* not a heredoc — treat << as operator */
713 }
714  
715 /* ── regex /.../ ─────────────────────────────────────────── */
716 298 ▶ if (c == '/' && can_regex) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '/' && can_regex) { 0 298 298
if (c == '/' && can_regex) { 0 0 0
717 0 const char *rs = p;
718 0 p++;
719 0 int in_class = 0;
720 0 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 0 0 0
721 0 char ch = *p;
722 0 ▶ if (ch == '\\' && p + 1 < end) { p += 2; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
if (ch == '\\' && p + 1 < end) { p += 2; continue; } 0 0 0
723 0 ▶ if (!in_class && ch == '[') { in_class = 1; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (!in_class && ch == '[') { in_class = 1; p++; continue; } 0 0 0
if (!in_class && ch == '[') { in_class = 1; p++; continue; } 0 0 0
724 0 ▶ if (in_class && ch == ']') { in_class = 0; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (in_class && ch == ']') { in_class = 0; p++; continue; } 0 0 0
if (in_class && ch == ']') { in_class = 0; p++; continue; } 0 0 0
725 0 ▶ if (!in_class && ch == '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (!in_class && ch == '/') { 0 0 0
if (!in_class && ch == '/') { 0 0 0
726 0 p++;
727 0 ▶ while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' ||
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 0 0
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 0 0
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 0 0
while (p < end && (*p == 'i' || *p == 'm' || *p == 'x' || 0 0 0
728 0 ▶ *p == 's' || *p == 'u' || *p == 'e'))
Branch: 3 branches
BranchTrueFalseTotal
*p == 's' || *p == 'u' || *p == 'e')) 0 0 0
*p == 's' || *p == 'u' || *p == 'e')) 0 0 0
*p == 's' || *p == 'u' || *p == 'e')) 0 0 0
729 0 p++;
730 0 break;
731 }
732 0 ▶ if (ch == '\n') break;
Branch: 1 branch
BranchTrueFalseTotal
if (ch == '\n') break; 0 0 0
733 0 p++;
734 }
735 0 RB_SPAN("esh-r", rs, p - rs);
736 0 can_regex = 0;
737 0 continue;
738 }
739  
740 /* ── symbol :name or :"..." ──────────────────────────────── */
741 298 ▶ if (c == ':' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == ':' && p + 1 < end) { 10 288 298
if (c == ':' && p + 1 < end) { 10 0 10
742 10 char nx = *(p+1);
743 10 ▶ if (nx != ':' && (isalpha((unsigned char)nx) || nx == '_' ||
Branch: 4 branches
BranchTrueFalseTotal
if (nx != ':' && (isalpha((unsigned char)nx) || nx == '_' || 10 0 10
if (nx != ':' && (isalpha((unsigned char)nx) || nx == '_' || 1 9 10
if (nx != ':' && (isalpha((unsigned char)nx) || nx == '_' || 1 0 1
if (nx != ':' && (isalpha((unsigned char)nx) || nx == '_' || 0 1 1
744 0 ▶ nx == '"' || nx == '\'')) {
Branch: 1 branch
BranchTrueFalseTotal
nx == '"' || nx == '\'')) { 0 0 0
745 10 const char *ss = p;
746 10 p++;
747 10 ▶ if (*p == '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '"') { 1 9 10
748 1 p++;
749 11 ▶ while (p < end && *p != '"') {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '"') { 11 0 11
while (p < end && *p != '"') { 10 1 11
750 10 ▶ if (*p == '\\' && p + 1 < end) p++;
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\' && p + 1 < end) p++; 0 10 10
if (*p == '\\' && p + 1 < end) p++; 0 0 0
751 10 p++;
752 }
753 1 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 1 0 1
754 9 ▶ } else if (*p == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (*p == '\'') { 0 9 9
755 0 p++;
756 0 ▶ while (p < end && *p != '\'') {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\'') { 0 0 0
while (p < end && *p != '\'') { 0 0 0
757 0 ▶ if (*p == '\\' && p + 1 < end) p++;
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\' && p + 1 < end) p++; 0 0 0
if (*p == '\\' && p + 1 < end) p++; 0 0 0
758 0 p++;
759 }
760 0 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 0 0 0
761 } else {
762 34 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_' ||
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || 30 4 34
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || 25 5 30
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || 0 5 5
763 5 ▶ *p == '?' || *p == '!'))
Branch: 2 branches
BranchTrueFalseTotal
*p == '?' || *p == '!')) 0 5 5
*p == '?' || *p == '!')) 0 5 5
764 25 p++;
765 }
766 10 RB_SPAN("esh-r", ss, p - ss);
767 10 can_regex = 0;
768 10 continue;
769 }
770 }
771  
772 /* ── special variables $global @iv @@cv ─────────────────── */
773 288 ▶ if ((c == '$' && p + 1 < end && (isalpha((unsigned char)*(p+1)) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((c == '$' && p + 1 < end && (isalpha((unsigned char)*(p+1)) || 3 285 288
if ((c == '$' && p + 1 < end && (isalpha((unsigned char)*(p+1)) || 3 0 3
if ((c == '$' && p + 1 < end && (isalpha((unsigned char)*(p+1)) || 1 2 3
774 286 ▶ *(p+1) == '_' || *(p+1) == '0')) ||
Branch: 3 branches
BranchTrueFalseTotal
*(p+1) == '_' || *(p+1) == '0')) || 1 0 1
*(p+1) == '_' || *(p+1) == '0')) || 0 1 1
*(p+1) == '_' || *(p+1) == '0')) || 2 283 285
775 2 ▶ (c == '@' && p + 1 < end && (isalpha((unsigned char)*(p+1)) ||
Branch: 2 branches
BranchTrueFalseTotal
(c == '@' && p + 1 < end && (isalpha((unsigned char)*(p+1)) || 2 0 2
(c == '@' && p + 1 < end && (isalpha((unsigned char)*(p+1)) || 1 1 2
776 1 ▶ *(p+1) == '_' || *(p+1) == '@'))) {
Branch: 2 branches
BranchTrueFalseTotal
*(p+1) == '_' || *(p+1) == '@'))) { 1 0 1
*(p+1) == '_' || *(p+1) == '@'))) { 1 0 1
777 5 const char *vs = p;
778 5 ▶ if (c == '@' && *(p+1) == '@') p++;
Branch: 2 branches
BranchTrueFalseTotal
if (c == '@' && *(p+1) == '@') p++; 2 3 5
if (c == '@' && *(p+1) == '@') p++; 1 1 2
779 5 p++;
780 32 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 30 2 32
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 26 4 30
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 1 3 4
781 5 RB_SPAN("esh-v", vs, p - vs);
782 5 can_regex = 0;
783 5 continue;
784 }
785  
786 /* ── number ──────────────────────────────────────────────── */
787 283 ▶ if (isdigit(c) || (c == '.' && p + 1 < end && isdigit((unsigned char)*(p+1)))) {
Branch: 4 branches
BranchTrueFalseTotal
if (isdigit(c) || (c == '.' && p + 1 < end && isdigit((unsigned char)*(p+1)))) { 272 11 283
if (isdigit(c) || (c == '.' && p + 1 < end && isdigit((unsigned char)*(p+1)))) { 2 270 272
if (isdigit(c) || (c == '.' && p + 1 < end && isdigit((unsigned char)*(p+1)))) { 2 0 2
if (isdigit(c) || (c == '.' && p + 1 < end && isdigit((unsigned char)*(p+1)))) { 1 1 2
788 12 const char *ns = p;
789 12 ▶ if (c == '0' && p + 1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) {
Branch: 4 branches
BranchTrueFalseTotal
if (c == '0' && p + 1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { 2 10 12
if (c == '0' && p + 1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { 2 0 2
if (c == '0' && p + 1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { 1 1 2
if (c == '0' && p + 1 < end && (*(p+1) == 'x' || *(p+1) == 'X')) { 0 1 1
790 1 p += 2;
791 3 ▶ while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; 2 1 3
while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; 2 0 2
while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; 0 0 0
792 11 ▶ } else if (c == '0' && p + 1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (c == '0' && p + 1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { 1 10 11
} else if (c == '0' && p + 1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { 1 0 1
} else if (c == '0' && p + 1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { 0 1 1
} else if (c == '0' && p + 1 < end && (*(p+1) == 'b' || *(p+1) == 'B')) { 0 0 0
793 1 p += 2;
794 5 ▶ while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++;
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; 4 1 5
while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; 2 2 4
while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; 2 0 2
while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; 0 0 0
795 10 ▶ } else if (c == '0' && p + 1 < end && (*(p+1) == 'o' || *(p+1) == 'O')) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (c == '0' && p + 1 < end && (*(p+1) == 'o' || *(p+1) == 'O')) { 0 10 10
} else if (c == '0' && p + 1 < end && (*(p+1) == 'o' || *(p+1) == 'O')) { 0 0 0
} else if (c == '0' && p + 1 < end && (*(p+1) == 'o' || *(p+1) == 'O')) { 0 0 0
} else if (c == '0' && p + 1 < end && (*(p+1) == 'o' || *(p+1) == 'O')) { 0 0 0
796 0 p += 2;
797 0 ▶ while (p < end && ((*p >= '0' && *p <= '7') || *p == '_')) p++;
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && ((*p >= '0' && *p <= '7') || *p == '_')) p++; 0 0 0
while (p < end && ((*p >= '0' && *p <= '7') || *p == '_')) p++; 0 0 0
while (p < end && ((*p >= '0' && *p <= '7') || *p == '_')) p++; 0 0 0
while (p < end && ((*p >= '0' && *p <= '7') || *p == '_')) p++; 0 0 0
798 } else {
799 20 ▶ while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 15 5 20
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 10 5 15
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 0 5 5
800 10 ▶ if (p < end && *p == '.') {
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '.') { 5 5 10
if (p < end && *p == '.') { 3 2 5
801 3 p++;
802 7 ▶ while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 6 1 7
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 4 2 6
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 0 2 2
803 }
804 10 ▶ if (p < end && (*p == 'e' || *p == 'E')) {
Branch: 3 branches
BranchTrueFalseTotal
if (p < end && (*p == 'e' || *p == 'E')) { 4 6 10
if (p < end && (*p == 'e' || *p == 'E')) { 4 0 4
if (p < end && (*p == 'e' || *p == 'E')) { 0 4 4
805 0 p++;
806 0 ▶ if (p < end && (*p == '+' || *p == '-')) p++;
Branch: 3 branches
BranchTrueFalseTotal
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
807 0 ▶ while (p < end && isdigit((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isdigit((unsigned char)*p)) p++; 0 0 0
while (p < end && isdigit((unsigned char)*p)) p++; 0 0 0
808 }
809 }
810 12 RB_SPAN("esh-n", ns, p - ns);
811 12 can_regex = 0;
812 12 continue;
813 }
814  
815 /* ── keyword / identifier ────────────────────────────────── */
816 271 ▶ if (isalpha(c) || c == '_') {
Branch: 2 branches
BranchTrueFalseTotal
if (isalpha(c) || c == '_') { 162 109 271
if (isalpha(c) || c == '_') { 3 159 162
817 112 const char *ts = p;
818 599 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 578 21 599
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 469 109 578
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; 18 91 109
819 /* Ruby allows ? and ! at end of method names */
820 112 ▶ if (p < end && (*p == '?' || *p == '!') &&
Branch: 3 branches
BranchTrueFalseTotal
if (p < end && (*p == '?' || *p == '!') && 91 21 112
if (p < end && (*p == '?' || *p == '!') && 90 1 91
if (p < end && (*p == '?' || *p == '!') && 0 90 90
821 1 ▶ !(p + 1 < end && *(p+1) == '='))
Branch: 2 branches
BranchTrueFalseTotal
!(p + 1 < end && *(p+1) == '=')) 1 0 1
!(p + 1 < end && *(p+1) == '=')) 1 0 1
822 1 p++;
823 112 size_t wlen = (size_t)(p - ts);
824 112 ▶ if (eshu_hl_kw(ts, wlen, eshu_hl_rb_kw)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_hl_kw(ts, wlen, eshu_hl_rb_kw)) { 57 55 112
825 57 RB_SPAN("esh-k", ts, wlen);
826 57 can_regex = 1;
827 55 ▶ } else if (eshu_hl_kw(ts, wlen, eshu_hl_rb_bi)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (eshu_hl_kw(ts, wlen, eshu_hl_rb_bi)) { 19 36 55
828 19 RB_SPAN("esh-b", ts, wlen);
829 19 can_regex = 0;
830 } else {
831 36 can_regex = 0;
832 }
833 112 continue;
834 }
835  
836 /* ── update can_regex for operators ──────────────────────── */
837 159 ▶ if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' ||
Branch: 6 branches
BranchTrueFalseTotal
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 152 7 159
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 151 1 152
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 150 1 151
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 150 0 150
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 148 2 150
if (c == '=' || c == '(' || c == ',' || c == '[' || c == '{' || 148 0 148
838 148 ▶ c == '!' || c == '&' || c == '|' || c == '+' || c == '-' ||
Branch: 5 branches
BranchTrueFalseTotal
c == '!' || c == '&' || c == '|' || c == '+' || c == '-' || 148 0 148
c == '!' || c == '&' || c == '|' || c == '+' || c == '-' || 144 4 148
c == '!' || c == '&' || c == '|' || c == '+' || c == '-' || 144 0 144
c == '!' || c == '&' || c == '|' || c == '+' || c == '-' || 144 0 144
c == '!' || c == '&' || c == '|' || c == '+' || c == '-' || 144 0 144
839 144 ▶ c == '*' || c == '<' || c == '>' || c == ';' || c == '\n') {
Branch: 4 branches
BranchTrueFalseTotal
c == '*' || c == '<' || c == '>' || c == ';' || c == '\n') { 142 2 144
c == '*' || c == '<' || c == '>' || c == ';' || c == '\n') { 140 2 142
c == '*' || c == '<' || c == '>' || c == ';' || c == '\n') { 115 25 140
c == '*' || c == '<' || c == '>' || c == ';' || c == '\n') { 0 115 115
840 44 can_regex = 1;
841 115 ▶ } else if (c == ')' || c == ']' || c == '}') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (c == ')' || c == ']' || c == '}') { 114 1 115
} else if (c == ')' || c == ']' || c == '}') { 114 0 114
} else if (c == ')' || c == ']' || c == '}') { 2 112 114
842 3 can_regex = 0;
843 }
844  
845 159 p++;
846 }
847  
848 47 eshu_hl_flush(&out, plain, end);
849 47 eshu_buf_putc(&out, '\0');
850 47 *out_len = out.len - 1;
851 47 return out.data;
852  
853 #undef RB_SPAN
854 }
855  
856 #endif /* ESHU_RUBY_H */
« include/eshu_ts.h ↑ Summary include/eshu_php.h »