diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-02-09 22:56:44 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-02-09 22:56:44 +0100 |
| commit | f9197dcfef11c4c054a460c80ff6023dae6f1f2a (patch) | |
| tree | 500d28b7a6e35eb99245deaa38367a19dc2aed7b /src/syntax | |
| parent | 06ca740d01b428f12f6bd327257cd05dce737b03 (diff) | |
Add arguments value 🏓
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/expr.rs | 16 | ||||
| -rw-r--r-- | src/syntax/node.rs | 1 | ||||
| -rw-r--r-- | src/syntax/visit.rs | 6 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index f431ba8d..8a11ebc4 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -531,7 +531,7 @@ impl ExprCall { // Function name. self.callee.pretty(p); - let mut write_args = |items: &[Argument]| { + let mut write_args = |items: &[ExprArg]| { if !items.is_empty() { p.push(' '); p.join(items, ", ", |item, p| item.pretty(p)); @@ -542,7 +542,7 @@ impl ExprCall { // This can written as a chain. // // Example: Transforms "#[v][[f]]" => "#[v | f]". - [head @ .., Argument::Pos(Expr::Call(call))] => { + [head @ .., ExprArg::Pos(Expr::Call(call))] => { write_args(head); call.pretty_bracketed(p, true); } @@ -550,7 +550,7 @@ impl ExprCall { // This can be written with a body. // // Example: Transforms "#[v [Hi]]" => "#[v][Hi]". - [head @ .., Argument::Pos(Expr::Template(template))] => { + [head @ .., ExprArg::Pos(Expr::Template(template))] => { write_args(head); p.push(']'); template.pretty(p); @@ -573,7 +573,7 @@ pub struct ExprArgs { /// The source code location. pub span: Span, /// The positional and named arguments. - pub items: Vec<Argument>, + pub items: Vec<ExprArg>, } impl Pretty for ExprArgs { @@ -584,14 +584,14 @@ impl Pretty for ExprArgs { /// An argument to a function call: `12` or `draw: false`. #[derive(Debug, Clone, PartialEq)] -pub enum Argument { - /// A positional arguments. +pub enum ExprArg { + /// A positional argument. Pos(Expr), /// A named argument. Named(Named), } -impl Argument { +impl ExprArg { /// The source code location. pub fn span(&self) -> Span { match self { @@ -601,7 +601,7 @@ impl Argument { } } -impl Pretty for Argument { +impl Pretty for ExprArg { fn pretty(&self, p: &mut Printer) { match self { Self::Pos(expr) => expr.pretty(p), diff --git a/src/syntax/node.rs b/src/syntax/node.rs index fe9767a1..246790f6 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -31,6 +31,7 @@ impl Pretty for Node { Self::Space => p.push(' '), Self::Linebreak => p.push_str(r"\"), Self::Parbreak => p.push_str("\n\n"), + // TODO: Handle escaping. Self::Text(text) => p.push_str(&text), Self::Heading(heading) => heading.pretty(p), Self::Raw(raw) => raw.pretty(p), diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs index 70159d2d..2d3c683f 100644 --- a/src/syntax/visit.rs +++ b/src/syntax/visit.rs @@ -111,10 +111,10 @@ visit! { } } - fn visit_arg(v, node: &Argument) { + fn visit_arg(v, node: &ExprArg) { match node { - Argument::Pos(expr) => v.visit_expr(&expr), - Argument::Named(named) => v.visit_expr(&named.expr), + ExprArg::Pos(expr) => v.visit_expr(&expr), + ExprArg::Named(named) => v.visit_expr(&named.expr), } } |
