diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-04 10:58:08 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-04 10:58:08 +0000 |
commit | 5197e1664856fa4fef5a4c4dd43b6915e9fa847d (patch) | |
tree | 9ae47c46374251c049531aa0b25859cfe98a78a6 /crates/ra_mbe/src/lib.rs | |
parent | 698aa9b3f6420351a41a3fb4819b871fec3c891c (diff) | |
parent | c9d6efc468b2e845aba3237331ea2e02af1b8cc2 (diff) |
Merge #916
916: Error handling for macros r=matklad a=detrumi
Part of #720
Co-authored-by: Wilco Kusee <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 907402f5f..2c75b7b4f 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -24,6 +24,18 @@ use ra_syntax::SmolStr; | |||
24 | 24 | ||
25 | pub use tt::{Delimiter, Punct}; | 25 | pub use tt::{Delimiter, Punct}; |
26 | 26 | ||
27 | #[derive(Debug, PartialEq, Eq)] | ||
28 | pub enum ParseError { | ||
29 | Expected(String), | ||
30 | } | ||
31 | |||
32 | #[derive(Debug, PartialEq, Eq)] | ||
33 | pub enum ExpandError { | ||
34 | NoMatchingRule, | ||
35 | UnexpectedToken, | ||
36 | BindingError(String), | ||
37 | } | ||
38 | |||
27 | pub use crate::syntax_bridge::{ast_to_token_tree, token_tree_to_ast_item_list}; | 39 | pub use crate::syntax_bridge::{ast_to_token_tree, token_tree_to_ast_item_list}; |
28 | 40 | ||
29 | /// This struct contains AST for a single `macro_rules` definition. What might | 41 | /// This struct contains AST for a single `macro_rules` definition. What might |
@@ -36,11 +48,11 @@ pub struct MacroRules { | |||
36 | } | 48 | } |
37 | 49 | ||
38 | impl MacroRules { | 50 | impl MacroRules { |
39 | pub fn parse(tt: &tt::Subtree) -> Option<MacroRules> { | 51 | pub fn parse(tt: &tt::Subtree) -> Result<MacroRules, ParseError> { |
40 | mbe_parser::parse(tt) | 52 | mbe_parser::parse(tt) |
41 | } | 53 | } |
42 | pub fn expand(&self, tt: &tt::Subtree) -> Option<tt::Subtree> { | 54 | pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree, ExpandError> { |
43 | mbe_expander::exapnd(self, tt) | 55 | mbe_expander::expand(self, tt) |
44 | } | 56 | } |
45 | } | 57 | } |
46 | 58 | ||