Add support for nested C-style comments
This commit is contained in:
parent
9f3ab157eb
commit
236172c9c5
|
@ -183,6 +183,28 @@ func (l *Lexer) scanToken() {
|
|||
for l.peek() != '\n' && !l.atEnd() {
|
||||
l.advance()
|
||||
}
|
||||
} else if l.match('*') {
|
||||
l.advance()
|
||||
l.advance() // swallow the "/*"
|
||||
nesting := 1
|
||||
// A comment goes until we reach */, however,
|
||||
// the comments can also nest
|
||||
for {
|
||||
if l.peek() == '/' && l.peekNext() == '*' {
|
||||
nesting++
|
||||
l.advance()
|
||||
l.advance()
|
||||
} else if l.peek() == '*' && l.peekNext() == '/' {
|
||||
nesting--
|
||||
l.advance()
|
||||
l.advance()
|
||||
} else {
|
||||
if l.peek() == '\n' {
|
||||
l.line++
|
||||
}
|
||||
l.advance()
|
||||
}
|
||||
}
|
||||
} else if l.match('.') {
|
||||
l.addSimpleToken(SLASH_DOT)
|
||||
} else if l.match('_') {
|
||||
|
|
Loading…
Reference in a new issue