From: Lukas Krickl Date: Tue, 21 Nov 2023 05:13:25 +0000 (+0100) Subject: Moved comment handling to single point X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=9614695565aa5e469c476c2b333cae5e9a2ce867;p=ulas%2F.git Moved comment handling to single point --- diff --git a/src/ulas.c b/src/ulas.c index 1a482f0..d3d312f 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1064,6 +1064,9 @@ int ulas_tokall(const char **line, unsigned long n, int term) { // check for any expression terminators here if (tok.type == term || tok.type == ULAS_TOK_COMMENT) { + // on terminator we roll back line so that the terminator token + // is not consumed now + *line -= tokrc; goto end; } @@ -1360,7 +1363,7 @@ int ulas_istokend(struct ulas_str *tok) { int ulas_asminstr(char *dst, unsigned long max, const char *line, unsigned long n) { - if (max < 3) { + if (max < 4) { ULASPANIC("Instruction buffer is too small!"); return -1; } @@ -1390,14 +1393,6 @@ int ulas_asminstr(char *dst, unsigned long max, const char *line, return -1; } - // check for trailing - if (ulas_tok(&ulas.tok, &line, n) > 0) { - if (!ulas_istokend(&ulas.tok)) { - ULASERR("Trailing token '%s'\n", ulas.tok.buf); - return -1; - } - } - return rc; } @@ -1497,6 +1492,15 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { // only node in an expression! } + // check for trailing + // but only if its not a comment + if (ulas_tok(&ulas.tok, &line, n) > 0) { + if (!ulas_istokend(&ulas.tok)) { + ULASERR("Trailing token '%s'\n", ulas.tok.buf); + return -1; + } + } + ulas_asmout(dst, outbuf, towrite); ulas_asmlst(start, outbuf, towrite); ulas.address += towrite;