chars literals: Fixed parsing errors when using char literals master origin/HEAD origin/master
authorLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 07:16:18 +0000 (09:16 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 07:16:18 +0000 (09:16 +0200)
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
src/ulas.c
tests/t0.bin
tests/t0.s
tests/t0_dasm.s

diff --git a/BUGS.md b/BUGS.md
index 122b444859603a25881ea0e11d9d22bc79b0caa8..616168dd6851663a1906c5e2684b1995700d979c 100644 (file)
--- a/BUGS.md
+++ b/BUGS.md
@@ -1,8 +1,3 @@
 # Known Bugs
 
 # 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
index 127456a6dce507ee715b7465dec0ded0cc349260..19894badbb7e52ae6d10f84491572ac69dc0c34d 100644 (file)
@@ -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_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;
 
 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] == '"') {
 
   // 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];
 
     while (ULAS_TOKCOND) {
       char c = line[i];
 
index 782f7d1c6efd1a8aa99f737553384837c6a3a5cb..07421d86f071a5d72fa6a2165c5069a723d3244f 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index fe556b69bbb2a534fde23e1fd5d880b674368b88..79d90ed42e01cbf93c933f95accea48fbba85b82 100644 (file)
@@ -222,3 +222,7 @@ defarg2 DEFARG * arg_p, arg_p
 #endmacro
 
 nopnest1
 #endmacro
 
 nopnest1
+
+ld a, '/'
+ld a, ' '
+ld a, '\''
index 47f15d20c818052e172693eee93acd0720fd024d..6426d46425a74da8f3ef5bc8ac22e3426e31e495 100644 (file)
   ld [bc], a
   ld [bc], a
   nop 
   ld [bc], a
   ld [bc], a
   nop 
-.db 0x0
+  nop 
+  ld a, 0x2f
+  ld a, 0x20
+.db 0x3e
+.db 0x27