Disabled comments in the repl

This commit is contained in:
2023-02-10 12:11:42 +00:00
parent a26a6a56d0
commit 66ea684a90
3 changed files with 13 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ static void cleanLexer(Toy_Lexer* lexer) {
lexer->start = 0;
lexer->current = 0;
lexer->line = 1;
lexer->commentsEnabled = true;
}
static bool isAtEnd(Toy_Lexer* lexer) {
@@ -54,6 +55,10 @@ static void eatWhitespace(Toy_Lexer* lexer) {
//comments
case '/':
if (!lexer->commentsEnabled) {
return;
}
//eat the line
if (peekNext(lexer) == '/') {
while (advance(lexer) != '\n' && !isAtEnd(lexer));
@@ -372,3 +377,7 @@ void Toy_printToken(Toy_Token* token) {
printf("\n");
}
void Toy_private_setComments(Toy_Lexer* lexer, bool enabled) {
lexer->commentsEnabled = enabled;
}

View File

@@ -9,6 +9,7 @@ typedef struct {
int start; //start of the token
int current; //current position of the lexer
int line; //track this for error handling
bool commentsEnabled; //BUGFIX: enable comments (disabled in repl)
} Toy_Lexer;
//tokens are intermediaries between lexers and parsers
@@ -24,3 +25,5 @@ Toy_Token Toy_scanLexer(Toy_Lexer* lexer);
//for debugging
void Toy_printToken(Toy_Token* token);
void Toy_private_setComments(Toy_Lexer* lexer, bool enabled);