feat: add comment support to saccharine language
Add '#' comment syntax that works like Python comments. Comments can take up a whole line or appear at the end of a line. All characters after '#' until the next newline or EOF are ignored. Closes #24
This commit is contained in:
@@ -77,6 +77,23 @@ func getToken(i *iterator.Iterator[rune]) (*Token, error) {
|
||||
}
|
||||
case letter == ';':
|
||||
return NewHardBreak(index), nil
|
||||
case letter == '#':
|
||||
// Skip everything until the next newline or EOF
|
||||
for {
|
||||
if i.Done() {
|
||||
break
|
||||
}
|
||||
r, err := i.Next()
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err, "error while parsing comment")
|
||||
}
|
||||
if r == '\n' {
|
||||
// Put the newline back so it can be processed as a soft break
|
||||
i.Back()
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
case unicode.IsSpace(letter):
|
||||
return nil, nil
|
||||
case isVariable(letter):
|
||||
|
||||
Reference in New Issue
Block a user