Skip to content

Commit

Permalink
Make behavior between curly- and paren-delimited blocks consistent.
Browse files Browse the repository at this point in the history
  Note that the formatter rewrite parens-block sequences as curly-block sequences anyway. Albeit weird looking syntax, they are valid nonetheless.
  • Loading branch information
KtorZ committed Jan 20, 2024
1 parent bf96c3a commit 2f8cb02
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions crates/aiken-lang/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ pub enum ErrorKind {
hint: Option<String>,
},

#[error("I discovered an unfinished assignment.")]
#[error("I spotted an unfinished assignment.")]
#[diagnostic(
help(
"{} and {} bindings must be followed by a valid expression.",
"{} and {} bindings must be followed by a valid, complete, expression.",
"let".if_supports_color(Stdout, |s| s.yellow()),
"expect".if_supports_color(Stdout, |s| s.yellow()),
),
Expand Down
22 changes: 11 additions & 11 deletions crates/aiken-lang/src/parser/expr/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ pub fn parser(
choice((
sequence
.clone()
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace))
.map_with_span(|e, span| {
if matches!(e, UntypedExpr::Assignment { .. }) {
UntypedExpr::Sequence {
location: span,
expressions: vec![e],
}
} else {
e
}
}),
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace)),
sequence.clone().delimited_by(
choice((just(Token::LeftParen), just(Token::NewLineLeftParen))),
just(Token::RightParen),
),
))
.map_with_span(|e, span| {
if matches!(e, UntypedExpr::Assignment { .. }) {
UntypedExpr::Sequence {
location: span,
expressions: vec![e],
}
} else {
e
}
})
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
---
source: crates/aiken-lang/src/parser/expr/assignment.rs
description: "Invalid code (parse error):\n\nlet a = ( let b = 42 )"
description: "Code:\n\nlet a = ( let b = 42 )"
---
[
ParseError {
kind: UnfinishedAssignmentRightHandSide,
span: 0..22,
while_parsing: None,
expected: {},
label: Some(
"invalid assignment right-hand side",
),
Assignment {
location: 0..22,
value: Sequence {
location: 8..22,
expressions: [
Assignment {
location: 10..20,
value: UInt {
location: 18..20,
value: "42",
base: Decimal {
numeric_underscore: false,
},
},
pattern: Var {
location: 14..15,
name: "b",
},
kind: Let,
annotation: None,
},
],
},
]
pattern: Var {
location: 4..5,
name: "a",
},
kind: Let,
annotation: None,
}
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/tipo/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Perhaps, try the following:
as, expect, check, const, else, fn, if, is, let, opaque, pub, test, todo, trace, type, use, when"#))]
KeywordInModuleName { name: String, keyword: String },

#[error("I discovered a function which is ending with an assignment.\n")]
#[error("I discovered a block which is ending with an assignment.\n")]
#[diagnostic(url("https://aiken-lang.org/language-tour/functions#named-functions"))]
#[diagnostic(code("illegal::return"))]
#[diagnostic(help(r#"In Aiken, functions must return an explicit result in the form of an expression. While assignments are technically speaking expressions, they aren't allowed to be the last expression of a function because they convey a different meaning and this could be error-prone.
Expand Down

0 comments on commit 2f8cb02

Please sign in to comment.