From 88151c546f3d4e8e594a5bfa6dfb0953d5e996b9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 13 Aug 2020 20:10:29 +0200 Subject: [PATCH] =?UTF-8?q?Use=20equals=20sign=20instead=20of=20colon=20fo?= =?UTF-8?q?r=20objects=20=F0=9F=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/expr.rs | 4 ++-- src/syntax/parsing.rs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index a637f115f..dd23ea610 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -30,7 +30,7 @@ pub enum Expr { Tuple(Tuple), /// A named tuple: `cmyk(37.7, 0, 3.9, 1.1)`. NamedTuple(NamedTuple), - /// An object: `{ fit: false, width: 12pt }`. + /// An object: `{ fit=false, width=12pt }`. Object(Object), /// An operation that negates the contained expression. Neg(Box>), @@ -322,7 +322,7 @@ impl Deref for NamedTuple { /// /// # Example /// ```typst -/// { fit: false, width: 12cm, items: (1, 2, 3) } +/// { fit = false, width = 12cm, items = (1, 2, 3) } /// ``` #[derive(Default, Clone, PartialEq)] pub struct Object(pub SpanVec); diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index b0b15dbfe..ae3f7e3d6 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -475,7 +475,7 @@ impl FuncParser<'_> { let after_key = self.pos(); self.skip_white(); - if !self.expect_at(Token::Colon, after_key) { + if !self.expect_at(Token::Equals, after_key) { continue; } @@ -1078,16 +1078,16 @@ mod tests { // Okay objects. pval!("{}" => (object! {})); - pval!("{ key: value }" => (object! { "key" => Id("value") })); + pval!("{ key = value }" => (object! { "key" => Id("value") })); // Unclosed object. - p!("[val: {hello: world]" => + p!("[val: {hello = world]" => [par![func!("val": (object! { "hello" => Id("world") }), {})]], - [(0:19, 0:19, "expected closing brace")], + [(0:20, 0:20, "expected closing brace")], ); p!("[val: { a]" => [par![func!("val": (object! {}), {})]], - [(0:9, 0:9, "expected colon"), (0:9, 0:9, "expected closing brace")], + [(0:9, 0:9, "expected equals sign"), (0:9, 0:9, "expected closing brace")], ); // Missing key. @@ -1096,39 +1096,39 @@ mod tests { p!("[val: { : }]" => [val()], [(0:8, 0:9, "expected key, found colon")]); // Missing colon. - p!("[val: { key }]" => [val()], [(0:11, 0:11, "expected colon")]); + p!("[val: { key }]" => [val()], [(0:11, 0:11, "expected equals sign")]); p!("[val: { key false }]" => [val()], [ - (0:11, 0:11, "expected colon"), + (0:11, 0:11, "expected equals sign"), (0:12, 0:17, "expected key, found bool"), ]); - p!("[val: { a b:c }]" => + p!("[val: { a b=c }]" => [par![func!("val": (object! { "b" => Id("c") }), {})]], - [(0:9, 0:9, "expected colon")], + [(0:9, 0:9, "expected equals sign")], ); // Missing value. - p!("[val: { key: : }]" => [val()], [(0:13, 0:14, "expected value, found colon")]); - p!("[val: { key: , k: \"s\" }]" => + p!("[val: { key= : }]" => [val()], [(0:13, 0:14, "expected value, found colon")]); + p!("[val: { key= , k= \"s\" }]" => [par![func!("val": (object! { "k" => Str("s") }), {})]], [(0:13, 0:14, "expected value, found comma")], ); // Missing comma, invalid token. - p!("[val: left={ a: 2, b: false 🌎 }]" => + p!("[val: left={ a=2, b=false 🌎 }]" => [par![func!("val": (), { "left" => object! { "a" => Num(2.0), "b" => Bool(false), } })]], - [(0:27, 0:27, "expected comma"), - (0:28, 0:29, "expected key, found invalid token")], + [(0:25, 0:25, "expected comma"), + (0:26, 0:27, "expected key, found invalid token")], ); } #[test] fn parse_nested_tuples_and_objects() { - pval!("(1, { ab: (), d: (3, 14pt) }), false" => ( + pval!("(1, { ab=(), d = (3, 14pt) }), false" => ( tuple!( Num(1.0), object!(