Fixes.
h3rald h3rald@h3rald.com
Fri, 22 Nov 2024 14:36:11 +0100
M
hex.c
→
hex.c
@@ -489,6 +489,7 @@ HEX_TOKEN_STRING,
HEX_TOKEN_SYMBOL, HEX_TOKEN_QUOTATION_START, HEX_TOKEN_QUOTATION_END, + HEX_TOKEN_COMMENT, HEX_TOKEN_INVALID } HEX_TokenType;@@ -510,8 +511,8 @@ HEX_Token *hex_next_token(const char **input, int *line, int *column)
{ const char *ptr = *input; - // Skip whitespace and comments - while (isspace(*ptr) || *ptr == ';') + // Skip whitespace + while (isspace(*ptr)) { if (*ptr == '\n') {@@ -522,15 +523,6 @@ else
{ (*column)++; } - - if (*ptr == ';') - { - while (*ptr != '\0' && *ptr != '\n') - { - ptr++; - (*column)++; - } - } ptr++; }@@ -544,7 +536,22 @@ token->value = NULL;
token->line = *line; token->column = *column; - if (*ptr == '"') + if (*ptr == ';') + { + // Comment token + const char *start = ptr; + while (*ptr != '\0' && *ptr != '\n') + { + ptr++; + (*column)++; + } + size_t len = ptr - start; + token->value = (char *)malloc(len + 1); + strncpy(token->value, start, len); + token->value[len] = '\0'; + token->type = HEX_TOKEN_COMMENT; + } + else if (*ptr == '"') { // String token ptr++;
M
tests.hex
→
tests.hex
@@ -1,11 +1,21 @@
+0x0 "successes" store +0x0 "failures" store + ( "current-test" store (current-test i) - ("." print) - ("\nTest Failed: " print current-test print "\n" print) + ( + "." print + successes 0x1 + "successes" store + ) + ( + "x" print + failures 0x1 + "failures" store + ) if ) "test" store -(0x1 0x1 ==) test i -(0x1 0x1 ==) test i -"" puts +(0x1 "a1" store a1 0x1 == "a1" free) test i +(0x1 0x2 ==) test i + +"\nSuccessful Tests: " print successes dec print "/" print successes failures + dec puts