add multiline comments
This commit is contained in:
parent
b24c0d3abd
commit
8b4496b363
@ -26,6 +26,9 @@ Lua-like, but with more minimalism and eventually some syntactic sugars.
|
||||
|
||||
```
|
||||
// C style comments
|
||||
/*
|
||||
C style multi line comments
|
||||
*/
|
||||
// No local for variable definitions; the local behavior should be implicit
|
||||
x = "foo"
|
||||
y = "bar"
|
||||
@ -33,6 +36,7 @@ fn add(a, b)
|
||||
return a + b
|
||||
end
|
||||
echo add(x, y) // Outputs: foobar
|
||||
fnVar = fn(x, y, ...) /* do something */ end
|
||||
|
||||
if expression and expression2 then
|
||||
res = add(1, 2)
|
||||
|
@ -59,10 +59,30 @@ func (s *Scanner) NextToken() types.Token {
|
||||
return s.makeToken(types.STAR)
|
||||
case '/':
|
||||
if s.match('/') {
|
||||
// Comment goes until end of line
|
||||
// Single-line comment
|
||||
for s.peek() != '\n' && !s.isAtEnd() {
|
||||
s.advance()
|
||||
}
|
||||
// Recursive call to get the next non-comment token
|
||||
return s.NextToken()
|
||||
} else if s.match('*') {
|
||||
// Multiline comment
|
||||
for !(s.peek() == '*' && s.peekNext() == '/') && !s.isAtEnd() {
|
||||
if s.peek() == '\n' {
|
||||
s.line++
|
||||
s.column = 0
|
||||
}
|
||||
s.advance()
|
||||
}
|
||||
|
||||
if s.isAtEnd() {
|
||||
return s.errorToken("Unclosed multiline comment.")
|
||||
}
|
||||
|
||||
// Consume the closing */
|
||||
s.advance() // *
|
||||
s.advance() // /
|
||||
|
||||
// Recursive call to get the next non-comment token
|
||||
return s.NextToken()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user