Call args span now includes parens

This commit is contained in:
Laurenz 2021-07-31 22:41:06 +02:00
parent e35fca54a0
commit fbd3d19113
6 changed files with 16 additions and 24 deletions

View File

@ -303,7 +303,7 @@ fn primary(p: &mut Parser, atomic: bool) -> Option<Expr> {
match p.peek() { match p.peek() {
// Things that start with an identifier. // Things that start with an identifier.
Some(Token::Ident(string)) => { Some(Token::Ident(string)) => {
let id = Ident { let ident = Ident {
span: p.eat_span(), span: p.eat_span(),
string: string.into(), string: string.into(),
}; };
@ -312,13 +312,13 @@ fn primary(p: &mut Parser, atomic: bool) -> Option<Expr> {
Some(if !atomic && p.eat_if(Token::Arrow) { Some(if !atomic && p.eat_if(Token::Arrow) {
let body = expr(p)?; let body = expr(p)?;
Expr::Closure(ClosureExpr { Expr::Closure(ClosureExpr {
span: id.span.join(body.span()), span: ident.span.join(body.span()),
name: None, name: None,
params: Rc::new(vec![id]), params: Rc::new(vec![ident]),
body: Rc::new(body), body: Rc::new(body),
}) })
} else { } else {
Expr::Ident(id) Expr::Ident(ident)
}) })
} }
@ -537,12 +537,7 @@ fn call(p: &mut Parser, callee: Expr) -> Option<Expr> {
} }
let mut args = match p.peek_direct() { let mut args = match p.peek_direct() {
Some(Token::LeftParen) => { Some(Token::LeftParen) => args(p),
p.start_group(Group::Paren, TokenMode::Code);
let args = args(p);
p.end_group();
args
}
Some(Token::LeftBracket) => CallArgs { Some(Token::LeftBracket) => CallArgs {
span: Span::at(callee.span().end), span: Span::at(callee.span().end),
items: vec![], items: vec![],
@ -568,22 +563,19 @@ fn call(p: &mut Parser, callee: Expr) -> Option<Expr> {
/// Parse the arguments to a function call. /// Parse the arguments to a function call.
fn args(p: &mut Parser) -> CallArgs { fn args(p: &mut Parser) -> CallArgs {
let start = p.next_start(); p.start_group(Group::Paren, TokenMode::Code);
let items = collection(p).0; let items = collection(p).0;
CallArgs { span: p.span(start), items } let span = p.end_group();
CallArgs { span, items }
} }
/// Parse a with expression. /// Parse a with expression.
fn with_expr(p: &mut Parser, callee: Expr) -> Option<Expr> { fn with_expr(p: &mut Parser, callee: Expr) -> Option<Expr> {
if p.peek() == Some(Token::LeftParen) { if p.peek() == Some(Token::LeftParen) {
p.start_group(Group::Paren, TokenMode::Code);
let args = args(p);
p.end_group();
Some(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: args(p),
})) }))
} else { } else {
p.expected("argument list"); p.expected("argument list");

View File

@ -71,7 +71,7 @@
let types(x, y) = "[" + type(x) + ", " + type(y) + "]" let types(x, y) = "[" + type(x) + ", " + type(y) + "]"
test(types(14%, 12pt), "[relative, length]") test(types(14%, 12pt), "[relative, length]")
// Error: 14-20 missing argument: y // Error: 13-21 missing argument: y
test(types("nope"), "[string, none]") test(types("nope"), "[string, none]")
} }

View File

@ -15,5 +15,5 @@ Relative #h(100%) spacing
--- ---
// Missing spacing. // Missing spacing.
// Error: 12 missing argument: spacing // Error: 11-13 missing argument: spacing
Totally #h() ignored Totally #h() ignored

View File

@ -9,7 +9,7 @@
#test(len((a: 1, b: 2)), 2) #test(len((a: 1, b: 2)), 2)
--- ---
// Error: 6 missing argument: collection // Error: 5-7 missing argument: collection
#len() #len()
--- ---

View File

@ -16,9 +16,9 @@
#rgb("lol") #rgb("lol")
--- ---
// Error: 6 missing argument: red component // Error: 5-7 missing argument: red component
#rgb() #rgb()
--- ---
// Error: 6-10 missing argument: blue component // Error: 5-11 missing argument: blue component
#rgb(0, 1) #rgb(0, 1)

View File

@ -9,9 +9,9 @@
#test(min("hi"), "hi") #test(min("hi"), "hi")
--- ---
// Error: 6 missing argument: value // Error: 5-7 missing argument: value
#min() #min()
--- ---
// Error: 11-18 cannot compare integer with string // Error: 10-19 cannot compare integer with string
#test(min(1, "hi"), error) #test(min(1, "hi"), error)