feat: add comment support to saccharine language #25
@@ -78,17 +78,15 @@ func getToken(i *iterator.Iterator[rune]) (*Token, error) {
|
|||||||
case letter == ';':
|
case letter == ';':
|
||||||
return NewHardBreak(index), nil
|
return NewHardBreak(index), nil
|
||||||
case letter == '#':
|
case letter == '#':
|
||||||
// Skip everything until the next newline or EOF
|
// Skip everything until the next newline or EOF.
|
||||||
for {
|
for i.Done() {
|
||||||
if i.Done() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
r, err := i.Next()
|
r, err := i.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, trace.Wrap(err, "error while parsing comment")
|
return nil, trace.Wrap(err, "error while parsing comment")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r == '\n' {
|
if r == '\n' {
|
||||||
// Put the newline back so it can be processed as a soft break
|
// Put the newline back so it can be processed as a soft break.
|
||||||
i.Back()
|
i.Back()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
identity := \x.x # This is an end-of-line comment
|
identity := \x.x # This is an end-of-line comment
|
||||||
|
|
||||||
# Define a simple function that applies a function twice
|
# Define a simple function that applies a function twice
|
||||||
twice := \f.\x.(f (f x))
|
twice := \f.\x.(f
|
||||||
|
# Comments can be anywhere!
|
||||||
|
(f x))
|
||||||
|
|
||||||
# Test that comments don't interfere with expressions
|
# Test that comments don't interfere with expressions
|
||||||
result := (twice identity VALUE) # Should just return VALUE
|
result := (twice identity VALUE) # Should just return VALUE
|
||||||
|
|||||||
Reference in New Issue
Block a user