Compare commits
1 commit
master
...
multiline-
Author | SHA1 | Date | |
---|---|---|---|
ab75e73421 |
1 changed files with 30 additions and 0 deletions
|
@ -80,6 +80,8 @@ class Scanner {
|
||||||
if (match('/')) {
|
if (match('/')) {
|
||||||
// A comment goes until the end of the line.
|
// A comment goes until the end of the line.
|
||||||
while (peek() != '\n' && !isAtEnd()) advance();
|
while (peek() != '\n' && !isAtEnd()) advance();
|
||||||
|
} else if (match('*')) {
|
||||||
|
multiline_comment();
|
||||||
} else {
|
} else {
|
||||||
addToken(SLASH);
|
addToken(SLASH);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +157,34 @@ class Scanner {
|
||||||
addToken(STRING, value);
|
addToken(STRING, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void multiline_comment() {
|
||||||
|
int depth = 0;
|
||||||
|
|
||||||
|
while (!isAtEnd()
|
||||||
|
&& (peek() != '*' || peekNext() != '/' || depth != 0)) {
|
||||||
|
if (peek() == '\n') line++;
|
||||||
|
|
||||||
|
if (peek() == '/' && peekNext() == '*') {
|
||||||
|
depth++;
|
||||||
|
advance();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (peek() == '*' && peekNext() == '/') {
|
||||||
|
depth--;
|
||||||
|
advance();
|
||||||
|
}
|
||||||
|
|
||||||
|
advance();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAtEnd()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
advance();
|
||||||
|
advance();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean match(char expected) {
|
private boolean match(char expected) {
|
||||||
if (isAtEnd()) return false;
|
if (isAtEnd()) return false;
|
||||||
if (source.charAt(current) != expected) return false;
|
if (source.charAt(current) != expected) return false;
|
||||||
|
|
Loading…
Reference in a new issue