Moved comment handling to single point
authorLukas Krickl <lukas@krickl.dev>
Tue, 21 Nov 2023 05:13:25 +0000 (06:13 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 21 Nov 2023 05:13:25 +0000 (06:13 +0100)
src/ulas.c

index 1a482f05a41f0f69bc18a6c2ac0c8b0ca26a3022..d3d312f05ff8766b52f736e9ec84a99ad6a5ca85 100644 (file)
@@ -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;