aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-01-28 18:51:23 -0500
committerMustafa Quraish <[email protected]>2022-01-28 22:38:02 -0500
commit421489b1cae33a054a7eb8e852b01dabbeafc3c1 (patch)
tree02e340a81ab5662b72578f38ab7beea8e58bfea1
parentIgnore nasm, object and executable files (diff)
downloadcup-421489b1cae33a054a7eb8e852b01dabbeafc3c1.tar.xz
cup-421489b1cae33a054a7eb8e852b01dabbeafc3c1.zip
Lexer: Support inline comments
Inline comments are now supported with `// Comment here`. No block comments (for now)
-rw-r--r--cup/lexer.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/cup/lexer.c b/cup/lexer.c
index d03ea78..b665353 100644
--- a/cup/lexer.c
+++ b/cup/lexer.c
@@ -129,9 +129,18 @@ Token Lexer_next(Lexer *lexer)
return Lexer_make_token(lexer, TOKEN_MINUSEQUALS, 2);
return Lexer_make_token(lexer, TOKEN_MINUS, 1);
}
+
+ case '/': {
+ if (peek(lexer, 1) == '/') {
+ lexer->pos += 2; // skip the '//'
+ while (lexer->pos < lexer->len && lexer->src[lexer->pos] != '\n')
+ lexer->pos++;
+ continue;
+ }
+ return Lexer_make_token(lexer, TOKEN_SLASH, 1);
+ }
case '*': return Lexer_make_token(lexer, TOKEN_STAR, 1);
- case '/': return Lexer_make_token(lexer, TOKEN_SLASH, 1);
case '%': return Lexer_make_token(lexer, TOKEN_PERCENT, 1);