diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-12-27 20:45:20 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-12-27 20:45:20 +0100 |
| commit | ba3d43f7b2a18984be27f3d472884a19f3adce4c (patch) | |
| tree | 1c6ffa31145fb69c19319440969d2037b27b584f /src/parse/mod.rs | |
| parent | 750d220bb080be077cd7ede6d18d485b1c3fb0c9 (diff) | |
Refresh function call and dictionary syntax
- No colon between function name and arguments, just whitespace
- "Named" arguments (previously "keyword" arguments) use colon instead of equals sign
Diffstat (limited to 'src/parse/mod.rs')
| -rw-r--r-- | src/parse/mod.rs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 04a9de58..3f647b12 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -154,7 +154,7 @@ fn bracket_call(p: &mut Parser) -> ExprCall { let mut outer = vec![]; let mut inner = p.span(|p| bracket_subheader(p)); - while p.eat_if(Token::Chain) { + while p.eat_if(Token::Pipe) { outer.push(inner); inner = p.span(|p| bracket_subheader(p)); } @@ -186,28 +186,17 @@ fn bracket_subheader(p: &mut Parser) -> ExprCall { p.skip_white(); let name = p.span(|p| ident(p)).transpose().unwrap_or_else(|| { + let what = "function name"; if p.eof() { - p.diag_expected_at("function name", start); + p.diag_expected_at(what, start); } else { - p.diag_expected("function name"); + p.diag_expected(what); } Ident(String::new()).span_with(start) }); p.skip_white(); - let args = if p.eat_if(Token::Colon) { - p.skip_white(); - p.span(|p| dict_contents(p).0) - } else { - // Ignore the rest if there's no colon. - p.span(|p| { - if !p.eof() { - p.diag_expected_at("colon", p.pos()); - } - p.eat_while(|_| true); - LitDict::new() - }) - }; + let args = p.span(|p| dict_contents(p).0); p.end_group(); ExprCall { name, args } @@ -285,8 +274,8 @@ fn dict_entry(p: &mut Parser) -> Option<LitDictEntry> { p.skip_white(); match p.peek() { // Key-value pair. - Some(Token::Equals) => { - p.eat_assert(Token::Equals); + Some(Token::Colon) => { + p.eat_assert(Token::Colon); p.skip_white(); if let Some(expr) = expr(p) { Some(LitDictEntry { @@ -463,7 +452,7 @@ fn content(p: &mut Parser) -> SynTree { tree } -/// Parse a parenthesized expression: `(a + b)`, `(1, key="value"). +/// Parse a parenthesized expression: `(a + b)`, `(1, name: "value"). fn parenthesized(p: &mut Parser) -> Expr { p.start_group(Group::Paren); let (dict, coercible) = dict_contents(p); |
