From: Lukas Krickl Date: Mon, 25 Aug 2025 07:16:18 +0000 (+0200) Subject: chars literals: Fixed parsing errors when using char literals X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Fmaster;p=ulas%2F.git chars literals: Fixed parsing errors when using char literals This was caused by char literals being treated like generic tokens which causes termination when a char is encountered that is not alphanumeric. The fix is to treat them like strings. --- diff --git a/BUGS.md b/BUGS.md index 122b444..616168d 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,8 +1,3 @@ # Known Bugs -## .scc ' ' does not work -`.scc ' ' = 100` results in an error. The expected result is for it to re-map the space character. - -## Slash char literal parsing error -'/' char literal is broken diff --git a/src/ulas.c b/src/ulas.c index 127456a..19894ba 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -494,6 +494,16 @@ int ulas_symbolout(FILE *dst, struct ulas_sym *s) { #define ULAS_TOKISTERM write #define ULAS_TOKCOND (i < n && write < n && line[i]) +#define ULAS_QUOTED_TOKEN(quote_char) { \ + dst->buf[write++] = line[i++];\ + int last_escape = 0;\ + while (ULAS_TOKCOND && (line[i] != (quote_char) || last_escape)) {\ + last_escape = line[i] == '\\';\ + dst->buf[write++] = line[i];\ + i++;\ + }\ + dst->buf[write++] = line[i++];\ + } int ulas_tok(struct ulas_str *dst, const char **out_line, unsigned long n) { const char *line = *out_line; @@ -509,15 +519,10 @@ int ulas_tok(struct ulas_str *dst, const char **out_line, unsigned long n) { // string token if (line[i] == '"') { - dst->buf[write++] = line[i++]; - int last_escape = 0; - while (ULAS_TOKCOND && (line[i] != '\"' || last_escape)) { - last_escape = line[i] == '\\'; - dst->buf[write++] = line[i]; - i++; - } - dst->buf[write++] = line[i++]; - } else { + ULAS_QUOTED_TOKEN('\"'); + } else if (line[i] == '\'') { + ULAS_QUOTED_TOKEN('\''); + } else { while (ULAS_TOKCOND) { char c = line[i]; diff --git a/tests/t0.bin b/tests/t0.bin index 782f7d1..07421d8 100644 Binary files a/tests/t0.bin and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index fe556b6..79d90ed 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -222,3 +222,7 @@ defarg2 DEFARG * arg_p, arg_p #endmacro nopnest1 + +ld a, '/' +ld a, ' ' +ld a, '\'' diff --git a/tests/t0_dasm.s b/tests/t0_dasm.s index 47f15d2..6426d46 100644 --- a/tests/t0_dasm.s +++ b/tests/t0_dasm.s @@ -136,4 +136,8 @@ ld [bc], a ld [bc], a nop -.db 0x0 + nop + ld a, 0x2f + ld a, 0x20 +.db 0x3e +.db 0x27