diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-28 18:51:23 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-28 22:38:02 -0500 |
| commit | 421489b1cae33a054a7eb8e852b01dabbeafc3c1 (patch) | |
| tree | 02e340a81ab5662b72578f38ab7beea8e58bfea1 | |
| parent | Ignore nasm, object and executable files (diff) | |
| download | cup-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.c | 11 |
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); |