WIP: macro expand
authorLukas Krickl <lukas@krickl.dev>
Thu, 9 Nov 2023 06:06:18 +0000 (07:06 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 9 Nov 2023 06:06:18 +0000 (07:06 +0100)
src/test.c
src/ulas.c

index 5975de766918e14a39441213bed5d97799c9be74..7bd40a2d1086aeeb2cc303222f4d8b214147d69f 100644 (file)
@@ -31,9 +31,9 @@
 void test_tok(void) {
   TESTBEGIN("tok");
 
-  assert_tok(
-      "  test  tokens   with   line / * + - , ;",
-      {"test", "tokens", "with", "line", "/", "*", "+", "-", ",", ";", NULL});
+  assert_tok("  test  tokens   with   line / * + - , ; \\1",
+             {"test", "tokens", "with", "line", "/", "*", "+", "-", ",", ";",
+              "\\1", NULL});
 
   TESTEND("tok");
 }
index 51a92ed2c8b222d4d649af4264614800ba57d302..26545ef51e44a66960268602dd8aef0f35c6d825 100644 (file)
@@ -94,13 +94,16 @@ int ulas_tok(struct ulas_str *dst, const char **out_line, size_t n) {
   case '-':
   case '*':
   case '/':
-  case '\\':
   case ULAS_TOK_COMMENT:
     // single char tokens
     dst->buf[write++] = line[i++];
     break;
-    // consume rest of the line but do not write anything to tokens
-    i = (int)n;
+  case '\\':
+    // make sure we have enough space in buffer
+    ulas_strensr(dst, write + 2);
+    // escape char tokens
+    dst->buf[write++] = line[i++];
+    dst->buf[write++] = line[i++];
     break;
   default:
     while (weld_tokcond) {