58af657f2ee3 — Danielle Hutzley v0.0.3 2 years ago
Actually fix single number parsing, should probably test before tagging
2 files changed, 10 insertions(+), 7 deletions(-)

M src/laal_lexer.c
M test/lexer.c
M src/laal_lexer.c +8 -5
@@ 44,13 44,16 @@ is_whitespace (char c)
 static bool
 is_number (const char *begin, uintptr_t len)
 {
-  const char *cur = begin;
-  if (*cur == '-')
+  uintptr_t cur = 0;
+  if (begin[cur] == '-')
     cur++;
 
-  while (++cur < begin + len)
-    if (!(isdigit (*cur) || *cur == '.'))
-      return false;
+  while (cur < len)
+    {
+      if (!(isdigit (begin[cur]) || begin[cur] == '.'))
+        return false;
+      cur++;
+    }
 
   return true;
 }

          
M test/lexer.c +2 -2
@@ 47,8 47,8 @@ test_lex (const char *programme, const l
         }
       if (expected_tokens[i].type != tok->type)
         {
-          fprintf (stderr, "Expected: %d, Actual: %d", expected_tokens[i].type,
-                   tok->type);
+          fprintf (stderr, "\nExpected: %d, Actual: %d",
+                   expected_tokens[i].type, tok->type);
           TEST_FAIL (
               "Mismatched token types, see laal_lexer.h for variant names")
         }