From 3fc9c8e0db7723cc86ad38d335416fb110c5ff54 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 7 Jun 2023 17:21:04 -0400 Subject: [PATCH] chore: re-add empty line handling by @KtorZ Co-authored-by: KtorZ --- crates/aiken-lang/src/parser.rs | 2 +- crates/aiken-lang/src/tests/parser.rs | 40 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/crates/aiken-lang/src/parser.rs b/crates/aiken-lang/src/parser.rs index 59779bf9..750e540d 100644 --- a/crates/aiken-lang/src/parser.rs +++ b/crates/aiken-lang/src/parser.rs @@ -34,7 +34,7 @@ pub fn module( let mut previous_is_newline = false; let tokens = tokens.into_iter().filter_map(|(token, ref span)| { - let current_is_newline = token == Token::NewLine; + let current_is_newline = token == Token::NewLine || token == Token::EmptyLine; let result = match token { Token::ModuleComment => { extra.module_comments.push(*span); diff --git a/crates/aiken-lang/src/tests/parser.rs b/crates/aiken-lang/src/tests/parser.rs index 2c2ff67b..b0d292df 100644 --- a/crates/aiken-lang/src/tests/parser.rs +++ b/crates/aiken-lang/src/tests/parser.rs @@ -3297,3 +3297,43 @@ fn parse_keyword_todo() { ], ) } + +#[test] +fn brackets_followed_by_parenthesis() { + fn assert_sequence(code: &str) { + let (module, _extra) = parser::module(code, ast::ModuleKind::Validator).unwrap(); + assert!( + matches!( + module.definitions[..], + [ast::Definition::Test(Function { + body: expr::UntypedExpr::Sequence { .. }, + .. + })] + ), + "{}", + code.to_string() + ); + } + + assert_sequence(indoc! {r#" + test foo () { + let a = [] + (x |> y) == [] + } + "#}); + + assert_sequence(indoc! {r#" + test foo () { + let a = [] + (x |> y) == [] + } + "#}); + + assert_sequence(indoc! {r#" + test foo () { + let a = [] + // foo + (x |> y) == [] + } + "#}); +}