diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-14 20:13:50 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-14 20:13:50 +0200 |
| commit | 1fb2d5103d0840f24ae588f4a05ed20a13f621d0 (patch) | |
| tree | d3875bc617e253876249d2ea9a2aa0b231f661c7 /src/library | |
| parent | 0ac2e86feb09cabd11c93bad325ab4acead8ccbe (diff) | |
Always parse bodies as syntax trees 🌳
Previously they were passed as strings to the function parser, now they are parsed and then passed as trees to the function. This allows making bodies sugar for a last content argument. While it removes some flexibility allowing function to parse arbitrary syntaxes in their bodies, these can be modelled as (raw) string arguments.
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/align.rs | 4 | ||||
| -rw-r--r-- | src/library/boxed.rs | 4 | ||||
| -rw-r--r-- | src/library/font.rs | 4 | ||||
| -rw-r--r-- | src/library/val.rs | 7 |
4 files changed, 9 insertions, 10 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index 8265c0f4..1ff07b89 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -10,11 +10,11 @@ use super::*; /// - `vertical`: Any of `top`, `bottom` or `center`. /// /// There may not be two alignment specifications for the same axis. -pub fn align(call: FuncCall, state: &ParseState) -> Pass<SyntaxNode> { +pub fn align(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.header.args; let node = AlignNode { - body: parse_body_maybe(call.body, state, &mut f), + body: call.body.map(|s| s.v), aligns: args.pos.all::<Spanned<SpecAlign>>().collect(), h: args.key.get::<Spanned<SpecAlign>>("horizontal", &mut f), v: args.key.get::<Spanned<SpecAlign>>("vertical", &mut f), diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 909115d5..5191480f 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -6,11 +6,11 @@ use super::*; /// # Keyword arguments /// - `width`: The width of the box (length of relative to parent's width). /// - `height`: The height of the box (length of relative to parent's height). -pub fn boxed(call: FuncCall, state: &ParseState) -> Pass<SyntaxNode> { +pub fn boxed(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.header.args; let node = BoxNode { - body: parse_body_maybe(call.body, state, &mut f).unwrap_or(SyntaxTree::new()), + body: call.body.map(|s| s.v).unwrap_or(SyntaxTree::new()), width: args.key.get::<ScaleLength>("width", &mut f), height: args.key.get::<ScaleLength>("height", &mut f), }; diff --git a/src/library/font.rs b/src/library/font.rs index 57ee92b3..356acc58 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -18,12 +18,12 @@ use super::*; /// ```typst /// serif = ("Source Serif Pro", "Noto Serif") /// ``` -pub fn font(call: FuncCall, state: &ParseState) -> Pass<SyntaxNode> { +pub fn font(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.header.args; let node = FontNode { - body: parse_body_maybe(call.body, state, &mut f), + body: call.body.map(|s| s.v), size: args.pos.get::<ScaleLength>(), style: args.key.get::<FontStyle>("style", &mut f), weight: args.key.get::<FontWeight>("weight", &mut f), diff --git a/src/library/val.rs b/src/library/val.rs index 8e431049..bbbeb1d1 100644 --- a/src/library/val.rs +++ b/src/library/val.rs @@ -4,12 +4,11 @@ use super::*; /// /// This is also the fallback function, which is used when a function name /// cannot be resolved. -pub fn val(call: FuncCall, state: &ParseState) -> Pass<SyntaxNode> { - let mut f = Feedback::new(); +pub fn val(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let node = ValNode { - body: parse_body_maybe(call.body, state, &mut f), + body: call.body.map(|s| s.v), }; - Pass::node(node, f) + Pass::node(node, Feedback::new()) } #[derive(Debug, Clone, PartialEq)] |
