include/eshu_pl.h

filter: Statementstmt 93.3% 655 / 702 Branchbran 72.0% 637 / 884 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.4% 1292 / 1586 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/eshu_xs.h ↑ Summary include/eshu_diff.h »
1 /*
2 * eshu_pl.h — Perl language indentation scanner
3 *
4 * Tracks {} () [] nesting depth while skipping strings, heredocs,
5 * regex, qw/qq/q constructs, pod sections, and comments.
6 * Rewrites leading whitespace only.
7 */
8  
9 #ifndef ESHU_PL_H
10 #define ESHU_PL_H
11  
12 #include "eshu.h"
13  
14 #define ESHU_PL_HEREDOC_MAX 64 /* max length of heredoc terminator */
15 #define ESHU_PL_QDEPTH_MAX 8 /* max nesting depth for paired delims */
16  
17 /* ══════════════════════════════════════════════════════════════════
18 * Scanner context — persists across lines
19 * ══════════════════════════════════════════════════════════════════ */
20  
21 typedef struct {
22 int depth; /* brace/paren/bracket nesting */
23 enum eshu_state state; /* current scanner state */
24 eshu_config_t cfg;
25  
26 /* Heredoc tracking */
27 char heredoc_tag[ESHU_PL_HEREDOC_MAX];
28 int heredoc_tag_len;
29 int heredoc_indented; /* <<~ variant */
30 int heredoc_pending; /* heredoc detected, body starts next line */
31  
32 /* Quoted construct tracking (qw, qq, q, s, tr, y, m) */
33 char q_open; /* opening delimiter */
34 char q_close; /* closing delimiter (0 for non-paired) */
35 int q_depth; /* nesting depth for paired delimiters */
36 int q_sections; /* remaining sections (2 for s///, 1 for others) */
37  
38 /* Regex tracking */
39 char rx_delim; /* regex delimiter char */
40  
41 /* Track whether last significant token could precede division */
42 int last_was_value; /* 1 if last token was var/number/)/] */
43  
44 /* POD buffering */
45 eshu_buf_t pod_buf;
46 int pod_active;
47  
48 /* __END__ / __DATA__ — everything after is non-code */
49 int past_end;
50  
51 /* Paren suppression: when ( and { appear on the same line
52 * (e.g. method(sub {), the ( doesn't add structural indent.
53 * Track suppressed ( so matching ) doesn't decrement depth. */
54 int suppressed_parens;
55  
56 /* Per-line delta tracking for suppression detection */
57 int line_paren_delta;
58 int line_brace_delta;
59 int line_bracket_delta;
60 } eshu_pl_ctx_t;
61  
62 270 static void eshu_pl_ctx_init(eshu_pl_ctx_t *ctx, const eshu_config_t *cfg) {
63 270 ctx->depth = 0;
64 270 ctx->state = ESHU_CODE;
65 270 ctx->cfg = *cfg;
66 270 ctx->heredoc_tag[0] = '\0';
67 270 ctx->heredoc_tag_len = 0;
68 270 ctx->heredoc_indented = 0;
69 270 ctx->heredoc_pending = 0;
70 270 ctx->q_open = 0;
71 270 ctx->q_close = 0;
72 270 ctx->q_depth = 0;
73 270 ctx->q_sections = 0;
74 270 ctx->rx_delim = 0;
75 270 ctx->last_was_value = 0;
76 270 eshu_buf_init(&ctx->pod_buf, 256);
77 270 ctx->pod_active = 0;
78 270 ctx->past_end = 0;
79 270 ctx->suppressed_parens = 0;
80 270 ctx->line_paren_delta = 0;
81 270 ctx->line_brace_delta = 0;
82 270 ctx->line_bracket_delta = 0;
83 270 }
84  
85 /* ══════════════════════════════════════════════════════════════════
86 * Delimiter helpers
87 * ══════════════════════════════════════════════════════════════════ */
88  
89 43 static char eshu_pl_matching_close(char open) {
90 43 switch (open) {
91 21 case '(': return ')';
92 18 case '{': return '}';
93 1 case '[': return ']';
94 3 case '<': return '>';
95 0 default: return 0; /* non-paired: same char closes */
96 }
97 }
98  
99 60 static int eshu_pl_is_paired(char c) {
100 60 ▶ return c == '(' || c == '{' || c == '[' || c == '<';
Branch: 4 branches
BranchTrueFalseTotal
return c == '(' || c == '{' || c == '[' || c == '<'; 39 21 60
return c == '(' || c == '{' || c == '[' || c == '<'; 21 18 39
return c == '(' || c == '{' || c == '[' || c == '<'; 20 1 21
return c == '(' || c == '{' || c == '[' || c == '<'; 3 17 20
101 }
102  
103 /* ══════════════════════════════════════════════════════════════════
104 * Heredoc detection
105 *
106 * Recognises: <<EOF <<'EOF' <<"EOF" <<~EOF <<~'EOF' <<~"EOF"
107 * Sets heredoc_pending=1 so the NEXT line enters heredoc state.
108 * ══════════════════════════════════════════════════════════════════ */
109  
110 35 static int eshu_pl_detect_heredoc(eshu_pl_ctx_t *ctx,
111 const char *p, const char *end) {
112 const char *start;
113 35 int indented = 0;
114 35 char quote = 0;
115 int len;
116  
117 /* p points to the first '<' — we need "<<" */
118 35 ▶ if (p + 1 >= end || *(p + 1) != '<')
Branch: 2 branches
BranchTrueFalseTotal
if (p + 1 >= end || *(p + 1) != '<') 35 0 35
if (p + 1 >= end || *(p + 1) != '<') 18 17 35
119 18 return 0;
120 17 p += 2;
121  
122 /* optional ~ for indented heredoc */
123 17 ▶ if (p < end && *p == '~') {
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '~') { 17 0 17
if (p < end && *p == '~') { 1 16 17
124 1 indented = 1;
125 1 p++;
126 }
127  
128 /* optional quote */
129 17 ▶ if (p < end && (*p == '\'' || *p == '"' || *p == '`')) {
Branch: 4 branches
BranchTrueFalseTotal
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 17 0 17
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 10 7 17
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 9 1 10
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 0 9 9
130 8 quote = *p;
131 8 p++;
132 }
133  
134 /* identifier */
135 17 start = p;
136 84 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_'))
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 84 0 84
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 67 17 84
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 0 17 17
137 67 p++;
138 17 len = (int)(p - start);
139 17 ▶ if (len == 0 || len >= ESHU_PL_HEREDOC_MAX)
Branch: 2 branches
BranchTrueFalseTotal
if (len == 0 || len >= ESHU_PL_HEREDOC_MAX) 17 0 17
if (len == 0 || len >= ESHU_PL_HEREDOC_MAX) 0 17 17
140 0 return 0;
141  
142 /* closing quote must match */
143 17 ▶ if (quote && (p >= end || *p != quote))
Branch: 3 branches
BranchTrueFalseTotal
if (quote && (p >= end || *p != quote)) 8 9 17
if (quote && (p >= end || *p != quote)) 8 0 8
if (quote && (p >= end || *p != quote)) 0 8 8
144 0 return 0;
145  
146 17 memcpy(ctx->heredoc_tag, start, len);
147 17 ctx->heredoc_tag[len] = '\0';
148 17 ctx->heredoc_tag_len = len;
149 17 ctx->heredoc_indented = indented;
150 17 ctx->heredoc_pending = 1;
151  
152 17 return 1;
153 }
154  
155 /* ══════════════════════════════════════════════════════════════════
156 * Check if line is a heredoc terminator
157 * ══════════════════════════════════════════════════════════════════ */
158  
159 66 static int eshu_pl_is_heredoc_end(const eshu_pl_ctx_t *ctx,
160 const char *line, const char *eol) {
161 66 const char *p = line;
162 int len;
163  
164 /* for <<~ the terminator may be indented */
165 66 ▶ if (ctx->heredoc_indented) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->heredoc_indented) { 3 63 66
166 15 ▶ while (p < eol && (*p == ' ' || *p == '\t'))
Branch: 3 branches
BranchTrueFalseTotal
while (p < eol && (*p == ' ' || *p == '\t')) 15 0 15
while (p < eol && (*p == ' ' || *p == '\t')) 12 3 15
while (p < eol && (*p == ' ' || *p == '\t')) 0 3 3
167 12 p++;
168 }
169  
170 66 len = (int)(eol - p);
171 /* terminator may have trailing ; or whitespace but we'll be strict:
172 the line content (trimmed) must exactly match the tag */
173 66 ▶ if (len < ctx->heredoc_tag_len)
Branch: 1 branch
BranchTrueFalseTotal
if (len < ctx->heredoc_tag_len) 0 66 66
174 0 return 0;
175  
176 66 ▶ if (memcmp(p, ctx->heredoc_tag, ctx->heredoc_tag_len) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(p, ctx->heredoc_tag, ctx->heredoc_tag_len) != 0) 49 17 66
177 49 return 0;
178  
179 /* rest of line must be empty or just whitespace/semicolons */
180 17 p += ctx->heredoc_tag_len;
181 17 ▶ while (p < eol) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < eol) { 0 17 17
182 0 ▶ if (*p != ' ' && *p != '\t' && *p != ';')
Branch: 3 branches
BranchTrueFalseTotal
if (*p != ' ' && *p != '\t' && *p != ';') 0 0 0
if (*p != ' ' && *p != '\t' && *p != ';') 0 0 0
if (*p != ' ' && *p != '\t' && *p != ';') 0 0 0
183 0 return 0;
184 0 p++;
185 }
186 17 return 1;
187 }
188  
189 /* ══════════════════════════════════════════════════════════════════
190 * Pod detection — "=word" at start of line
191 * ══════════════════════════════════════════════════════════════════ */
192  
193 1675 static int eshu_pl_is_pod_start(const char *content, const char *eol) {
194 1675 ▶ if (*content != '=')
Branch: 1 branch
BranchTrueFalseTotal
if (*content != '=') 1649 26 1675
195 1649 return 0;
196 /* must be followed by a letter */
197 26 ▶ if (content + 1 >= eol || !isalpha((unsigned char)content[1]))
Branch: 2 branches
BranchTrueFalseTotal
if (content + 1 >= eol || !isalpha((unsigned char)content[1])) 26 0 26
if (content + 1 >= eol || !isalpha((unsigned char)content[1])) 0 26 26
198 0 return 0;
199 /* must NOT be =cut */
200 26 ▶ if (eol - content >= 4 && memcmp(content, "=cut", 4) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (eol - content >= 4 && memcmp(content, "=cut", 4) == 0) 26 0 26
if (eol - content >= 4 && memcmp(content, "=cut", 4) == 0) 0 26 26
201 0 return 0;
202 26 return 1;
203 }
204  
205 1141 static int eshu_pl_is_pod_end(const char *content, const char *eol) {
206 1141 int len = (int)(eol - content);
207 1141 ▶ if (len < 4) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len < 4) return 0; 13 1128 1141
208 1128 ▶ if (memcmp(content, "=cut", 4) != 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(content, "=cut", 4) != 0) return 0; 1104 24 1128
209 /* rest should be whitespace or EOL */
210 24 ▶ if (len > 4 && content[4] != ' ' && content[4] != '\t')
Branch: 3 branches
BranchTrueFalseTotal
if (len > 4 && content[4] != ' ' && content[4] != '\t') 0 24 24
if (len > 4 && content[4] != ' ' && content[4] != '\t') 0 0 0
if (len > 4 && content[4] != ' ' && content[4] != '\t') 0 0 0
211 0 return 0;
212 24 return 1;
213 }
214  
215 /* ══════════════════════════════════════════════════════════════════
216 * Classify whether a preceding context expects regex or division
217 *
218 * Returns 1 if the next '/' should be treated as regex opening.
219 * ══════════════════════════════════════════════════════════════════ */
220  
221 82 static int eshu_pl_expects_regex(const eshu_pl_ctx_t *ctx) {
222 /*
223 * If last token was a "value" (variable, number, closing bracket/paren)
224 * then / is division. Otherwise it's regex.
225 */
226 82 return !ctx->last_was_value;
227 }
228  
229 /* ══════════════════════════════════════════════════════════════════
230 * Enter a quoted construct (q/qq/qw/qx/s/tr/y/m)
231 *
232 * p points to the character AFTER the keyword letter(s).
233 * Returns the number of chars consumed for the delimiter.
234 * ══════════════════════════════════════════════════════════════════ */
235  
236 60 static int eshu_pl_enter_quoted(eshu_pl_ctx_t *ctx, char delim,
237 int sections, enum eshu_state state) {
238 60 ctx->q_open = delim;
239 60 ctx->q_sections = sections;
240 60 ▶ if (eshu_pl_is_paired(delim)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_pl_is_paired(delim)) { 43 17 60
241 43 ctx->q_close = eshu_pl_matching_close(delim);
242 43 ctx->q_depth = 1;
243 } else {
244 17 ctx->q_close = delim;
245 17 ctx->q_depth = 0; /* non-paired don't nest */
246 }
247 60 ctx->state = state;
248 60 return 1; /* consumed the delimiter char */
249 }
250  
251 /* ══════════════════════════════════════════════════════════════════
252 * Try to detect q/qq/qw/qx/s/tr/y/m constructs
253 *
254 * p points to a char that may be q, s, t, m, y.
255 * Returns chars consumed (including keyword + delimiter) or 0.
256 * ══════════════════════════════════════════════════════════════════ */
257  
258 1049 static int eshu_pl_try_q_construct(eshu_pl_ctx_t *ctx,
259 const char *p, const char *end) {
260 1049 const char *start = p;
261 1049 char c = *p;
262 1049 int sections = 1;
263 1049 enum eshu_state st = ESHU_Q;
264  
265 1049 ▶ if (c == 'q') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == 'q') { 35 1014 1049
266 35 p++;
267 35 ▶ if (p < end && *(p) == 'w') {
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *(p) == 'w') { 35 0 35
if (p < end && *(p) == 'w') { 18 17 35
268 18 p++; st = ESHU_QW;
269 17 ▶ } else if (p < end && *(p) == 'q') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && *(p) == 'q') { 17 0 17
} else if (p < end && *(p) == 'q') { 8 9 17
270 8 p++; st = ESHU_QQ;
271 9 ▶ } else if (p < end && *(p) == 'x') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && *(p) == 'x') { 9 0 9
} else if (p < end && *(p) == 'x') { 1 8 9
272 1 p++; st = ESHU_QQ; /* qx behaves like qq */
273 8 ▶ } else if (p < end && *(p) == 'r') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && *(p) == 'r') { 8 0 8
} else if (p < end && *(p) == 'r') { 5 3 8
274 5 p++; st = ESHU_QQ; /* qr// behaves like qq for scanning */
275 } else {
276 3 st = ESHU_Q;
277 }
278 1014 ▶ } else if (c == 's') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == 's') { 475 539 1014
279 475 p++;
280 475 sections = 2;
281 475 st = ESHU_QQ; /* s/// — two sections, interpolates */
282 539 ▶ } else if (c == 't' && p + 1 < end && *(p + 1) == 'r') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (c == 't' && p + 1 < end && *(p + 1) == 'r') { 3 536 539
} else if (c == 't' && p + 1 < end && *(p + 1) == 'r') { 3 0 3
} else if (c == 't' && p + 1 < end && *(p + 1) == 'r') { 3 0 3
283 3 p += 2;
284 3 sections = 2;
285 3 st = ESHU_QQ;
286 536 ▶ } else if (c == 'y') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == 'y') { 5 531 536
287 5 p++;
288 5 sections = 2;
289 5 st = ESHU_QQ;
290 531 ▶ } else if (c == 'm') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == 'm') { 531 0 531
291 531 p++;
292 531 st = ESHU_QQ; /* m// uses same delimiter tracking as qq */
293 } else {
294 0 return 0;
295 }
296  
297 /* Must be followed by a non-alnum delimiter */
298 1049 ▶ if (p >= end)
Branch: 1 branch
BranchTrueFalseTotal
if (p >= end) 0 1049 1049
299 0 return 0;
300 1049 ▶ if (isalnum((unsigned char)*p) || *p == '_')
Branch: 2 branches
BranchTrueFalseTotal
if (isalnum((unsigned char)*p) || *p == '_') 57 992 1049
if (isalnum((unsigned char)*p) || *p == '_') 0 57 57
301 992 return 0;
302 57 ▶ if (*p == ' ' || *p == '\t' || *p == '\n')
Branch: 3 branches
BranchTrueFalseTotal
if (*p == ' ' || *p == '\t' || *p == '\n') 54 3 57
if (*p == ' ' || *p == '\t' || *p == '\n') 54 0 54
if (*p == ' ' || *p == '\t' || *p == '\n') 0 54 54
303 3 return 0;
304  
305 54 eshu_pl_enter_quoted(ctx, *p, sections, st);
306 54 p++;
307 54 return (int)(p - start);
308 }
309  
310 /* Check if the character before position p is a word character
311 * (to prevent matching 'eq' as 'q' construct, etc.) */
312 1615 static int eshu_pl_preceded_by_word(const char *line_start, const char *p) {
313 1615 ▶ if (p <= line_start)
Branch: 1 branch
BranchTrueFalseTotal
if (p <= line_start) 751 864 1615
314 751 return 0;
315 864 ▶ return isalnum((unsigned char)*(p - 1)) || *(p - 1) == '_';
Branch: 2 branches
BranchTrueFalseTotal
return isalnum((unsigned char)*(p - 1)) || *(p - 1) == '_'; 347 517 864
return isalnum((unsigned char)*(p - 1)) || *(p - 1) == '_'; 0 347 347
316 }
317  
318 /* ══════════════════════════════════════════════════════════════════
319 * Scan a line for nesting changes (Perl-aware)
320 *
321 * Called AFTER the line has been emitted. Updates ctx->state
322 * and ctx->depth for the next line.
323 * ══════════════════════════════════════════════════════════════════ */
324  
325 2207 static void eshu_pl_scan_line(eshu_pl_ctx_t *ctx,
326 const char *p, const char *end) {
327 2207 const char *line_start = p;
328  
329 22098 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 19919 2179 22098
330 19919 char c = *p;
331  
332 19919 switch (ctx->state) {
333 17056 case ESHU_CODE:
334 17056 ▶ if (c == '{' || c == '(' || c == '[') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '{' || c == '(' || c == '[') { 16119 937 17056
if (c == '{' || c == '(' || c == '[') { 15662 457 16119
if (c == '{' || c == '(' || c == '[') { 79 15583 15662
335 1473 ctx->depth++;
336 1473 ▶ if (c == '(') ctx->line_paren_delta++;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '(') ctx->line_paren_delta++; 457 1016 1473
337 1016 ▶ else if (c == '{') ctx->line_brace_delta++;
Branch: 1 branch
BranchTrueFalseTotal
else if (c == '{') ctx->line_brace_delta++; 937 79 1016
338 79 else ctx->line_bracket_delta++;
339 1473 ctx->last_was_value = 0;
340 15583 ▶ } else if (c == '}' || c == ']') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == '}' || c == ']') { 14646 937 15583
} else if (c == '}' || c == ']') { 79 14567 14646
341 1016 ctx->depth--;
342 1016 ▶ if (ctx->depth < 0) ctx->depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->depth < 0) ctx->depth = 0; 0 1016 1016
343 1016 ▶ if (c == '}') ctx->line_brace_delta--;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '}') ctx->line_brace_delta--; 937 79 1016
344 79 else ctx->line_bracket_delta--;
345 1016 ctx->last_was_value = 1;
346 14567 ▶ } else if (c == ')') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == ')') { 457 14110 14567
347 457 ▶ if (ctx->line_paren_delta > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->line_paren_delta > 0) { 436 21 457
348 /* closing a ( from this line — normal */
349 436 ctx->line_paren_delta--;
350 436 ctx->depth--;
351 436 ▶ if (ctx->depth < 0) ctx->depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->depth < 0) ctx->depth = 0; 0 436 436
352 21 ▶ } else if (ctx->suppressed_parens > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ctx->suppressed_parens > 0) { 7 14 21
353 /* closing a suppressed ( — don't change depth */
354 7 ctx->suppressed_parens--;
355 } else {
356 14 ctx->depth--;
357 14 ▶ if (ctx->depth < 0) ctx->depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->depth < 0) ctx->depth = 0; 0 14 14
358 }
359 457 ctx->last_was_value = 1;
360 14110 ▶ } else if (c == '"') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == '"') { 71 14039 14110
361 71 ctx->state = ESHU_STRING_DQ;
362 71 ctx->last_was_value = 0;
363 14039 ▶ } else if (c == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == '\'') { 120 13919 14039
364 120 ctx->state = ESHU_STRING_SQ;
365 120 ctx->last_was_value = 0;
366 13919 ▶ } else if (c == '#') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == '#') { 28 13891 13919
367 /* line comment — skip rest */
368 28 ctx->last_was_value = 0;
369 28 return;
370 13891 ▶ } else if (c == '<' && eshu_pl_detect_heredoc(ctx, p, end)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == '<' && eshu_pl_detect_heredoc(ctx, p, end)) { 35 13856 13891
} else if (c == '<' && eshu_pl_detect_heredoc(ctx, p, end)) { 17 18 35
371 /* heredoc_pending is set; continue scanning rest of line */
372 /* skip past the heredoc operator to avoid re-matching */
373 17 p += 2; /* skip << */
374 17 ▶ if (p < end && *p == '~') p++;
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '~') p++; 17 0 17
if (p < end && *p == '~') p++; 1 16 17
375 25 ▶ if (p < end && (*p == '\'' || *p == '"' || *p == '`')) {
Branch: 4 branches
BranchTrueFalseTotal
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 17 0 17
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 10 7 17
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 9 1 10
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 0 9 9
376 8 char hq = *p; p++;
377 36 ▶ while (p < end && *p != hq) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != hq) p++; 36 0 36
while (p < end && *p != hq) p++; 28 8 36
378 8 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 8 0 8
379 } else {
380 48 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_'))
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 48 0 48
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 39 9 48
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 0 9 9
381 39 p++;
382 }
383 17 ctx->last_was_value = 1;
384 17 continue;
385 13874 ▶ } else if (c == '/' && eshu_pl_expects_regex(ctx)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == '/' && eshu_pl_expects_regex(ctx)) { 48 13826 13874
} else if (c == '/' && eshu_pl_expects_regex(ctx)) { 14 34 48
386 /* Check for // (defined-or) — not a regex even in regex context */
387 14 ▶ if (p + 1 < end && *(p + 1) == '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (p + 1 < end && *(p + 1) == '/') { 13 1 14
if (p + 1 < end && *(p + 1) == '/') { 0 13 13
388 /* // or //= — defined-or operator */
389 0 p += 2;
390 0 ▶ if (p < end && *p == '=') p++; /* //= */
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '=') p++; /* //= */ 0 0 0
if (p < end && *p == '=') p++; /* //= */ 0 0 0
391 0 ctx->last_was_value = 0;
392 0 continue;
393 }
394 /* regex literal */
395 14 ctx->rx_delim = '/';
396 14 ctx->state = ESHU_REGEX;
397 14 ctx->last_was_value = 0;
398 13860 ▶ } else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' ||
Branch: 5 branches
BranchTrueFalseTotal
} else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' || 13825 35 13860
} else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' || 13272 553 13825
} else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' || 12776 496 13272
} else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' || 12274 502 12776
} else if ((c == 'q' || c == 'm' || c == 's' || c == 'y' || 65 12209 12274
399 1680 ▶ (c == 't' && p + 1 < end && *(p + 1) == 'r')) &&
Branch: 1 branch
BranchTrueFalseTotal
(c == 't' && p + 1 < end && *(p + 1) == 'r')) && 65 0 65
400 2713 ▶ !eshu_pl_preceded_by_word(line_start, p) &&
Branch: 1 branch
BranchTrueFalseTotal
!eshu_pl_preceded_by_word(line_start, p) && 347 751 1098
401 1342 ▶ !(p > line_start && *(p - 1) == '{')) {
Branch: 1 branch
BranchTrueFalseTotal
!(p > line_start && *(p - 1) == '{')) { 298 49 347
402 1049 int consumed = eshu_pl_try_q_construct(ctx, p, end);
403 1049 ▶ if (consumed > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (consumed > 0) { 54 995 1049
404 54 p += consumed;
405 54 ctx->last_was_value = 0;
406 54 continue;
407 }
408 /* not a q-construct, fall through */
409 995 ▶ if (isalnum((unsigned char)c))
Branch: 1 branch
BranchTrueFalseTotal
if (isalnum((unsigned char)c)) 995 0 995
410 995 ctx->last_was_value = 0;
411 12811 ▶ } else if (c == '/' && !eshu_pl_expects_regex(ctx)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == '/' && !eshu_pl_expects_regex(ctx)) { 34 12777 12811
} else if (c == '/' && !eshu_pl_expects_regex(ctx)) { 34 0 34
412 /* division or // (defined-or) operator */
413 34 ▶ if (p + 1 < end && *(p + 1) == '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (p + 1 < end && *(p + 1) == '/') { 34 0 34
if (p + 1 < end && *(p + 1) == '/') { 27 7 34
414 27 p += 2;
415 27 ▶ if (p < end && *p == '=') p++; /* //= */
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '=') p++; /* //= */ 27 0 27
if (p < end && *p == '=') p++; /* //= */ 11 16 27
416 27 ctx->last_was_value = 0;
417 27 continue;
418 }
419 7 ctx->last_was_value = 0;
420 12777 ▶ } else if (c == '$' || c == '@' || c == '%') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (c == '$' || c == '@' || c == '%') { 11347 1430 12777
} else if (c == '$' || c == '@' || c == '%') { 10972 375 11347
} else if (c == '$' || c == '@' || c == '%') { 88 10884 10972
421 /* variable sigil — skip the variable name */
422 1893 ctx->last_was_value = 1;
423 1893 p++;
424 /* $# is the "last index" operator: $#array, $#$ref */
425 1893 ▶ if (c == '$' && p < end && *p == '#') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '$' && p < end && *p == '#') { 1430 463 1893
if (c == '$' && p < end && *p == '#') { 1430 0 1430
if (c == '$' && p < end && *p == '#') { 8 1422 1430
426 8 p++;
427 /* $#$ref or $#{ — skip the extra sigil */
428 8 ▶ if (p < end && *p == '$')
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '$') 8 0 8
if (p < end && *p == '$') 4 4 8
429 4 p++;
430 }
431 7725 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == ':'))
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == ':')) 7722 3 7725
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == ':')) 5565 2157 7722
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == ':')) 259 1898 2157
while (p < end && (isalnum((unsigned char)*p) || *p == '_' || *p == ':')) 8 1890 1898
432 5832 p++;
433 1893 continue;
434 10884 ▶ } else if (isdigit((unsigned char)c)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (isdigit((unsigned char)c)) { 317 10567 10884
435 317 ctx->last_was_value = 1;
436 727 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '.' || *p == '_'))
Branch: 4 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '.' || *p == '_')) 725 2 727
while (p < end && (isalnum((unsigned char)*p) || *p == '.' || *p == '_')) 388 337 725
while (p < end && (isalnum((unsigned char)*p) || *p == '.' || *p == '_')) 22 315 337
while (p < end && (isalnum((unsigned char)*p) || *p == '.' || *p == '_')) 0 315 315
437 410 p++;
438 317 continue;
439 10567 ▶ } else if (c == '=' && p + 1 < end && *(p + 1) == '~') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (c == '=' && p + 1 < end && *(p + 1) == '~') { 681 9886 10567
} else if (c == '=' && p + 1 < end && *(p + 1) == '~') { 681 0 681
} else if (c == '=' && p + 1 < end && *(p + 1) == '~') { 31 650 681
440 /* =~ forces next / to be regex */
441 31 ctx->last_was_value = 0;
442 31 p += 2;
443 31 continue;
444 10536 ▶ } else if (c == '!' && p + 1 < end && *(p + 1) == '~') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (c == '!' && p + 1 < end && *(p + 1) == '~') { 19 10517 10536
} else if (c == '!' && p + 1 < end && *(p + 1) == '~') { 19 0 19
} else if (c == '!' && p + 1 < end && *(p + 1) == '~') { 0 19 19
445 0 ctx->last_was_value = 0;
446 0 p += 2;
447 0 continue;
448 10536 ▶ } else if (c == ' ' || c == '\t') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (c == ' ' || c == '\t') { 5913 4623 10536
} else if (c == ' ' || c == '\t') { 5913 0 5913
449 /* whitespace — don't change last_was_value */
450 5913 ▶ } else if (isalpha((unsigned char)c) || c == '_') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (isalpha((unsigned char)c) || c == '_') { 3333 2580 5913
} else if (isalpha((unsigned char)c) || c == '_') { 61 3272 3333
451 /* keyword or bareword — skip it */
452 2641 const char *ws = p;
453 12834 ▶ while (p < end && (isalnum((unsigned char)*p) || *p == '_'))
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 12833 1 12834
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 10003 2830 12833
while (p < end && (isalnum((unsigned char)*p) || *p == '_')) 190 2640 2830
454 10193 p++;
455 /* barewords ending in a value context: could be function call */
456 2641 ctx->last_was_value = 0;
457 2641 continue;
458 } else {
459 /* operator chars: = + - * etc */
460 3272 ctx->last_was_value = 0;
461 }
462 12048 break;
463  
464 981 case ESHU_STRING_DQ:
465 981 ▶ if (c == '\\' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { 48 933 981
if (c == '\\' && p + 1 < end) { 48 0 48
466 48 p++; /* skip escaped char */
467 933 ▶ } else if (c == '"') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == '"') { 71 862 933
468 71 ctx->state = ESHU_CODE;
469 71 ctx->last_was_value = 1;
470 }
471 981 break;
472  
473 771 case ESHU_STRING_SQ:
474 771 ▶ if (c == '\\' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { 1 770 771
if (c == '\\' && p + 1 < end) { 1 0 1
475 1 p++; /* skip escaped char */
476 770 ▶ } else if (c == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == '\'') { 120 650 770
477 120 ctx->state = ESHU_CODE;
478 120 ctx->last_was_value = 1;
479 }
480 771 break;
481  
482 146 case ESHU_REGEX:
483 146 ▶ if (c == '\\' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end) { 20 126 146
if (c == '\\' && p + 1 < end) { 20 0 20
484 20 p++; /* skip escaped char */
485 126 ▶ } else if (c == ctx->rx_delim) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == ctx->rx_delim) { 14 112 126
486 14 ctx->state = ESHU_CODE;
487 14 ctx->last_was_value = 1;
488 /* skip optional flags */
489 14 p++;
490 16 ▶ while (p < end && isalpha((unsigned char)*p))
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) 16 0 16
while (p < end && isalpha((unsigned char)*p)) 2 14 16
491 2 p++;
492 14 continue;
493 }
494 132 break;
495  
496 965 case ESHU_QW:
497 case ESHU_QQ:
498 case ESHU_Q:
499 965 ▶ if (c == '\\' && p + 1 < end && ctx->state != ESHU_QW) {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '\\' && p + 1 < end && ctx->state != ESHU_QW) { 27 938 965
if (c == '\\' && p + 1 < end && ctx->state != ESHU_QW) { 27 0 27
if (c == '\\' && p + 1 < end && ctx->state != ESHU_QW) { 27 0 27
500 27 p++; /* skip escaped char (not in qw) */
501 938 ▶ } else if (ctx->q_close != ctx->q_open) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ctx->q_close != ctx->q_open) { 607 331 938
502 /* paired delimiters — track nesting */
503 607 ▶ if (c == ctx->q_open) {
Branch: 1 branch
BranchTrueFalseTotal
if (c == ctx->q_open) { 5 602 607
504 5 ctx->q_depth++;
505 602 ▶ } else if (c == ctx->q_close) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (c == ctx->q_close) { 48 554 602
506 48 ctx->q_depth--;
507 48 ▶ if (ctx->q_depth == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->q_depth == 0) { 43 5 48
508 43 ctx->q_sections--;
509 43 ▶ if (ctx->q_sections <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->q_sections <= 0) { 37 6 43
510 37 ctx->state = ESHU_CODE;
511 37 ctx->last_was_value = 1;
512 /* skip optional flags */
513 37 p++;
514 46 ▶ while (p < end && isalpha((unsigned char)*p))
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) 46 0 46
while (p < end && isalpha((unsigned char)*p)) 9 37 46
515 9 p++;
516 37 continue;
517 } else {
518 /* next section: find new delimiter */
519 6 p++;
520 /* skip whitespace between sections */
521 6 ▶ while (p < end && (*p == ' ' || *p == '\t'))
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (*p == ' ' || *p == '\t')) 6 0 6
while (p < end && (*p == ' ' || *p == '\t')) 0 6 6
while (p < end && (*p == ' ' || *p == '\t')) 0 6 6
522 0 p++;
523 6 ▶ if (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) { 6 0 6
524 6 eshu_pl_enter_quoted(ctx, *p,
525 ctx->q_sections, ctx->state);
526 6 p++; /* skip past opening delimiter */
527 }
528 6 continue;
529 }
530 }
531 }
532 } else {
533 /* non-paired: same char opens and closes */
534 331 ▶ if (c == ctx->q_close) {
Branch: 1 branch
BranchTrueFalseTotal
if (c == ctx->q_close) { 30 301 331
535 30 ctx->q_sections--;
536 30 ▶ if (ctx->q_sections <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->q_sections <= 0) { 17 13 30
537 17 ctx->state = ESHU_CODE;
538 17 ctx->last_was_value = 1;
539 /* skip optional flags */
540 17 p++;
541 30 ▶ while (p < end && isalpha((unsigned char)*p))
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) 30 0 30
while (p < end && isalpha((unsigned char)*p)) 13 17 30
542 13 p++;
543 17 continue;
544 }
545 /* next section uses same delimiter, just continue */
546 }
547 }
548 905 break;
549  
550 /* States handled at line level, or not used by Perl scanner */
551 0 default:
552 0 return;
553 }
554 14837 p++;
555 }
556 }
557  
558 /* ══════════════════════════════════════════════════════════════════
559 * Process a single Perl line — decide indent, emit, scan
560 * ══════════════════════════════════════════════════════════════════ */
561  
562 4297 static void eshu_pl_process_line(eshu_pl_ctx_t *ctx, eshu_buf_t *out,
563 const char *line_start, const char *eol) {
564 4297 const char *content = eshu_skip_leading_ws(line_start);
565 int line_len;
566 int indent_depth;
567  
568 /* ── Pod section: buffer and indent (before blank check!) ── */
569 4297 ▶ if (ctx->state == ESHU_POD) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state == ESHU_POD) { 1757 2540 4297
570 1757 ▶ if (content < eol && eshu_pl_is_pod_end(content, eol)) {
Branch: 2 branches
BranchTrueFalseTotal
if (content < eol && eshu_pl_is_pod_end(content, eol)) { 1141 616 1757
if (content < eol && eshu_pl_is_pod_end(content, eol)) { 24 1117 1141
571 /* Run buffered POD through the POD indenter */
572 24 ▶ if (ctx->pod_buf.len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->pod_buf.len > 0) { 24 0 24
573 char *pod_result;
574 size_t pod_out_len;
575 24 eshu_buf_putc(&ctx->pod_buf, '\0');
576 24 ctx->pod_buf.len--;
577 24 pod_result = eshu_indent_pod(ctx->pod_buf.data, ctx->pod_buf.len, &ctx->cfg, &pod_out_len);
578 24 eshu_buf_write(out, pod_result, (int)pod_out_len);
579 24 free(pod_result);
580 }
581 24 ctx->pod_buf.len = 0;
582 24 ctx->pod_active = 0;
583 /* Emit =cut at column 0 */
584 24 eshu_buf_write_trimmed(out, content, (int)(eol - content));
585 24 eshu_buf_putc(out, '\n');
586 24 ctx->state = ESHU_CODE;
587 } else {
588 /* Buffer this POD line (including blanks) */
589 1733 eshu_buf_write(&ctx->pod_buf, line_start, (int)(eol - line_start));
590 1733 eshu_buf_putc(&ctx->pod_buf, '\n');
591 }
592 1757 return;
593 }
594  
595 /* ── Heredoc body: pass through verbatim (before blank check!) ── */
596 2540 ▶ if (ctx->state == ESHU_HEREDOC || ctx->state == ESHU_HEREDOC_INDENT) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->state == ESHU_HEREDOC || ctx->state == ESHU_HEREDOC_INDENT) { 2477 63 2540
if (ctx->state == ESHU_HEREDOC || ctx->state == ESHU_HEREDOC_INDENT) { 3 2474 2477
597 /* emit line exactly as-is */
598 66 eshu_buf_write_trimmed(out, line_start, (int)(eol - line_start));
599 66 eshu_buf_putc(out, '\n');
600  
601 /* check for terminator */
602 66 ▶ if (eshu_pl_is_heredoc_end(ctx, line_start, eol)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_pl_is_heredoc_end(ctx, line_start, eol)) { 17 49 66
603 17 ctx->state = ESHU_CODE;
604 17 ctx->heredoc_tag[0] = '\0';
605 17 ctx->heredoc_tag_len = 0;
606 }
607 66 return;
608 }
609  
610 /* empty line — preserve it */
611 2474 ▶ if (content >= eol) {
Branch: 1 branch
BranchTrueFalseTotal
if (content >= eol) { 214 2260 2474
612 214 eshu_buf_putc(out, '\n');
613 214 return;
614 }
615  
616 2260 line_len = (int)(eol - content);
617  
618 /* ── Past __END__ / __DATA__: pass through verbatim ── */
619 2260 ▶ if (ctx->past_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->past_end) { 23 2237 2260
620 /* Still detect POD starts within __END__ section */
621 23 ▶ if (content == line_start && eshu_pl_is_pod_start(content, eol)) {
Branch: 2 branches
BranchTrueFalseTotal
if (content == line_start && eshu_pl_is_pod_start(content, eol)) { 18 5 23
if (content == line_start && eshu_pl_is_pod_start(content, eol)) { 5 13 18
622 5 ctx->state = ESHU_POD;
623 5 ctx->pod_active = 1;
624 5 eshu_buf_write(&ctx->pod_buf, content, (int)(eol - content));
625 5 eshu_buf_putc(&ctx->pod_buf, '\n');
626 5 return;
627 }
628 /* verbatim — don't change indentation */
629 18 eshu_buf_write_trimmed(out, line_start, (int)(eol - line_start));
630 18 eshu_buf_putc(out, '\n');
631 18 return;
632 }
633  
634 /* ── __END__ / __DATA__ detection ── */
635 2237 ▶ if (content == line_start &&
Branch: 2 branches
BranchTrueFalseTotal
if (content == line_start && 1666 571 2237
if (content == line_start && 1208 458 1666
636 1208 ▶ ((line_len >= 7 && memcmp(content, "__END__", 7) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
((line_len >= 7 && memcmp(content, "__END__", 7) == 0 && 7 1201 1208
((line_len >= 7 && memcmp(content, "__END__", 7) == 0 && 0 7 7
637 1659 ▶ (line_len == 7 || content[7] == ' ' || content[7] == '\t' || content[7] == '\r')) ||
Branch: 4 branches
BranchTrueFalseTotal
(line_len == 7 || content[7] == ' ' || content[7] == '\t' || content[7] == '\r')) || 0 0 0
(line_len == 7 || content[7] == ' ' || content[7] == '\t' || content[7] == '\r')) || 0 0 0
(line_len == 7 || content[7] == ' ' || content[7] == '\t' || content[7] == '\r')) || 0 0 0
(line_len == 7 || content[7] == ' ' || content[7] == '\t' || content[7] == '\r')) || 1155 504 1659
638 1155 ▶ (line_len >= 8 && memcmp(content, "__DATA__", 8) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
(line_len >= 8 && memcmp(content, "__DATA__", 8) == 0 && 2 1153 1155
(line_len >= 8 && memcmp(content, "__DATA__", 8) == 0 && 0 2 2
639 0 ▶ (line_len == 8 || content[8] == ' ' || content[8] == '\t' || content[8] == '\r')))) {
Branch: 3 branches
BranchTrueFalseTotal
(line_len == 8 || content[8] == ' ' || content[8] == '\t' || content[8] == '\r')))) { 0 0 0
(line_len == 8 || content[8] == ' ' || content[8] == '\t' || content[8] == '\r')))) { 0 0 0
(line_len == 8 || content[8] == ' ' || content[8] == '\t' || content[8] == '\r')))) { 0 0 0
640 9 ctx->past_end = 1;
641 9 eshu_buf_write_trimmed(out, content, line_len);
642 9 eshu_buf_putc(out, '\n');
643 9 return;
644 }
645  
646 /* ── Pod start detection (= at column 0) ── */
647 2228 ▶ if (content == line_start && eshu_pl_is_pod_start(content, eol)) {
Branch: 2 branches
BranchTrueFalseTotal
if (content == line_start && eshu_pl_is_pod_start(content, eol)) { 1657 571 2228
if (content == line_start && eshu_pl_is_pod_start(content, eol)) { 21 1636 1657
648 21 ctx->state = ESHU_POD;
649 21 ctx->pod_active = 1;
650 /* Buffer the opening directive line */
651 21 eshu_buf_write(&ctx->pod_buf, content, (int)(eol - content));
652 21 eshu_buf_putc(&ctx->pod_buf, '\n');
653 21 return;
654 }
655  
656 /* ── Inside multi-line DQ/SQ string: preserve verbatim (re-indenting changes value) ── */
657 2207 ▶ if (ctx->state == ESHU_STRING_DQ || ctx->state == ESHU_STRING_SQ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->state == ESHU_STRING_DQ || ctx->state == ESHU_STRING_SQ) { 2202 5 2207
if (ctx->state == ESHU_STRING_DQ || ctx->state == ESHU_STRING_SQ) { 1 2201 2202
658 6 eshu_buf_write_trimmed(out, line_start, (int)(eol - line_start));
659 6 eshu_buf_putc(out, '\n');
660 6 eshu_pl_scan_line(ctx, content, eol);
661 6 return;
662 }
663  
664 /* ── Inside multi-line qq/q (string literals): preserve verbatim ── */
665 2201 ▶ if (ctx->state == ESHU_QQ || ctx->state == ESHU_Q) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->state == ESHU_QQ || ctx->state == ESHU_Q) { 2173 28 2201
if (ctx->state == ESHU_QQ || ctx->state == ESHU_Q) { 1 2172 2173
666 29 eshu_buf_write_trimmed(out, line_start, (int)(eol - line_start));
667 29 eshu_buf_putc(out, '\n');
668 29 eshu_pl_scan_line(ctx, content, eol);
669 29 return;
670 }
671  
672 /* ── Inside multi-line qw/regex: indent at current depth+1 ── */
673 2172 ▶ if (ctx->state == ESHU_QW || ctx->state == ESHU_REGEX) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->state == ESHU_QW || ctx->state == ESHU_REGEX) { 2152 20 2172
if (ctx->state == ESHU_QW || ctx->state == ESHU_REGEX) { 6 2146 2152
674 26 int qdepth = ctx->depth + 1;
675 /* closing delimiter line gets same depth as opening line */
676 26 ▶ if (ctx->q_close && *content == ctx->q_close)
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->q_close && *content == ctx->q_close) 20 6 26
if (ctx->q_close && *content == ctx->q_close) 4 16 20
677 4 qdepth = ctx->depth;
678 26 eshu_emit_indent(out, qdepth, &ctx->cfg);
679 26 eshu_buf_write_trimmed(out, content, line_len);
680 26 eshu_buf_putc(out, '\n');
681 26 eshu_pl_scan_line(ctx, content, eol);
682 26 return;
683 }
684  
685 /* ── Normal Perl code ── */
686 2146 indent_depth = ctx->depth;
687  
688 /* If line starts with closer, dedent this line */
689 2146 ▶ if (*content == ')' && ctx->suppressed_parens > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (*content == ')' && ctx->suppressed_parens > 0) { 14 2132 2146
if (*content == ')' && ctx->suppressed_parens > 0) { 0 14 14
690 /* suppressed paren — don't dedent */
691 2146 ▶ } else if (*content == '}' || *content == ')' || *content == ']') {
Branch: 3 branches
BranchTrueFalseTotal
} else if (*content == '}' || *content == ')' || *content == ']') { 1689 457 2146
} else if (*content == '}' || *content == ')' || *content == ']') { 1675 14 1689
} else if (*content == '}' || *content == ')' || *content == ']') { 12 1663 1675
692 483 indent_depth--;
693 483 ▶ if (indent_depth < 0) indent_depth = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (indent_depth < 0) indent_depth = 0; 0 483 483
694 }
695  
696 2146 eshu_emit_indent(out, indent_depth, &ctx->cfg);
697 2146 eshu_buf_write_trimmed(out, content, line_len);
698 2146 eshu_buf_putc(out, '\n');
699  
700 /* scan for nesting changes */
701 2146 ctx->line_paren_delta = 0;
702 2146 ctx->line_brace_delta = 0;
703 2146 ctx->line_bracket_delta = 0;
704 2146 eshu_pl_scan_line(ctx, content, eol);
705  
706 /* Suppress unmatched ( when { or [ also opened on the same line.
707 * e.g. method(sub { or method([ — the ( is just call syntax,
708 * only the { or [ should add structural indentation. */
709 2146 ▶ if (ctx->line_paren_delta > 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->line_paren_delta > 0 && 22 2124 2146
710 22 ▶ (ctx->line_brace_delta > 0 || ctx->line_bracket_delta > 0)) {
Branch: 2 branches
BranchTrueFalseTotal
(ctx->line_brace_delta > 0 || ctx->line_bracket_delta > 0)) { 15 7 22
(ctx->line_brace_delta > 0 || ctx->line_bracket_delta > 0)) { 0 15 15
711 7 ctx->depth -= ctx->line_paren_delta;
712 7 ctx->suppressed_parens += ctx->line_paren_delta;
713 }
714  
715 /* If a heredoc was detected on this line, enter heredoc state now */
716 2146 ▶ if (ctx->heredoc_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->heredoc_pending) { 17 2129 2146
717 17 ctx->heredoc_pending = 0;
718 17 ▶ ctx->state = ctx->heredoc_indented ? ESHU_HEREDOC_INDENT : ESHU_HEREDOC;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state = ctx->heredoc_indented ? ESHU_HEREDOC_INDENT : ESHU_HEREDOC; 1 16 17
719 }
720 }
721  
722 /* ══════════════════════════════════════════════════════════════════
723 * Public API — indent a Perl source string
724 * ══════════════════════════════════════════════════════════════════ */
725  
726 270 static char * eshu_indent_pl(const char *src, size_t src_len,
727 const eshu_config_t *cfg, size_t *out_len) {
728 eshu_pl_ctx_t ctx;
729 eshu_buf_t out;
730 270 const char *p = src;
731 270 const char *end = src + src_len;
732 char *result;
733  
734 270 eshu_pl_ctx_init(&ctx, cfg);
735 270 eshu_buf_init(&out, src_len + 256);
736  
737 {
738 270 int line_num = 1;
739 4567 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 4297 270 4567
740 4297 const char *eol = eshu_find_eol(p);
741  
742 4297 ▶ if (eshu_in_range(cfg, line_num)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_in_range(cfg, line_num)) { 4294 3 4297
743 4294 eshu_pl_process_line(&ctx, &out, p, eol);
744 } else {
745 3 size_t saved = out.len;
746 3 eshu_pl_process_line(&ctx, &out, p, eol);
747 3 out.len = saved;
748 3 eshu_buf_write_trimmed(&out, p, (int)(eol - p));
749 3 eshu_buf_putc(&out, '\n');
750 }
751  
752 4297 p = eol;
753 4297 ▶ if (*p == '\n') p++;
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '\n') p++; 4296 1 4297
754 4297 line_num++;
755 }
756 }
757  
758 /* Flush any remaining buffered POD (no =cut at EOF) */
759 270 ▶ if (ctx.pod_buf.len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx.pod_buf.len > 0) { 2 268 270
760 char *pod_result;
761 size_t pod_out_len;
762 2 eshu_buf_putc(&ctx.pod_buf, '\0');
763 2 ctx.pod_buf.len--;
764 2 pod_result = eshu_indent_pod(ctx.pod_buf.data, ctx.pod_buf.len, &ctx.cfg, &pod_out_len);
765 2 eshu_buf_write(&out, pod_result, (int)pod_out_len);
766 2 free(pod_result);
767 }
768 270 eshu_buf_free(&ctx.pod_buf);
769  
770 /* NUL-terminate */
771 270 eshu_buf_putc(&out, '\0');
772 270 out.len--;
773  
774 270 *out_len = out.len;
775 270 result = out.data;
776 270 return result;
777 }
778  
779  
780 #include "eshu_hl_util.h"
781  
782 /* ══════════════════════════════════════════════════════════════════
783 * Perl keyword list
784 * ══════════════════════════════════════════════════════════════════ */
785  
786 static const char * const eshu_hl_pl_kw[] = {
787 "BEGIN", "END", "AUTOLOAD", "DESTROY",
788 "abs", "accept", "alarm", "and", "atan2",
789 "bind", "binmode", "bless",
790 "caller", "chdir", "chmod", "chomp", "chop", "chown", "chr",
791 "chroot", "close", "closedir", "connect", "cos", "crypt",
792 "dbmclose", "dbmopen", "defined", "delete", "die", "do", "dump",
793 "each", "else", "elsif", "endgrent", "endhostent", "endnetent",
794 "endprotoent", "endpwent", "endservent", "eof", "eval", "exec",
795 "exists", "exit", "exp",
796 "fcntl", "fileno", "flock", "for", "foreach", "fork", "format",
797 "formline",
798 "getc", "getgrent", "getgrgid", "getgrnam", "gethostbyaddr",
799 "gethostbyname", "gethostent", "getlogin", "getnetbyaddr",
800 "getnetbyname", "getnetent", "getpeername", "getpgrp", "getppid",
801 "getpriority", "getprotobyname", "getprotobynumber", "getprotoent",
802 "getpwent", "getpwnam", "getpwuid", "getservbyname",
803 "getservbyport", "getservent", "getsockname", "getsockopt",
804 "given", "glob", "gmtime", "goto", "grep",
805 "hex",
806 "if", "import", "index", "int", "ioctl",
807 "join",
808 "keys", "kill",
809 "last", "lc", "lcfirst", "length", "link", "listen", "local",
810 "localtime", "log", "lstat",
811 "m", "map", "mkdir", "msgctl", "msgget", "msgrcv", "msgsnd",
812 "my",
813 "next", "no",
814 "oct", "open", "opendir", "or", "ord", "our",
815 "pack", "package", "pipe", "pop", "pos", "print", "printf",
816 "prototype", "push",
817 "q", "qq", "qr", "quotemeta", "qw", "qx",
818 "rand", "read", "readdir", "readline", "readlink", "readpipe",
819 "recv", "redo", "ref", "rename", "require", "reset", "return",
820 "reverse", "rewinddir", "rindex", "rmdir",
821 "s", "say", "scalar", "seek", "seekdir", "select", "semctl",
822 "semget", "semop", "send", "setgrent", "sethostent", "setnetent",
823 "setpgrp", "setpriority", "setprotoent", "setpwent", "setservent",
824 "setsockopt", "shift", "shmctl", "shmget", "shmread", "shmwrite",
825 "shutdown", "sin", "sleep", "socket", "socketpair", "sort", "splice",
826 "split", "sprintf", "sqrt", "srand", "stat", "state", "study", "sub",
827 "substr", "symlink", "syscall", "sysopen", "sysread", "sysseek",
828 "system", "syswrite",
829 "tell", "telldir", "tie", "tied", "time", "times", "tr",
830 "truncate",
831 "uc", "ucfirst", "umask", "undef", "unless", "unlink", "unpack",
832 "unshift", "untie", "until", "use", "utime",
833 "values", "vec",
834 "wait", "waitpid", "wantarray", "warn", "when", "while", "write",
835 "y",
836 NULL
837 };
838  
839 /* ══════════════════════════════════════════════════════════════════
840 * Perl highlighter
841 * ══════════════════════════════════════════════════════════════════ */
842  
843 /* Paired delimiter map: ( → ), [ → ], { → }, < → > */
844 10 static char eshu_hl_paired(char open) {
845 10 switch (open) {
846 2 case '(': return ')';
847 0 case '[': return ']';
848 3 case '{': return '}';
849 0 case '<': return '>';
850 5 default: return open;
851 }
852 }
853  
854 /* Scan past a quoted construct body using delimiter d_open/d_close.
855 * p points to the first char after the opening delimiter.
856 * Returns pointer past the closing delimiter. */
857 13 static const char *eshu_hl_pl_qbody(const char *p, const char *end,
858 char d_open, char d_close) {
859 13 int depth = 1;
860 13 int is_paired = (d_open != d_close);
861 95 ▶ while (p < end && depth > 0) {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && depth > 0) { 92 3 95
while (p < end && depth > 0) { 82 10 92
862 82 ▶ if (*p == '\\') { p++; if (p < end) p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\') { p++; if (p < end) p++; continue; } 0 82 82
if (*p == '\\') { p++; if (p < end) p++; continue; } 0 0 0
863 82 ▶ if (is_paired && *p == d_open) { depth++; p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (is_paired && *p == d_open) { depth++; p++; continue; } 49 33 82
if (is_paired && *p == d_open) { depth++; p++; continue; } 0 49 49
864 82 ▶ if (*p == d_close) { depth--; p++; continue; }
Branch: 1 branch
BranchTrueFalseTotal
if (*p == d_close) { depth--; p++; continue; } 13 69 82
865 69 p++;
866 }
867 13 return p;
868 }
869  
870 /* Detect whether '/' at p is a regex delimiter (vs division).
871 * last_was_value: 1 if previous token was an rvalue (number, var, ')' etc.) */
872 0 static int eshu_hl_pl_is_regex(const char *src_start, const char *p,
873 int last_was_value) {
874 (void)src_start;
875 0 ▶ if (last_was_value) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (last_was_value) return 0; 0 0 0
876 0 return 1;
877 }
878  
879 /* Single special Perl variable chars after sigil (no alpha start) */
880 7 static int eshu_hl_pl_special_var(char c) {
881 7 ▶ switch (c) {
Branch: 1 branch
BranchTrueFalseTotal
switch (c) { 7 0 7
882 7 case '_': case '!': case '@': case '&': case '\'': case '"':
883 case ';': case ',': case '\\': case '/': case '.': case '?':
884 case '|': case '+': case '-': case '^': case '~': case '0':
885 case '$': case '*': case '(': case ')': case '[': case '{':
886 case '}': case '<': case '>': case '=': case '%': case '#':
887 7 return 1;
888 0 default:
889 0 return isdigit((unsigned char)c);
890 }
891 }
892  
893 #define ESHU_HL_HEREDOC_MAX 64
894  
895 75 static char *eshu_highlight_pl(const char *src, size_t src_len, size_t *out_len) {
896 eshu_buf_t out;
897 75 const char *p = src;
898 75 const char *end = src + src_len;
899 75 const char *plain = p;
900 75 int last_val = 0; /* last non-ws was rvalue-like */
901 75 int past_end_data = 0; /* past __END__ / __DATA__ */
902 75 int in_pod = 0;
903 char hd_tag[ESHU_HL_HEREDOC_MAX];
904 75 int hd_len = 0;
905 75 int hd_pending = 0; /* heredoc body starts on next line */
906 75 int at_bol = 1;
907  
908 75 eshu_buf_init(&out, src_len * 2 + 64);
909  
910 #define PL_SPAN(cls, ts, te) do { \
911 eshu_hl_flush(&out, plain, (ts)); \
912 eshu_hl_span(&out, (cls), (ts), (te)); \
913 p = (te); plain = p; \
914 } while(0)
915  
916 669 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 595 74 669
917 595 char c = *p;
918  
919 /* ── past __END__ / __DATA__: dump rest as comment ── */
920 595 ▶ if (past_end_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (past_end_data) { 1 594 595
921 1 PL_SPAN("esh-c", p, end);
922 1 break;
923 }
924  
925 /* ── POD block ── */
926 594 ▶ if (in_pod) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_pod) { 8 586 594
927 /* POD ends at '=cut' at start of line */
928 8 ▶ if (at_bol && p + 4 <= end && memcmp(p, "=cut", 4) == 0 &&
Branch: 3 branches
BranchTrueFalseTotal
if (at_bol && p + 4 <= end && memcmp(p, "=cut", 4) == 0 && 8 0 8
if (at_bol && p + 4 <= end && memcmp(p, "=cut", 4) == 0 && 8 0 8
if (at_bol && p + 4 <= end && memcmp(p, "=cut", 4) == 0 && 2 6 8
929 2 ▶ (p + 4 >= end || *(p + 4) == '\n' || *(p + 4) == '\r' ||
Branch: 3 branches
BranchTrueFalseTotal
(p + 4 >= end || *(p + 4) == '\n' || *(p + 4) == '\r' || 2 0 2
(p + 4 >= end || *(p + 4) == '\n' || *(p + 4) == '\r' || 0 2 2
(p + 4 >= end || *(p + 4) == '\n' || *(p + 4) == '\r' || 0 0 0
930 0 ▶ *(p + 4) == ' ')) {
Branch: 1 branch
BranchTrueFalseTotal
*(p + 4) == ' ')) { 0 0 0
931 2 const char *ts = p;
932 10 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 10 0 10
while (p < end && *p != '\n') p++; 8 2 10
933 2 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 2 0 2
934 2 PL_SPAN("esh-d", ts, p);
935 2 in_pod = 0;
936 2 at_bol = 1;
937 } else {
938 6 const char *ts = p;
939 26 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 26 0 26
while (p < end && *p != '\n') p++; 20 6 26
940 6 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 6 0 6
941 6 PL_SPAN("esh-d", ts, p);
942 6 at_bol = 1;
943 }
944 8 continue;
945 }
946  
947 /* ── heredoc body ── */
948 586 ▶ if (hd_pending && at_bol) {
Branch: 2 branches
BranchTrueFalseTotal
if (hd_pending && at_bol) { 4 582 586
if (hd_pending && at_bol) { 2 2 4
949 /* check if this line is the terminator */
950 2 ▶ if (hd_len > 0 && (size_t)(end - p) >= (size_t)hd_len &&
Branch: 2 branches
BranchTrueFalseTotal
if (hd_len > 0 && (size_t)(end - p) >= (size_t)hd_len && 2 0 2
if (hd_len > 0 && (size_t)(end - p) >= (size_t)hd_len && 2 0 2
951 2 ▶ memcmp(p, hd_tag, (size_t)hd_len) == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
memcmp(p, hd_tag, (size_t)hd_len) == 0 && 1 1 2
952 1 ▶ (p + hd_len >= end || *(p + hd_len) == '\n' ||
Branch: 2 branches
BranchTrueFalseTotal
(p + hd_len >= end || *(p + hd_len) == '\n' || 1 0 1
(p + hd_len >= end || *(p + hd_len) == '\n' || 0 1 1
953 0 ▶ *(p + hd_len) == '\r')) {
Branch: 1 branch
BranchTrueFalseTotal
*(p + hd_len) == '\r')) { 0 0 0
954 1 const char *ts = p;
955 4 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 4 0 4
while (p < end && *p != '\n') p++; 3 1 4
956 1 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 1 0 1
957 1 PL_SPAN("esh-h", ts, p);
958 1 hd_pending = 0;
959 1 hd_len = 0;
960 1 at_bol = 1;
961 } else {
962 1 const char *ts = p;
963 6 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 6 0 6
while (p < end && *p != '\n') p++; 5 1 6
964 1 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 1 0 1
965 1 PL_SPAN("esh-h", ts, p);
966 1 at_bol = 1;
967 }
968 2 continue;
969 }
970  
971 /* ── POD start: '=word' at beginning of line ── */
972 584 ▶ if (at_bol && c == '=') {
Branch: 2 branches
BranchTrueFalseTotal
if (at_bol && c == '=') { 140 444 584
if (at_bol && c == '=') { 2 138 140
973 2 const char *np = p + 1;
974 2 ▶ if (np < end && isalpha((unsigned char)*np)) {
Branch: 2 branches
BranchTrueFalseTotal
if (np < end && isalpha((unsigned char)*np)) { 2 0 2
if (np < end && isalpha((unsigned char)*np)) { 2 0 2
975 /* check it's not '=~' operator */
976 2 const char *ts = p;
977 17 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 17 0 17
while (p < end && *p != '\n') p++; 15 2 17
978 2 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 2 0 2
979 2 PL_SPAN("esh-d", ts, p);
980 2 in_pod = 1;
981 2 at_bol = 1;
982 2 continue;
983 }
984 }
985  
986 /* ── comment: '#' not inside anything ── */
987 582 ▶ if (c == '#') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '#') { 5 577 582
988 5 const char *ts = p;
989 85 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 85 0 85
while (p < end && *p != '\n') p++; 80 5 85
990 5 PL_SPAN("esh-c", ts, p);
991 5 at_bol = 0;
992 5 last_val = 0;
993 5 continue;
994 }
995  
996 /* ── heredoc start: << or <<~ ── */
997 577 ▶ if (c == '<' && p + 1 < end && *(p + 1) == '<') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '<' && p + 1 < end && *(p + 1) == '<') { 4 573 577
if (c == '<' && p + 1 < end && *(p + 1) == '<') { 4 0 4
if (c == '<' && p + 1 < end && *(p + 1) == '<') { 1 3 4
998 1 const char *ts = p;
999 1 p += 2;
1000 1 int indented = 0;
1001 1 ▶ if (p < end && *p == '~') { indented = 1; p++; }
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '~') { indented = 1; p++; } 1 0 1
if (p < end && *p == '~') { indented = 1; p++; } 0 1 1
1002 /* optional quote around tag */
1003 1 char qchar = 0;
1004 1 ▶ if (p < end && (*p == '\'' || *p == '"' || *p == '`')) {
Branch: 4 branches
BranchTrueFalseTotal
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 1 0 1
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 1 0 1
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 1 0 1
if (p < end && (*p == '\'' || *p == '"' || *p == '`')) { 0 1 1
1005 0 qchar = *p++;
1006 }
1007 /* collect tag */
1008 1 const char *tag_start = p;
1009 8 ▶ while (p < end && *p != '\n' && *p != '\r' &&
Branch: 5 branches
BranchTrueFalseTotal
while (p < end && *p != '\n' && *p != '\r' && 4 0 4
while (p < end && *p != '\n' && *p != '\r' && 4 0 4
while (p < end && *p != '\n' && *p != '\r' && 4 0 4
while (p < end && *p != '\n' && *p != '\r' && 0 4 4
while (p < end && *p != '\n' && *p != '\r' && 3 1 4
1010 4 ▶ (qchar ? *p != qchar : (isalnum((unsigned char)*p) || *p == '_')))
Branch: 3 branches
BranchTrueFalseTotal
(qchar ? *p != qchar : (isalnum((unsigned char)*p) || *p == '_'))) 0 0 0
(qchar ? *p != qchar : (isalnum((unsigned char)*p) || *p == '_'))) 1 3 4
(qchar ? *p != qchar : (isalnum((unsigned char)*p) || *p == '_'))) 0 1 1
1011 3 p++;
1012 1 int tl = (int)(p - tag_start);
1013 1 ▶ if (tl > 0 && tl < ESHU_HL_HEREDOC_MAX) {
Branch: 2 branches
BranchTrueFalseTotal
if (tl > 0 && tl < ESHU_HL_HEREDOC_MAX) { 1 0 1
if (tl > 0 && tl < ESHU_HL_HEREDOC_MAX) { 1 0 1
1014 1 memcpy(hd_tag, tag_start, (size_t)tl);
1015 1 hd_tag[tl] = '\0';
1016 1 hd_len = tl;
1017 1 hd_pending = 1;
1018 }
1019 1 ▶ if (qchar && p < end && *p == qchar) p++;
Branch: 3 branches
BranchTrueFalseTotal
if (qchar && p < end && *p == qchar) p++; 0 1 1
if (qchar && p < end && *p == qchar) p++; 0 0 0
if (qchar && p < end && *p == qchar) p++; 0 0 0
1020 /* the rest of the current line (after <<TAG) continues normally */
1021 /* emit the << token as plain; body will be highlighted next line */
1022 1 PL_SPAN("esh-h", ts, p);
1023 (void)indented;
1024 1 last_val = 1;
1025 1 continue;
1026 }
1027  
1028 /* ── __END__ / __DATA__ ── */
1029 576 ▶ if (at_bol && (
Branch: 1 branch
BranchTrueFalseTotal
if (at_bol && ( 134 442 576
1030 134 ▶ (p + 7 <= end && memcmp(p, "__END__", 7) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
(p + 7 <= end && memcmp(p, "__END__", 7) == 0 && 111 23 134
(p + 7 <= end && memcmp(p, "__END__", 7) == 0 && 1 110 111
1031 1 ▶ (p + 7 >= end || *(p + 7) == '\n' || *(p + 7) == '\r')) ||
Branch: 3 branches
BranchTrueFalseTotal
(p + 7 >= end || *(p + 7) == '\n' || *(p + 7) == '\r')) || 1 0 1
(p + 7 >= end || *(p + 7) == '\n' || *(p + 7) == '\r')) || 0 1 1
(p + 7 >= end || *(p + 7) == '\n' || *(p + 7) == '\r')) || 0 0 0
1032 133 ▶ (p + 8 <= end && memcmp(p, "__DATA__", 8) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
(p + 8 <= end && memcmp(p, "__DATA__", 8) == 0 && 106 27 133
(p + 8 <= end && memcmp(p, "__DATA__", 8) == 0 && 0 106 106
1033 0 ▶ (p + 8 >= end || *(p + 8) == '\n' || *(p + 8) == '\r')))) {
Branch: 3 branches
BranchTrueFalseTotal
(p + 8 >= end || *(p + 8) == '\n' || *(p + 8) == '\r')))) { 0 0 0
(p + 8 >= end || *(p + 8) == '\n' || *(p + 8) == '\r')))) { 0 0 0
(p + 8 >= end || *(p + 8) == '\n' || *(p + 8) == '\r')))) { 0 0 0
1034 /* consume the token line */
1035 1 const char *ts = p;
1036 8 ▶ while (p < end && *p != '\n') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '\n') p++; 8 0 8
while (p < end && *p != '\n') p++; 7 1 8
1037 1 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 1 0 1
1038 1 PL_SPAN("esh-k", ts, p);
1039 1 past_end_data = 1;
1040 1 at_bol = 1;
1041 1 continue;
1042 }
1043  
1044 /* ── string: "..." '...' `...` ── */
1045 575 ▶ if (c == '"' || c == '\'' || c == '`') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '"' || c == '\'' || c == '`') { 569 6 575
if (c == '"' || c == '\'' || c == '`') { 565 4 569
if (c == '"' || c == '\'' || c == '`') { 1 564 565
1046 11 const char *ts = p++;
1047 80 ▶ while (p < end && *p != c) {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != c) { 80 0 80
while (p < end && *p != c) { 69 11 80
1048 69 ▶ if (*p == '\\') { p++; if (p < end) p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\') { p++; if (p < end) p++; continue; } 2 67 69
if (*p == '\\') { p++; if (p < end) p++; continue; } 2 0 2
1049 67 p++;
1050 }
1051 11 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 11 0 11
1052 11 PL_SPAN("esh-s", ts, p);
1053 11 last_val = 1;
1054 11 at_bol = 0;
1055 11 continue;
1056 }
1057  
1058 /* ── number: digits ── */
1059 564 ▶ if (isdigit((unsigned char)c) ||
Branch: 2 branches
BranchTrueFalseTotal
if (isdigit((unsigned char)c) || 542 22 564
if (isdigit((unsigned char)c) || 0 542 542
1060 0 ▶ (c == '.' && p + 1 < end && isdigit((unsigned char)*(p + 1)))) {
Branch: 2 branches
BranchTrueFalseTotal
(c == '.' && p + 1 < end && isdigit((unsigned char)*(p + 1)))) { 0 0 0
(c == '.' && p + 1 < end && isdigit((unsigned char)*(p + 1)))) { 0 0 0
1061 22 const char *ts = p;
1062 26 ▶ if (c == '0' && p + 1 < end) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '0' && p + 1 < end) { 4 18 22
if (c == '0' && p + 1 < end) { 4 0 4
1063 4 char nc = *(p + 1);
1064 4 ▶ if (nc == 'x' || nc == 'X') {
Branch: 2 branches
BranchTrueFalseTotal
if (nc == 'x' || nc == 'X') { 3 1 4
if (nc == 'x' || nc == 'X') { 0 3 3
1065 3 ▶ p += 2; while (p < end && isxdigit((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
p += 2; while (p < end && isxdigit((unsigned char)*p)) p++; 2 1 3
p += 2; while (p < end && isxdigit((unsigned char)*p)) p++; 2 0 2
1066 3 ▶ } else if (nc == 'b' || nc == 'B') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (nc == 'b' || nc == 'B') { 2 1 3
} else if (nc == 'b' || nc == 'B') { 0 2 2
1067 5 ▶ p += 2; while (p < end && (*p == '0' || *p == '1')) p++;
Branch: 3 branches
BranchTrueFalseTotal
p += 2; while (p < end && (*p == '0' || *p == '1')) p++; 4 1 5
p += 2; while (p < end && (*p == '0' || *p == '1')) p++; 1 3 4
p += 2; while (p < end && (*p == '0' || *p == '1')) p++; 3 0 3
1068 } else {
1069 4 ▶ while (p < end && isdigit((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isdigit((unsigned char)*p)) p++; 4 0 4
while (p < end && isdigit((unsigned char)*p)) p++; 2 2 4
1070 }
1071 } else {
1072 56 ▶ while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++;
Branch: 3 branches
BranchTrueFalseTotal
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 53 3 56
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 34 19 53
while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; 4 15 19
1073 18 ▶ if (p < end && *p == '.') {
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && *p == '.') { 15 3 18
if (p < end && *p == '.') { 1 14 15
1074 1 p++;
1075 3 ▶ while (p < end && isdigit((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isdigit((unsigned char)*p)) p++; 2 1 3
while (p < end && isdigit((unsigned char)*p)) p++; 2 0 2
1076 }
1077 18 ▶ if (p < end && (*p == 'e' || *p == 'E')) {
Branch: 3 branches
BranchTrueFalseTotal
if (p < end && (*p == 'e' || *p == 'E')) { 14 4 18
if (p < end && (*p == 'e' || *p == 'E')) { 14 0 14
if (p < end && (*p == 'e' || *p == 'E')) { 0 14 14
1078 0 ▶ p++; if (p < end && (*p == '+' || *p == '-')) p++;
Branch: 3 branches
BranchTrueFalseTotal
p++; if (p < end && (*p == '+' || *p == '-')) p++; 0 0 0
p++; if (p < end && (*p == '+' || *p == '-')) p++; 0 0 0
p++; if (p < end && (*p == '+' || *p == '-')) p++; 0 0 0
1079 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
1080 }
1081 }
1082 22 PL_SPAN("esh-n", ts, p);
1083 22 last_val = 1;
1084 22 at_bol = 0;
1085 22 continue;
1086 }
1087  
1088 /* ── variable sigil: $, @, % ── */
1089 542 ▶ if (c == '$' || c == '@' || c == '%') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '$' || c == '@' || c == '%') { 492 50 542
if (c == '$' || c == '@' || c == '%') { 479 13 492
if (c == '$' || c == '@' || c == '%') { 1 478 479
1090 64 const char *ts = p++;
1091 /* $# prefix (last-index-of) */
1092 64 ▶ if (c == '$' && p < end && *p == '#') {
Branch: 3 branches
BranchTrueFalseTotal
if (c == '$' && p < end && *p == '#') { 50 14 64
if (c == '$' && p < end && *p == '#') { 50 0 50
if (c == '$' && p < end && *p == '#') { 1 49 50
1093 1 p++;
1094 1 ▶ if (p < end && eshu_hl_isalpha_(*p)) {
Branch: 2 branches
BranchTrueFalseTotal
if (p < end && eshu_hl_isalpha_(*p)) { 1 0 1
if (p < end && eshu_hl_isalpha_(*p)) { 1 0 1
1095 6 ▶ while (p < end && eshu_hl_isalnum_(*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && eshu_hl_isalnum_(*p)) p++; 5 1 6
while (p < end && eshu_hl_isalnum_(*p)) p++; 5 0 5
1096 }
1097 63 ▶ } else if (p < end && eshu_hl_isalpha_(*p)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && eshu_hl_isalpha_(*p)) { 63 0 63
} else if (p < end && eshu_hl_isalpha_(*p)) { 56 7 63
1098 143 ▶ while (p < end && eshu_hl_isalnum_(*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && eshu_hl_isalnum_(*p)) p++; 138 5 143
while (p < end && eshu_hl_isalnum_(*p)) p++; 87 51 138
1099 7 ▶ } else if (p < end && eshu_hl_pl_special_var(*p)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && eshu_hl_pl_special_var(*p)) { 7 0 7
} else if (p < end && eshu_hl_pl_special_var(*p)) { 7 0 7
1100 7 p++;
1101 0 ▶ } else if (p < end && *p == '{') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (p < end && *p == '{') { 0 0 0
} else if (p < end && *p == '{') { 0 0 0
1102 0 p++;
1103 0 ▶ while (p < end && *p != '}') p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '}') p++; 0 0 0
while (p < end && *p != '}') p++; 0 0 0
1104 0 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 0 0 0
1105 }
1106 64 PL_SPAN("esh-v", ts, p);
1107 64 last_val = 1;
1108 64 at_bol = 0;
1109 64 continue;
1110 }
1111  
1112 /* ── regex / quoted-like starting with m, s, qw, qq, qr, q, tr, y ── */
1113 478 ▶ if ((c == 'm' || c == 's' || c == 'q' || c == 'y') &&
Branch: 4 branches
BranchTrueFalseTotal
if ((c == 'm' || c == 's' || c == 'q' || c == 'y') && 454 24 478
if ((c == 'm' || c == 's' || c == 'q' || c == 'y') && 445 9 454
if ((c == 'm' || c == 's' || c == 'q' || c == 'y') && 441 4 445
if ((c == 'm' || c == 's' || c == 'q' || c == 'y') && 1 440 441
1114 38 ▶ (p + 1 >= end || !eshu_hl_isalnum_(*(p + 1)))) {
Branch: 2 branches
BranchTrueFalseTotal
(p + 1 >= end || !eshu_hl_isalnum_(*(p + 1)))) { 38 0 38
(p + 1 >= end || !eshu_hl_isalnum_(*(p + 1)))) { 5 33 38
1115 /* single-char operator: m/./, s/../., q(.) etc. */
1116 5 const char *ts = p++;
1117 5 ▶ char d_open = (p < end) ? *p++ : '/';
Branch: 1 branch
BranchTrueFalseTotal
char d_open = (p < end) ? *p++ : '/'; 5 0 5
1118 5 char d_close = eshu_hl_paired(d_open);
1119 5 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1120 5 ▶ if (c == 's' || c == 'y') {
Branch: 2 branches
BranchTrueFalseTotal
if (c == 's' || c == 'y') { 3 2 5
if (c == 's' || c == 'y') { 1 2 3
1121 /* s and y always have a second section */
1122 3 ▶ if (d_open != d_close) {
Branch: 1 branch
BranchTrueFalseTotal
if (d_open != d_close) { 1 2 3
1123 /* paired delimiters: consume new opening delimiter */
1124 1 ▶ if (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) { 1 0 1
1125 1 d_open = *p++;
1126 1 d_close = eshu_hl_paired(d_open);
1127 1 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1128 }
1129 } else {
1130 /* same delimiter: second section starts immediately */
1131 2 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1132 }
1133 }
1134 /* skip flags: gimsxpeodual etc. */
1135 7 ▶ while (p < end && isalpha((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) p++; 3 4 7
while (p < end && isalpha((unsigned char)*p)) p++; 2 1 3
1136 5 PL_SPAN("esh-r", ts, p);
1137 5 last_val = 1;
1138 5 at_bol = 0;
1139 5 continue;
1140 }
1141  
1142 /* ── qw / qq / qr (multi-char) ── */
1143 473 ▶ if (c == 'q' && p + 1 < end &&
Branch: 2 branches
BranchTrueFalseTotal
if (c == 'q' && p + 1 < end && 3 470 473
if (c == 'q' && p + 1 < end && 3 0 3
1144 3 ▶ (*(p + 1) == 'w' || *(p + 1) == 'q' || *(p + 1) == 'r' ||
Branch: 3 branches
BranchTrueFalseTotal
(*(p + 1) == 'w' || *(p + 1) == 'q' || *(p + 1) == 'r' || 2 1 3
(*(p + 1) == 'w' || *(p + 1) == 'q' || *(p + 1) == 'r' || 1 1 2
(*(p + 1) == 'w' || *(p + 1) == 'q' || *(p + 1) == 'r' || 0 1 1
1145 0 ▶ *(p + 1) == 'x') &&
Branch: 1 branch
BranchTrueFalseTotal
*(p + 1) == 'x') && 0 0 0
1146 3 ▶ (p + 2 >= end || !eshu_hl_isalnum_(*(p + 2)))) {
Branch: 2 branches
BranchTrueFalseTotal
(p + 2 >= end || !eshu_hl_isalnum_(*(p + 2)))) { 3 0 3
(p + 2 >= end || !eshu_hl_isalnum_(*(p + 2)))) { 3 0 3
1147 3 const char *ts = p;
1148 3 p += 2;
1149 3 ▶ char d_open = (p < end) ? *p++ : '(';
Branch: 1 branch
BranchTrueFalseTotal
char d_open = (p < end) ? *p++ : '('; 3 0 3
1150 3 char d_close = eshu_hl_paired(d_open);
1151 3 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1152 3 PL_SPAN("esh-r", ts, p);
1153 3 last_val = 1;
1154 3 at_bol = 0;
1155 3 continue;
1156 }
1157  
1158 /* ── tr/y (two-char) ── */
1159 470 ▶ if (((c == 't' && p + 1 < end && *(p + 1) == 'r') ||
Branch: 4 branches
BranchTrueFalseTotal
if (((c == 't' && p + 1 < end && *(p + 1) == 'r') || 1 469 470
if (((c == 't' && p + 1 < end && *(p + 1) == 'r') || 1 0 1
if (((c == 't' && p + 1 < end && *(p + 1) == 'r') || 0 1 1
if (((c == 't' && p + 1 < end && *(p + 1) == 'r') || 0 469 469
1160 1 (c == 'y')) &&
1161 2 ▶ (p + (c == 'y' ? 1 : 2) >= end ||
Branch: 1 branch
BranchTrueFalseTotal
(p + (c == 'y' ? 1 : 2) >= end || 0 1 1
1162 1 ▶ !eshu_hl_isalnum_(*(p + (c == 'y' ? 1 : 2))))) {
Branch: 1 branch
BranchTrueFalseTotal
!eshu_hl_isalnum_(*(p + (c == 'y' ? 1 : 2))))) { 0 1 1
1163 1 const char *ts = p;
1164 1 ▶ p += (c == 'y') ? 1 : 2;
Branch: 1 branch
BranchTrueFalseTotal
p += (c == 'y') ? 1 : 2; 0 1 1
1165 1 ▶ char d_open = (p < end) ? *p++ : '/';
Branch: 1 branch
BranchTrueFalseTotal
char d_open = (p < end) ? *p++ : '/'; 1 0 1
1166 1 char d_close = eshu_hl_paired(d_open);
1167 1 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1168 1 ▶ if (d_open == d_close) {
Branch: 1 branch
BranchTrueFalseTotal
if (d_open == d_close) { 1 0 1
1169 /* same delimiter: second section starts immediately */
1170 1 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1171 } else {
1172 /* paired delimiters: consume opening delimiter of second section */
1173 0 ▶ if (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) { 0 0 0
1174 0 d_open = *p++;
1175 0 d_close = eshu_hl_paired(d_open);
1176 0 p = eshu_hl_pl_qbody(p, end, d_open, d_close);
1177 }
1178 }
1179 1 ▶ while (p < end && isalpha((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) p++; 0 1 1
while (p < end && isalpha((unsigned char)*p)) p++; 0 0 0
1180 1 PL_SPAN("esh-r", ts, p);
1181 1 last_val = 1;
1182 1 at_bol = 0;
1183 1 continue;
1184 }
1185  
1186 /* ── bare regex: / not preceded by rvalue ── */
1187 469 ▶ if (c == '/' && !last_val) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '/' && !last_val) { 4 465 469
if (c == '/' && !last_val) { 3 1 4
1188 3 const char *ts = p++;
1189 10 ▶ while (p < end && *p != '/') {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && *p != '/') { 10 0 10
while (p < end && *p != '/') { 7 3 10
1190 7 ▶ if (*p == '\\') { p++; if (p < end) p++; continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\') { p++; if (p < end) p++; continue; } 0 7 7
if (*p == '\\') { p++; if (p < end) p++; continue; } 0 0 0
1191 7 ▶ if (*p == '\n') { p = ts + 1; goto pl_not_regex; }
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '\n') { p = ts + 1; goto pl_not_regex; } 0 7 7
1192 7 p++;
1193 }
1194 3 ▶ if (p < end) p++;
Branch: 1 branch
BranchTrueFalseTotal
if (p < end) p++; 3 0 3
1195 4 ▶ while (p < end && isalpha((unsigned char)*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isalpha((unsigned char)*p)) p++; 4 0 4
while (p < end && isalpha((unsigned char)*p)) p++; 1 3 4
1196 3 PL_SPAN("esh-r", ts, p);
1197 3 last_val = 1;
1198 3 at_bol = 0;
1199 3 continue;
1200 0 pl_not_regex:;
1201 }
1202  
1203 /* ── identifier or keyword ── */
1204 466 ▶ if (eshu_hl_isalpha_(c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_hl_isalpha_(c)) { 85 381 466
1205 85 const char *ts = p;
1206 418 ▶ while (p < end && eshu_hl_isalnum_(*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && eshu_hl_isalnum_(*p)) p++; 416 2 418
while (p < end && eshu_hl_isalnum_(*p)) p++; 333 83 416
1207 85 eshu_hl_flush(&out, plain, ts);
1208 85 plain = p;
1209 85 size_t ilen = (size_t)(p - ts);
1210 85 ▶ if (eshu_hl_kw(ts, ilen, eshu_hl_pl_kw)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eshu_hl_kw(ts, ilen, eshu_hl_pl_kw)) { 61 24 85
1211 61 eshu_hl_span(&out, "esh-k", ts, p);
1212 61 last_val = 0;
1213 } else {
1214 24 eshu_hl_write_html(&out, ts, ilen);
1215 24 last_val = 1;
1216 }
1217 85 at_bol = 0;
1218 85 continue;
1219 }
1220  
1221 /* ── track rvalue context ── */
1222 381 ▶ if (c == ')' || c == ']') last_val = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (c == ')' || c == ']') last_val = 1; 371 10 381
if (c == ')' || c == ']') last_val = 1; 0 371 371
1223 371 ▶ else if (c == '(' || c == ',' || c == ';' || c == '=' ||
Branch: 5 branches
BranchTrueFalseTotal
else if (c == '(' || c == ',' || c == ';' || c == '=' || 361 10 371
else if (c == '(' || c == ',' || c == ';' || c == '=' || 358 3 361
else if (c == '(' || c == ',' || c == ';' || c == '=' || 315 43 358
else if (c == '(' || c == ',' || c == ';' || c == '=' || 291 24 315
else if (c == '(' || c == ',' || c == ';' || c == '=' || 289 2 291
1224 289 ▶ c == '+' || c == '-' || c == '*' || c == '!' ||
Branch: 4 branches
BranchTrueFalseTotal
c == '+' || c == '-' || c == '*' || c == '!' || 288 1 289
c == '+' || c == '-' || c == '*' || c == '!' || 287 1 288
c == '+' || c == '-' || c == '*' || c == '!' || 287 0 287
c == '+' || c == '-' || c == '*' || c == '!' || 286 1 287
1225 286 ▶ c == '~' || c == ':' || c == '?' || c == '{' ||
Branch: 4 branches
BranchTrueFalseTotal
c == '~' || c == ':' || c == '?' || c == '{' || 284 2 286
c == '~' || c == ':' || c == '?' || c == '{' || 284 0 284
c == '~' || c == ':' || c == '?' || c == '{' || 268 16 284
c == '~' || c == ':' || c == '?' || c == '{' || 268 0 268
1226 268 ▶ c == '[' || c == '&' || c == '|' || c == '^')
Branch: 3 branches
BranchTrueFalseTotal
c == '[' || c == '&' || c == '|' || c == '^') 268 0 268
c == '[' || c == '&' || c == '|' || c == '^') 266 2 268
c == '[' || c == '&' || c == '|' || c == '^') 0 266 266
1227 105 last_val = 0;
1228  
1229 381 ▶ if (c == '\n') { at_bol = 1; last_val = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\n') { at_bol = 1; last_val = 0; } 25 356 381
1230 356 ▶ else if (c != ' ' && c != '\t') at_bol = 0;
Branch: 2 branches
BranchTrueFalseTotal
else if (c != ' ' && c != '\t') at_bol = 0; 138 218 356
else if (c != ' ' && c != '\t') at_bol = 0; 138 0 138
1231 381 p++;
1232 }
1233  
1234 75 eshu_hl_flush(&out, plain, end);
1235 75 eshu_buf_putc(&out, '\0');
1236 75 *out_len = out.len - 1;
1237 75 return out.data;
1238  
1239 #undef PL_SPAN
1240 }
1241  
1242 #endif /* ESHU_PL_H */
« include/eshu_xs.h ↑ Summary include/eshu_diff.h »