aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-15 19:34:46 +0100
committergingerBill <bill@gingerbill.org>2021-05-15 19:34:46 +0100
commit5d03bc61b870d525536290627044e9638c3495b9 (patch)
tree77c74045e3c6a0c8b2f51ba74526577d10aa8cec /src/tokenizer.cpp
parent5e31c04a01e5fa1d11c5a72b684263005451980a (diff)
Tokenize `++` and `--` as tokens but disallow them in the parser, and give better error messages for they are used as operators/statements
Diffstat (limited to 'src/tokenizer.cpp')
-rw-r--r--src/tokenizer.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp
index 081ef6443..3410517bc 100644
--- a/src/tokenizer.cpp
+++ b/src/tokenizer.cpp
@@ -51,8 +51,10 @@ TOKEN_KIND(Token__AssignOpBegin, ""), \
TOKEN_KIND(Token_CmpAndEq, "&&="), \
TOKEN_KIND(Token_CmpOrEq, "||="), \
TOKEN_KIND(Token__AssignOpEnd, ""), \
- TOKEN_KIND(Token_ArrowRight, "->"), \
- TOKEN_KIND(Token_Undef, "---"), \
+ TOKEN_KIND(Token_Increment, "++"), \
+ TOKEN_KIND(Token_Decrement, "--"), \
+ TOKEN_KIND(Token_ArrowRight,"->"), \
+ TOKEN_KIND(Token_Undef, "---"), \
\
TOKEN_KIND(Token__ComparisonBegin, ""), \
TOKEN_KIND(Token_CmpEq, "=="), \
@@ -1287,6 +1289,9 @@ void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) {
if (t->curr_rune == '=') {
advance_to_next_rune(t);
token->kind = Token_AddEq;
+ } else if (t->curr_rune == '+') {
+ advance_to_next_rune(t);
+ token->kind = Token_Increment;
}
break;
case '-':
@@ -1298,7 +1303,10 @@ void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) {
advance_to_next_rune(t);
advance_to_next_rune(t);
token->kind = Token_Undef;
- } else if (t->curr_rune == '>') {
+ } else if (t->curr_rune == '-') {
+ advance_to_next_rune(t);
+ token->kind = Token_Decrement;
+ }else if (t->curr_rune == '>') {
advance_to_next_rune(t);
token->kind = Token_ArrowRight;
}