From a6eacb6619819e82ba17499394b035a00b352a60 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 25 Aug 2025 09:16:18 +0200 Subject: [PATCH] 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. --- BUGS.md | 5 ----- src/ulas.c | 23 ++++++++++++++--------- tests/t0.bin | Bin 247 -> 253 bytes tests/t0.s | 4 ++++ tests/t0_dasm.s | 6 +++++- 5 files changed, 23 insertions(+), 15 deletions(-) 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 782f7d1c6efd1a8aa99f737553384837c6a3a5cb..07421d86f071a5d72fa6a2165c5069a723d3244f 100644 GIT binary patch delta 13 Ucmey)_?L0QcQ!kHI|Vy+04Ui6v;Y7A delta 6 Ncmey%_?>aWcK{3T1AYJi 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 -- 2.30.2