Skip to content

Commit ea9c90b

Browse files
committed
lx: Rewrite logic to make the four cases explicit, fix dead code.
This was previously ending up with a useless call to the current zone after returning the token ("case S1: return TOK_UNKNOWN; lx->z(lx);"), which led to a warning in CI [-Werror=implicit-fallthrough=].
1 parent ae53e94 commit ea9c90b

File tree

1 file changed

+21
-13
lines changed
  • src/lx/print

1 file changed

+21
-13
lines changed

src/lx/print/c.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,28 @@ accept_c(FILE *f, const struct fsm_options *opt,
190190
}
191191

192192
fprintf(f, "return ");
193-
if (m->to != NULL) {
194-
fprintf(f, "lx->z = z%u, ", zindexof(ast, m->to));
195-
} else if (m->to == NULL && m->token == NULL) {
196-
/* If accept-ing here doesn't actually map to a token or
197-
* a different zone, then it's stuck in the middle of a
198-
* pattern pair like `'//' .. /\n/ -> $nl;` with an EOF,
199-
* so tokenization should still fail. */
200-
fprintf(f, "%sUNKNOWN; ", prefix.tok);
201-
}
202-
if (m->token != NULL) {
203-
fprintf(f, "%s", prefix.tok);
204-
esctok(f, m->token->s);
193+
if (m->to == NULL) {
194+
if (m->token == NULL) {
195+
/* If accept-ing here doesn't actually map to a token or
196+
* a different zone, then it's stuck in the middle of a
197+
* pattern pair like `'//' .. /\n/ -> $nl;` with an EOF,
198+
* so tokenization should still fail. */
199+
fprintf(f, "%sUNKNOWN", prefix.tok);
200+
} else {
201+
/* yield a token */
202+
fprintf(f, "%s", prefix.tok);
203+
esctok(f, m->token->s);
204+
}
205205
} else {
206-
fprintf(f, "lx->z(lx)");
206+
if (m->token == NULL) {
207+
/* update to a different zone, then call to it */
208+
fprintf(f, "lx->z = z%u, lx->z(lx)", zindexof(ast, m->to));
209+
} else {
210+
/* update zone, then yield a token */
211+
fprintf(f, "lx->z = z%u, ", zindexof(ast, m->to));
212+
fprintf(f, "%s", prefix.tok);
213+
esctok(f, m->token->s);
214+
}
207215
}
208216
fprintf(f, ";");
209217
return 0;

0 commit comments

Comments
 (0)