1
1
Fork 0
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:
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) fun fac n = if n == 0 then 1 else n * fac(n - 1)
@ -6,3 +18,5 @@ fun main = do
print(foo(1)) print(foo(1))
print(fac(5)) print(fac(5))
end end
// end

View file

@ -174,15 +174,25 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
.or(symbol) .or(symbol)
.or(delim) .or(delim)
.or(keyword) .or(keyword)
.map_with_span(move |token, span| (token, span))
.padded()
.recover_with(skip_then_retry_until([])); .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 token
.padded_by(comment.repeated()) .padded_by(comments)
.map_with_span(|token, span| (token, span))
.padded()
.repeated() .repeated()
.padded()
.then_ignore(end())
} }
pub fn lex(src: String) -> (Option<Vec<(Token, Span)>>, Vec<Simple<char>>) { pub fn lex(src: String) -> (Option<Vec<(Token, Span)>>, Vec<Simple<char>>) {