diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-17 09:41:30 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-17 09:41:30 +0000 |
commit | 6aa432d86b7e4fb691600032ebdf6f2301152447 (patch) | |
tree | aa012212c11e43a95547f553b5116922631f9896 /crates/ra_tt | |
parent | cf4ae9aa591729dde25a7df3fa5c22ca0fd94145 (diff) | |
parent | 6c20d7e979b967eb20207414c0a0bf875bbcb98d (diff) |
Merge #3580
3580: More error-resilient MBE expansion r=matklad a=flodiebold
This is the beginning of an attempt to make macro-by-example expansion more resilient, so that we still get an expansion even if no rule exactly matches, with the goal to make completion work better in macro calls.
The general idea is to make everything return `(T, Option<ExpandError>)` instead of `Result<T, ExpandError>`; and then to try each macro arm in turn, and somehow choose the 'best' matching rule if none matches without errors. Finding that 'best' match isn't done yet; I'm currently counting how many tokens were consumed from the args before an error, but it also needs to take into account whether there were further patterns that had nothing to match.
I'll continue this later, but I'm interested whether you think this is the right path, @matklad & @edwin0cheng.
Co-authored-by: Florian Diebold <[email protected]>
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_tt')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 10f424aae..1e2fb8b91 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -40,6 +40,12 @@ pub enum TokenTree { | |||
40 | } | 40 | } |
41 | impl_froms!(TokenTree: Leaf, Subtree); | 41 | impl_froms!(TokenTree: Leaf, Subtree); |
42 | 42 | ||
43 | impl TokenTree { | ||
44 | pub fn empty() -> Self { | ||
45 | TokenTree::Subtree(Subtree::default()) | ||
46 | } | ||
47 | } | ||
48 | |||
43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 49 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
44 | pub enum Leaf { | 50 | pub enum Leaf { |
45 | Literal(Literal), | 51 | Literal(Literal), |