From fbd3d191137aac8188ab8c6503d257d65d873972 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 31 Jul 2021 22:41:06 +0200 Subject: [PATCH] Call args span now includes parens --- src/parse/mod.rs | 26 +++++++++----------------- tests/typ/code/closure.typ | 2 +- tests/typ/layout/spacing.typ | 2 +- tests/typ/utility/basics.typ | 2 +- tests/typ/utility/color.typ | 4 ++-- tests/typ/utility/math.typ | 4 ++-- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 70c234422..c103c342d 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -303,7 +303,7 @@ fn primary(p: &mut Parser, atomic: bool) -> Option { match p.peek() { // Things that start with an identifier. Some(Token::Ident(string)) => { - let id = Ident { + let ident = Ident { span: p.eat_span(), string: string.into(), }; @@ -312,13 +312,13 @@ fn primary(p: &mut Parser, atomic: bool) -> Option { Some(if !atomic && p.eat_if(Token::Arrow) { let body = expr(p)?; Expr::Closure(ClosureExpr { - span: id.span.join(body.span()), + span: ident.span.join(body.span()), name: None, - params: Rc::new(vec![id]), + params: Rc::new(vec![ident]), body: Rc::new(body), }) } else { - Expr::Ident(id) + Expr::Ident(ident) }) } @@ -537,12 +537,7 @@ fn call(p: &mut Parser, callee: Expr) -> Option { } let mut args = match p.peek_direct() { - Some(Token::LeftParen) => { - p.start_group(Group::Paren, TokenMode::Code); - let args = args(p); - p.end_group(); - args - } + Some(Token::LeftParen) => args(p), Some(Token::LeftBracket) => CallArgs { span: Span::at(callee.span().end), items: vec![], @@ -568,22 +563,19 @@ fn call(p: &mut Parser, callee: Expr) -> Option { /// Parse the arguments to a function call. fn args(p: &mut Parser) -> CallArgs { - let start = p.next_start(); + p.start_group(Group::Paren, TokenMode::Code); let items = collection(p).0; - CallArgs { span: p.span(start), items } + let span = p.end_group(); + CallArgs { span, items } } /// Parse a with expression. fn with_expr(p: &mut Parser, callee: Expr) -> Option { if p.peek() == Some(Token::LeftParen) { - p.start_group(Group::Paren, TokenMode::Code); - let args = args(p); - p.end_group(); - Some(Expr::With(WithExpr { span: p.span(callee.span().start), callee: Box::new(callee), - args, + args: args(p), })) } else { p.expected("argument list"); diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ index dcd355865..1bc369e95 100644 --- a/tests/typ/code/closure.typ +++ b/tests/typ/code/closure.typ @@ -71,7 +71,7 @@ let types(x, y) = "[" + type(x) + ", " + type(y) + "]" test(types(14%, 12pt), "[relative, length]") - // Error: 14-20 missing argument: y + // Error: 13-21 missing argument: y test(types("nope"), "[string, none]") } diff --git a/tests/typ/layout/spacing.typ b/tests/typ/layout/spacing.typ index ec5200635..bd670edb8 100644 --- a/tests/typ/layout/spacing.typ +++ b/tests/typ/layout/spacing.typ @@ -15,5 +15,5 @@ Relative #h(100%) spacing --- // Missing spacing. -// Error: 12 missing argument: spacing +// Error: 11-13 missing argument: spacing Totally #h() ignored diff --git a/tests/typ/utility/basics.typ b/tests/typ/utility/basics.typ index 25cac039d..203b7eb1a 100644 --- a/tests/typ/utility/basics.typ +++ b/tests/typ/utility/basics.typ @@ -9,7 +9,7 @@ #test(len((a: 1, b: 2)), 2) --- -// Error: 6 missing argument: collection +// Error: 5-7 missing argument: collection #len() --- diff --git a/tests/typ/utility/color.typ b/tests/typ/utility/color.typ index 5b10477fa..1e16c0a6f 100644 --- a/tests/typ/utility/color.typ +++ b/tests/typ/utility/color.typ @@ -16,9 +16,9 @@ #rgb("lol") --- -// Error: 6 missing argument: red component +// Error: 5-7 missing argument: red component #rgb() --- -// Error: 6-10 missing argument: blue component +// Error: 5-11 missing argument: blue component #rgb(0, 1) diff --git a/tests/typ/utility/math.typ b/tests/typ/utility/math.typ index 933f882f3..3718866be 100644 --- a/tests/typ/utility/math.typ +++ b/tests/typ/utility/math.typ @@ -9,9 +9,9 @@ #test(min("hi"), "hi") --- -// Error: 6 missing argument: value +// Error: 5-7 missing argument: value #min() --- -// Error: 11-18 cannot compare integer with string +// Error: 10-19 cannot compare integer with string #test(min(1, "hi"), error)