mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Handle missing arguments to with expr
This commit is contained in:
parent
859275b17b
commit
c5635d8a3f
@ -256,7 +256,7 @@ fn expr_with(p: &mut Parser, atomic: bool, min_prec: usize) -> Option<Expr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.eat_if(Token::With) {
|
if p.eat_if(Token::With) {
|
||||||
lhs = with_expr(p, lhs);
|
lhs = with_expr(p, lhs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if atomic {
|
if atomic {
|
||||||
@ -574,16 +574,21 @@ fn args(p: &mut Parser) -> CallArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a with expression.
|
/// Parse a with expression.
|
||||||
fn with_expr(p: &mut Parser, callee: Expr) -> Expr {
|
fn with_expr(p: &mut Parser, callee: Expr) -> Option<Expr> {
|
||||||
p.start_group(Group::Paren, TokenMode::Code);
|
if p.peek() == Some(Token::LeftParen) {
|
||||||
let args = args(p);
|
p.start_group(Group::Paren, TokenMode::Code);
|
||||||
p.end_group();
|
let args = args(p);
|
||||||
|
p.end_group();
|
||||||
|
|
||||||
Expr::With(WithExpr {
|
Some(Expr::With(WithExpr {
|
||||||
span: p.span(callee.span().start),
|
span: p.span(callee.span().start),
|
||||||
callee: Box::new(callee),
|
callee: Box::new(callee),
|
||||||
args,
|
args,
|
||||||
})
|
}))
|
||||||
|
} else {
|
||||||
|
p.expected("argument list");
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a let expression.
|
/// Parse a let expression.
|
||||||
@ -596,7 +601,7 @@ fn let_expr(p: &mut Parser) -> Option<Expr> {
|
|||||||
let mut init = None;
|
let mut init = None;
|
||||||
|
|
||||||
if p.eat_if(Token::With) {
|
if p.eat_if(Token::With) {
|
||||||
init = Some(with_expr(p, Expr::Ident(binding.clone())));
|
init = with_expr(p, Expr::Ident(binding.clone()));
|
||||||
} else {
|
} else {
|
||||||
// If a parenthesis follows, this is a function definition.
|
// If a parenthesis follows, this is a function definition.
|
||||||
let mut params = None;
|
let mut params = None;
|
||||||
|
@ -38,6 +38,12 @@
|
|||||||
// Error: 14-22 cannot apply '+=' to integer and string
|
// Error: 14-22 cannot apply '+=' to integer and string
|
||||||
{ let x = 1; x += "2" }
|
{ let x = 1; x += "2" }
|
||||||
|
|
||||||
|
// Error: 13-14 expected argument list, found integer
|
||||||
|
{ test with 2 }
|
||||||
|
|
||||||
|
// Error: 3-4 expected function, found integer
|
||||||
|
{ 1 with () }
|
||||||
|
|
||||||
---
|
---
|
||||||
// Bad left-hand sides of assignment.
|
// Bad left-hand sides of assignment.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user