Skip to content

Commit

Permalink
fix: bad parsing of comments at end of file closes #551
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed May 30, 2023
1 parent c3b8ff0 commit 26a607e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
- **uplc**: Fix pair formatting
- **aiken-lang**: forced new line in formatter for assignments
- **aiken-lang**: Incorrect parsing of generic type annotation prefixed with module
- **aiken-lang**: Incorrect handling of comments at end of a file when newline not present

## v1.0.6-alpha - 2023-05-17

Expand Down
4 changes: 2 additions & 2 deletions crates/aiken-lang/src/parser/lexer.rs
Expand Up @@ -148,13 +148,13 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
// NOTE: The first case here work around a bug introduced with chumsky=0.9.0 which
// miscalculate the offset for empty comments.
just("/".repeat(n))
.ignore_then(text::newline().rewind())
.ignore_then(choice((text::newline().rewind(), end())))
.to(token.clone())
.map_with_span(move |token, span: Span| {
(token, Span::new((), span.start + n..span.end))
}),
just("/".repeat(n)).ignore_then(
take_until(text::newline().rewind())
take_until(choice((text::newline().rewind(), end())))
.to(token)
.map_with_span(|token, span| (token, span)),
),
Expand Down
20 changes: 20 additions & 0 deletions crates/aiken-lang/src/tests/parser.rs
Expand Up @@ -38,6 +38,26 @@ fn windows_newline() {
)
}

#[test]
fn can_handle_comments_at_end_of_file() {
let code = indoc! {r#"
use aiken
// some comment
// more comments"#};

assert_definitions(
code,
vec![ast::UntypedDefinition::Use(Use {
location: Span::new((), 0..9),
module: vec!["aiken".to_string()],
as_name: None,
unqualified: vec![],
package: (),
})],
)
}

#[test]
fn type_annotation_with_module_prefix() {
let code = indoc! {r#"
Expand Down

0 comments on commit 26a607e

Please sign in to comment.