Add support for nested C-style comments
This commit is contained in:
parent
26358faa09
commit
d0bc61275e
|
@ -183,6 +183,28 @@ func (l *Lexer) scanToken() {
|
||||||
for l.peek() != '\n' && !l.atEnd() {
|
for l.peek() != '\n' && !l.atEnd() {
|
||||||
l.advance()
|
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('.') {
|
} else if l.match('.') {
|
||||||
l.addSimpleToken(SLASH_DOT)
|
l.addSimpleToken(SLASH_DOT)
|
||||||
} else if l.match('_') {
|
} else if l.match('_') {
|
||||||
|
|
Loading…
Reference in a new issue