mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-21 23:10:05 +00:00
Added support for multiline comments using '/*' and '*/'
This commit is contained in:
parent
78e21a0f28
commit
7db0782991
18
src/clex.c
18
src/clex.c
@ -147,6 +147,8 @@ static char peekNext(CLexState *state) {
|
||||
}
|
||||
|
||||
char next(CLexState *state) {
|
||||
if (isEnd(state))
|
||||
return '\0'; // return a null terminator
|
||||
state->currentChar++;
|
||||
return state->currentChar[-1];
|
||||
}
|
||||
@ -182,11 +184,21 @@ void skipWhitespace(CLexState *state) {
|
||||
break;
|
||||
case '/': // consume comments
|
||||
if (peekNext(state) == '/') {
|
||||
|
||||
// skip to next line (also let \n be consumed on the next iteration to properly handle that)
|
||||
while (!isEnd(state) && peek(state) != '\n' && peek(state) != '\0') // if it's not a newline or null terminator
|
||||
while (!isEnd(state) && peek(state) != '\n') // if it's not a newline or the end of the source
|
||||
next(state);
|
||||
|
||||
|
||||
// keep consuming whitespace
|
||||
break;
|
||||
} else if (peekNext(state) == '*') { // multiline comments
|
||||
while (!isEnd(state) && !(peek(state) == '*' && peekNext(state) == '/')) // if it's the end of the comment or the end of the source
|
||||
next(state);
|
||||
|
||||
// consume the '*/'
|
||||
next(state);
|
||||
next(state);
|
||||
|
||||
// keep consuming whitespace
|
||||
break;
|
||||
}
|
||||
return; // it's a TOKEN_SLASH, let the main body handle that
|
||||
|
Loading…
Reference in New Issue
Block a user