diff options
Diffstat (limited to 'src/compiler/lexer')
-rw-r--r-- | src/compiler/lexer/lexer.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/compiler/lexer/lexer.c b/src/compiler/lexer/lexer.c index 5c7c256..c216298 100644 --- a/src/compiler/lexer/lexer.c +++ b/src/compiler/lexer/lexer.c @@ -90,14 +90,45 @@ Nodes lexer(char const *restrict str) { } else if (follow == '*') { push_if_not_empty(&nodes, &nodes_size, &nodes_inserted, &node, str, i, TOKEN_NONE); - for (i += 2; str[i] != '\0' && str[i + 1] != '\0' && - (str[i] != '*' || str[i + 1] != '/'); - ++i); - if (str[i] == '\0' || str[i + 1] == '\0') { - perror("expected multi line comment to end\n"); - exit(1); + int in = 1; + for (i += 2;; ++i) { + switch (str[i]) { + case '\0': + fprintf(stderr, + "expected multi line comment to end at compiler line %d " + "and in=%d\n", + __LINE__, in); + exit(1); + case '*': + ++i; + if (str[i] == '/') { + --in; + if (in == 0) { + goto END_OF_BLOCK_COMMENT_LOOP; + } + } else if (str[i] == '\0') { + fprintf(stderr, + "expected multi line comment to end at compiler line " + "%d and in=%d\n", + __LINE__, in); + exit(1); + } + break; + case '/': + ++i; + if (str[i] == '*') { + ++in; + } else if (str[i] == '\0') { + fprintf(stderr, + "expected multi line comment to end at compiler line " + "%d and in=%d\n", + __LINE__, in); + exit(1); + } + break; + } } - i += 1; + END_OF_BLOCK_COMMENT_LOOP: push_if_not_empty(&nodes, &nodes_size, &nodes_inserted, &node, str, i, TOKEN_NONE); if (str[i] == '\0') { |