summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-31 22:41:06 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-31 22:41:06 +0200
commitfbd3d191137aac8188ab8c6503d257d65d873972 (patch)
tree60bc7039d226b1515dec19c6c8dc5a3306452cc7
parente35fca54a0c5b3cd5251a58837e9c1ef2b6c3c6d (diff)
Call args span now includes parens
-rw-r--r--src/parse/mod.rs26
-rw-r--r--tests/typ/code/closure.typ2
-rw-r--r--tests/typ/layout/spacing.typ2
-rw-r--r--tests/typ/utility/basics.typ2
-rw-r--r--tests/typ/utility/color.typ4
-rw-r--r--tests/typ/utility/math.typ4
6 files changed, 16 insertions, 24 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 70c23442..c103c342 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -303,7 +303,7 @@ fn primary(p: &mut Parser, atomic: bool) -> Option<Expr> {
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<Expr> {
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<Expr> {
}
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<Expr> {
/// 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<Expr> {
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 dcd35586..1bc369e9 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 ec520063..bd670edb 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 25cac039..203b7eb1 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 5b10477f..1e16c0a6 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 933f882f..3718866b 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)