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:
2026-01-12 20:53:38 -05:00
parent 19652563a4
commit 6418e05255
3 changed files with 33 additions and 0 deletions

View File

@@ -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):