Now processing comments properly.
h3rald h3rald@h3rald.com
Fri, 28 Nov 2025 14:23:37 +0100
1 files changed,
21 insertions(+),
28 deletions(-)
jump to
M
xywasm.c
→
xywasm.c
@@ -318,34 +318,7 @@ //// Processing functions
static int process_comment(xyw_context *ctx) { - char c; - // Process single-line comment - while (1) - { - if (ctx->src == SRC_FILE) - { - if (fread(&c, 1, 1, ctx->fp) != 1) - { - break; - } - } - else - { - if (!ctx->sp || *ctx->sp == '\0') - { - break; - } - c = *ctx->sp++; - } - // Ignore all characters until end of line - if (c == '\n') - { - ctx->line++; - ctx->column = 0; - break; - } - ctx->column++; - } + (void)ctx; token_type = TOKEN_TYPE_COMMENT; printf("Comment:\t%s\n", token); return 0;@@ -839,6 +812,7 @@ static xyw_token_terminator next_token(xyw_context *ctx)
{ char c; int in_string = 0; + int in_comment = 0; token_length = 0; token[0] = '\0'; while (1)@@ -859,6 +833,7 @@ break;
} c = *ctx->sp++; } + // Handle character if (c == '\n') { if (in_string)@@ -866,10 +841,20 @@ {
token_error("Unterminated string literal"); return TOKEN_END_INVALID; } + if (in_comment) + { + in_comment = 0; + } ctx->line++; ctx->column = 1; return TOKEN_END_EOL; } + else if (in_comment) + { + ctx->column++; + token[token_length++] = (char)c; + token[token_length] = '\0'; + } else if (c == '"') { ctx->column++;@@ -897,6 +882,14 @@ {
token_error("Token too long"); return TOKEN_END_INVALID; } + token[token_length++] = (char)c; + token[token_length] = '\0'; + } + else if (c == ';' && !in_string && !in_comment) + { + in_comment = 1; + ctx->column++; + // Start of comment token token[token_length++] = (char)c; token[token_length] = '\0'; }