fix comment not being ignored

pull/4/head
azur 2022-12-14 13:00:16 +07:00
parent a53d7b31f0
commit 0a62f14571
2 changed files with 29 additions and 5 deletions

View File

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

View File

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