mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Disabled comments in the repl
This commit is contained in:
@@ -53,6 +53,7 @@ void repl() {
|
|||||||
Toy_Compiler compiler;
|
Toy_Compiler compiler;
|
||||||
|
|
||||||
Toy_initLexer(&lexer, input);
|
Toy_initLexer(&lexer, input);
|
||||||
|
Toy_private_setComments(&lexer, false); //BUGFIX: disable comments here
|
||||||
Toy_initParser(&parser, &lexer);
|
Toy_initParser(&parser, &lexer);
|
||||||
Toy_initCompiler(&compiler);
|
Toy_initCompiler(&compiler);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ static void cleanLexer(Toy_Lexer* lexer) {
|
|||||||
lexer->start = 0;
|
lexer->start = 0;
|
||||||
lexer->current = 0;
|
lexer->current = 0;
|
||||||
lexer->line = 1;
|
lexer->line = 1;
|
||||||
|
lexer->commentsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isAtEnd(Toy_Lexer* lexer) {
|
static bool isAtEnd(Toy_Lexer* lexer) {
|
||||||
@@ -54,6 +55,10 @@ static void eatWhitespace(Toy_Lexer* lexer) {
|
|||||||
|
|
||||||
//comments
|
//comments
|
||||||
case '/':
|
case '/':
|
||||||
|
if (!lexer->commentsEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//eat the line
|
//eat the line
|
||||||
if (peekNext(lexer) == '/') {
|
if (peekNext(lexer) == '/') {
|
||||||
while (advance(lexer) != '\n' && !isAtEnd(lexer));
|
while (advance(lexer) != '\n' && !isAtEnd(lexer));
|
||||||
@@ -372,3 +377,7 @@ void Toy_printToken(Toy_Token* token) {
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Toy_private_setComments(Toy_Lexer* lexer, bool enabled) {
|
||||||
|
lexer->commentsEnabled = enabled;
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ typedef struct {
|
|||||||
int start; //start of the token
|
int start; //start of the token
|
||||||
int current; //current position of the lexer
|
int current; //current position of the lexer
|
||||||
int line; //track this for error handling
|
int line; //track this for error handling
|
||||||
|
bool commentsEnabled; //BUGFIX: enable comments (disabled in repl)
|
||||||
} Toy_Lexer;
|
} Toy_Lexer;
|
||||||
|
|
||||||
//tokens are intermediaries between lexers and parsers
|
//tokens are intermediaries between lexers and parsers
|
||||||
@@ -24,3 +25,5 @@ Toy_Token Toy_scanLexer(Toy_Lexer* lexer);
|
|||||||
|
|
||||||
//for debugging
|
//for debugging
|
||||||
void Toy_printToken(Toy_Token* token);
|
void Toy_printToken(Toy_Token* token);
|
||||||
|
|
||||||
|
void Toy_private_setComments(Toy_Lexer* lexer, bool enabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user