aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r--crates/ra_mbe/src/lib.rs18
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
25pub use tt::{Delimiter, Punct}; 25pub use tt::{Delimiter, Punct};
26 26
27#[derive(Debug, PartialEq, Eq)]
28pub enum ParseError {
29 Expected(String),
30}
31
32#[derive(Debug, PartialEq, Eq)]
33pub enum ExpandError {
34 NoMatchingRule,
35 UnexpectedToken,
36 BindingError(String),
37}
38
27pub use crate::syntax_bridge::{ast_to_token_tree, token_tree_to_ast_item_list}; 39pub 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
38impl MacroRules { 50impl 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