mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
fix comment not being ignored
This commit is contained in:
parent
a53d7b31f0
commit
0a62f14571
|
@ -1,4 +1,16 @@
|
|||
fun foo x = x
|
||||
// start
|
||||
|
||||
fun foo x = do
|
||||
69 // unused
|
||||
print("Hi")
|
||||
x
|
||||
end
|
||||
|
||||
/* block comment
|
||||
|
||||
fun invalid =
|
||||
|
||||
*/
|
||||
|
||||
fun fac n = if n == 0 then 1 else n * fac(n - 1)
|
||||
|
||||
|
@ -6,3 +18,5 @@ fun main = do
|
|||
print(foo(1))
|
||||
print(fac(5))
|
||||
end
|
||||
|
||||
// end
|
|
@ -174,15 +174,25 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
|||
.or(symbol)
|
||||
.or(delim)
|
||||
.or(keyword)
|
||||
.map_with_span(move |token, span| (token, span))
|
||||
.padded()
|
||||
.recover_with(skip_then_retry_until([]));
|
||||
|
||||
let comment = just("--").then(take_until(just('\n'))).padded();
|
||||
let comments = just('/')
|
||||
.then_ignore(
|
||||
just('*')
|
||||
.ignore_then(take_until(just("*/")).ignored())
|
||||
.or(just('/').ignore_then(none_of('\n').ignored().repeated().ignored())),
|
||||
)
|
||||
.padded()
|
||||
.ignored()
|
||||
.repeated();
|
||||
|
||||
token
|
||||
.padded_by(comment.repeated())
|
||||
.map_with_span(|token, span| (token, span))
|
||||
.padded()
|
||||
.padded_by(comments)
|
||||
.repeated()
|
||||
.padded()
|
||||
.then_ignore(end())
|
||||
}
|
||||
|
||||
pub fn lex(src: String) -> (Option<Vec<(Token, Span)>>, Vec<Simple<char>>) {
|
||||
|
|
Loading…
Reference in a new issue