diff --git a/examples/sim.sial b/examples/sim.sial index 1ee9359..10155f2 100644 --- a/examples/sim.sial +++ b/examples/sim.sial @@ -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 \ No newline at end of file diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 54126c6..f69128c 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -174,15 +174,25 @@ pub fn lexer() -> impl Parser, Error = Simple> { .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>) {