all repos — xyw @ 4e537c4129d6d43826468842a3782a42d477fc8b

A minimal virtual machine and assembler for terminals.

Refactoring: symbol validation function.
h3rald h3rald@h3rald.com
Wed, 26 Nov 2025 14:06:10 +0100
commit

4e537c4129d6d43826468842a3782a42d477fc8b

parent

492a40825569405ca3d40290c10b59833eee4799

1 files changed, 5 insertions(+), 5 deletions(-)

jump to
M xywasm.cxywasm.c

@@ -70,16 +70,16 @@ }

str[8] = '\0'; } -static int validate_symbol(xyw_context *ctx, char *str, unsigned int start_index, unsigned int length) +static int validate_symbol(xyw_context *ctx, char *str, unsigned int length) { // symbols must start with a letter or underscore, // and they can contain letters, numbers, underscores, dashes, or dots. - if (!((str[start_index] >= 'A' && str[start_index] <= 'Z') || (str[start_index] >= 'a' && str[start_index] <= 'z') || str[start_index] == '_')) + if (!((str[0] >= 'A' && str[0] <= 'Z') || (str[0] >= 'a' && str[0] <= 'z') || str[0] == '_')) { symbol_error(str, "symbol must start with a letter or underscore"); return -1; } - for (unsigned int i = start_index + 1; i < length; i++) + for (unsigned int i = 1; i < length; i++) { char c = str[i]; if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.'))

@@ -278,7 +278,7 @@ }

static int parse_symbol(xyw_context *ctx) { - if (validate_symbol(ctx, token, 0, token_length) != 0) + if (validate_symbol(ctx, token, token_length) != 0) { return -1; }

@@ -290,7 +290,7 @@ }

static int parse_directive(xyw_context *ctx) { - if (validate_symbol(ctx, token, 1, token_length) != 0) + if (validate_symbol(ctx, token + 1, token_length - 1) != 0) { return -1; }