diff options
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 | ||