aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/mbe/src/lib.rs16
-rw-r--r--crates/tt/src/lib.rs11
2 files changed, 27 insertions, 0 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index 22fbf9a80..844e5a117 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -12,6 +12,8 @@ mod subtree_source;
12#[cfg(test)] 12#[cfg(test)]
13mod tests; 13mod tests;
14 14
15use std::fmt;
16
15pub use tt::{Delimiter, Punct}; 17pub use tt::{Delimiter, Punct};
16 18
17use crate::{ 19use crate::{
@@ -42,6 +44,20 @@ impl From<tt::ExpansionError> for ExpandError {
42 } 44 }
43} 45}
44 46
47impl fmt::Display for ExpandError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 ExpandError::NoMatchingRule => f.write_str("no rule matches input tokens"),
51 ExpandError::UnexpectedToken => f.write_str("unexpected token in input"),
52 ExpandError::BindingError(e) => f.write_str(e),
53 ExpandError::ConversionError => f.write_str("could not convert tokens"),
54 ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"),
55 ExpandError::ProcMacroError(e) => write!(f, "{}", e),
56 ExpandError::Other(e) => f.write_str(e),
57 }
58 }
59}
60
45pub use crate::syntax_bridge::{ 61pub use crate::syntax_bridge::{
46 ast_to_token_tree, parse_to_token_tree, syntax_node_to_token_tree, token_tree_to_syntax_node, 62 ast_to_token_tree, parse_to_token_tree, syntax_node_to_token_tree, token_tree_to_syntax_node,
47 TokenMap, 63 TokenMap,
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 20c3f5eab..7c796f564 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -240,6 +240,17 @@ pub enum ExpansionError {
240 ExpansionError(String), 240 ExpansionError(String),
241} 241}
242 242
243impl fmt::Display for ExpansionError {
244 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
245 match self {
246 ExpansionError::IOError(e) => write!(f, "I/O error: {}", e),
247 ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e),
248 ExpansionError::Unknown(e) => write!(f, "{}", e),
249 ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e),
250 }
251 }
252}
253
243pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { 254pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe {
244 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) 255 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
245 -> Result<Subtree, ExpansionError>; 256 -> Result<Subtree, ExpansionError>;