aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tokenizer.c')
-rw-r--r--src/tokenizer.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/tokenizer.c b/src/tokenizer.c
index 9ce1bba..d753b20 100644
--- a/src/tokenizer.c
+++ b/src/tokenizer.c
@@ -235,19 +235,6 @@ static CHECK_RESULT int __tokenizer_next(Tokenizer *self, Token *token) {
}
}
*token = TOK_IDENTIFIER;
- } else if(c == '"') {
- int string_end;
- ++self->index;
- string_end = find_end_of_string(self->code, self->index);
- if(string_end == -1) {
- tokenizer_print_error(self, self->prev_index, "String end not found. Did you forget '\"' or did you have a mismatch of number of '\"'?");
- return TOKENIZER_ERR;
- }
-
- self->value.string.data = &self->code.data[self->index];
- self->value.string.size = string_end - self->index;
- self->index = string_end + 1;
- *token = TOK_STRING;
} else if(isDigit(c)) {
int number_start;
int dot_index;
@@ -290,9 +277,31 @@ static CHECK_RESULT int __tokenizer_next(Tokenizer *self, Token *token) {
self->number_is_integer = bool_false;
}
*token = TOK_NUMBER;
+ } else if(c == '"') {
+ int string_end;
+ ++self->index;
+ string_end = find_end_of_string(self->code, self->index);
+ if(string_end == -1) {
+ tokenizer_print_error(self, self->prev_index, "String end not found. Did you forget '\"' or did you have a mismatch of number of '\"'?");
+ return TOKENIZER_ERR;
+ }
+
+ self->value.string.data = &self->code.data[self->index];
+ self->value.string.size = string_end - self->index;
+ self->index = string_end + 1;
+ *token = TOK_STRING;
} else if(c == '.') {
+ const char *start = self->code.data + self->index;
++self->index;
- SET_BINOP(BINOP_DOT);
+ /* ... */
+ if((usize)self->index + 2 < self->code.size && am_memcmp(self->code.data + self->index, "..", 2) == 0) {
+ self->index += 2;
+ self->value.identifier.data = start;
+ self->value.identifier.size = 3;
+ *token = TOK_C_VARARGS;
+ } else {
+ SET_BINOP(BINOP_DOT);
+ }
} else if(c == '+') {
++self->index;
SET_BINOP(BINOP_ADD);
@@ -351,6 +360,9 @@ static CHECK_RESULT int __tokenizer_next(Tokenizer *self, Token *token) {
} else if(c == ':') {
++self->index;
*token = TOK_COLON;
+ } else if(c == '?') {
+ ++self->index;
+ *token = TOK_QUESTION_MARK;
} else if(c == '@') {
const char *err_msg;
++self->index;
@@ -502,6 +514,12 @@ static BufferView tokenizer_expected_token_as_string(Token token) {
case TOK_RETURN:
str = "return";
break;
+ case TOK_QUESTION_MARK:
+ str = "?";
+ break;
+ case TOK_C_VARARGS:
+ str = "...";
+ break;
}
return create_buffer_view(str, strlen(str));
}