@@ -83,8 +83,8 @@ pub struct Parser {
83
83
impl Parser {
84
84
pub fn parse ( & self , code : & str ) -> Result < Block , ParserError > {
85
85
full_moon:: parse ( code)
86
- . map_err ( ParserError :: Parsing )
87
- . and_then ( |ast| self . convert_ast ( ast) . map_err ( ParserError :: Converting ) )
86
+ . map_err ( ParserError :: parsing )
87
+ . and_then ( |ast| self . convert_ast ( ast) . map_err ( ParserError :: converting ) )
88
88
}
89
89
90
90
pub fn preserve_tokens ( mut self ) -> Self {
@@ -1048,7 +1048,7 @@ impl Parser {
1048
1048
}
1049
1049
1050
1050
#[ derive( Clone , Debug ) ]
1051
- pub enum ConvertError {
1051
+ enum ConvertError {
1052
1052
Statement {
1053
1053
statement : String ,
1054
1054
} ,
@@ -1134,16 +1134,35 @@ impl fmt::Display for ConvertError {
1134
1134
}
1135
1135
1136
1136
#[ derive( Clone , Debug ) ]
1137
- pub enum ParserError {
1137
+ enum ParserErrorKind {
1138
1138
Parsing ( full_moon:: Error ) ,
1139
1139
Converting ( ConvertError ) ,
1140
1140
}
1141
1141
1142
+ #[ derive( Clone , Debug ) ]
1143
+ pub struct ParserError {
1144
+ kind : Box < ParserErrorKind > ,
1145
+ }
1146
+
1147
+ impl ParserError {
1148
+ fn parsing ( err : full_moon:: Error ) -> Self {
1149
+ Self {
1150
+ kind : ParserErrorKind :: Parsing ( err) . into ( ) ,
1151
+ }
1152
+ }
1153
+
1154
+ fn converting ( err : ConvertError ) -> Self {
1155
+ Self {
1156
+ kind : ParserErrorKind :: Converting ( err) . into ( ) ,
1157
+ }
1158
+ }
1159
+ }
1160
+
1142
1161
impl fmt:: Display for ParserError {
1143
1162
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1144
- match self {
1145
- Self :: Parsing ( err) => write ! ( f, "{}" , err) ,
1146
- Self :: Converting ( err) => write ! ( f, "{}" , err) ,
1163
+ match & * self . kind {
1164
+ ParserErrorKind :: Parsing ( err) => write ! ( f, "{}" , err) ,
1165
+ ParserErrorKind :: Converting ( err) => write ! ( f, "{}" , err) ,
1147
1166
}
1148
1167
}
1149
1168
}
0 commit comments