summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-14 20:13:50 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-14 20:13:50 +0200
commit1fb2d5103d0840f24ae588f4a05ed20a13f621d0 (patch)
treed3875bc617e253876249d2ea9a2aa0b231f661c7 /src/syntax
parent0ac2e86feb09cabd11c93bad325ab4acead8ccbe (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/syntax')
-rw-r--r--src/syntax/parsing.rs16
-rw-r--r--src/syntax/test.rs7
2 files changed, 15 insertions, 8 deletions
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index ae3f7e3d..502f4de1 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -15,9 +15,9 @@ pub type CallParser = dyn Fn(FuncCall, &ParseState) -> Pass<SyntaxNode>;
/// An invocation of a function.
#[derive(Debug, Clone, PartialEq)]
-pub struct FuncCall<'s> {
+pub struct FuncCall {
pub header: FuncHeader,
- pub body: FuncBody<'s>,
+ pub body: FuncBody,
}
/// The parsed header of a function (everything in the first set of brackets).
@@ -29,7 +29,7 @@ pub struct FuncHeader {
/// The body of a function as a raw spanned string containing what's inside of
/// the brackets.
-pub type FuncBody<'s> = Option<Spanned<&'s str>>;
+pub type FuncBody = Option<Spanned<SyntaxTree>>;
/// The positional and keyword arguments passed to a function.
#[derive(Debug, Default, Clone, PartialEq)]
@@ -196,9 +196,17 @@ impl<'s> FuncParser<'s> {
(parser, header)
};
- let call = FuncCall { header, body: self.body };
+ let body = self.body.map(|body| body.map(|src| {
+ let parsed = parse(src, body.span.start, &self.state);
+ self.feedback.extend(parsed.feedback);
+ parsed.output
+ }));
+
+ let call = FuncCall { header, body };
+
let parsed = parser(call, self.state);
self.feedback.extend(parsed.feedback);
+
Pass::new(parsed.output, self.feedback)
}
diff --git a/src/syntax/test.rs b/src/syntax/test.rs
index 7dec20e3..2ea5dde3 100644
--- a/src/syntax/test.rs
+++ b/src/syntax/test.rs
@@ -58,13 +58,12 @@ macro_rules! span_item {
};
}
-pub fn debug_func(call: FuncCall, state: &ParseState) -> Pass<SyntaxNode> {
- let mut f = Feedback::new();
+pub fn debug_func(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> {
let node = DebugNode {
header: call.header,
- 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)]