File tree Expand file tree Collapse file tree 2 files changed +27
-23
lines changed
Expand file tree Collapse file tree 2 files changed +27
-23
lines changed Original file line number Diff line number Diff line change 1+ use crate :: parser:: Rule ;
2+
3+ #[ derive( Debug ) ]
4+ pub enum ParseError {
5+ PestError ( Box < pest:: error:: Error < Rule > > ) ,
6+ SemanticError ( String ) ,
7+ }
8+
9+ impl From < pest:: error:: Error < Rule > > for ParseError {
10+ fn from ( error : pest:: error:: Error < Rule > ) -> Self {
11+ Self :: PestError ( Box :: new ( error) )
12+ }
13+ }
14+
15+ impl std:: fmt:: Display for ParseError {
16+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
17+ match self {
18+ Self :: PestError ( e) => write ! ( f, "Parse error: {e}" ) ,
19+ Self :: SemanticError ( e) => write ! ( f, "Semantic error: {e}" ) ,
20+ }
21+ }
22+ }
23+
24+ impl std:: error:: Error for ParseError { }
Original file line number Diff line number Diff line change @@ -13,33 +13,13 @@ use crate::{
1313 } ,
1414} ;
1515
16+ pub mod error;
17+ pub use error:: * ;
18+
1619#[ derive( Parser , Debug ) ]
1720#[ grammar = "grammar.pest" ]
1821pub struct LangParser ;
1922
20- #[ derive( Debug ) ]
21- pub enum ParseError {
22- PestError ( Box < pest:: error:: Error < Rule > > ) ,
23- SemanticError ( String ) ,
24- }
25-
26- impl From < pest:: error:: Error < Rule > > for ParseError {
27- fn from ( error : pest:: error:: Error < Rule > ) -> Self {
28- Self :: PestError ( Box :: new ( error) )
29- }
30- }
31-
32- impl std:: fmt:: Display for ParseError {
33- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
34- match self {
35- Self :: PestError ( e) => write ! ( f, "Parse error: {e}" ) ,
36- Self :: SemanticError ( e) => write ! ( f, "Semantic error: {e}" ) ,
37- }
38- }
39- }
40-
41- impl std:: error:: Error for ParseError { }
42-
4323pub fn parse_program ( input : & str ) -> Result < Program , ParseError > {
4424 let input = remove_comments ( input) ;
4525 let mut pairs = LangParser :: parse ( Rule :: program, & input) ?;
You can’t perform that action at this time.
0 commit comments