@@ -46,7 +46,7 @@ pub struct LexBuildError {
4646impl Error for LexBuildError { }
4747
4848/// The various different possible Lex parser errors.
49- #[ derive( Debug , PartialEq , Eq , Clone ) ]
49+ #[ derive( Debug , Clone ) ]
5050pub enum LexErrorKind {
5151 PrematureEnd ,
5252 RoutinesNotSupported ,
@@ -58,13 +58,40 @@ pub enum LexErrorKind {
5858 InvalidStartState ,
5959 InvalidStartStateName ,
6060 DuplicateName ,
61- RegexError ,
61+ RegexError ( regex :: Error ) ,
6262 InvalidGrmtoolsSectionValue ,
6363 InvalidNumber ,
6464 DuplicateGrmtoolsSectionValue ,
6565 VerbatimNotSupported ,
6666}
6767
68+ impl PartialEq for LexErrorKind {
69+ fn eq ( & self , other : & Self ) -> bool {
70+ use LexErrorKind as EK ;
71+ match ( self , other) {
72+ ( EK :: PrematureEnd , EK :: PrematureEnd )
73+ | ( EK :: RoutinesNotSupported , EK :: RoutinesNotSupported )
74+ | ( EK :: UnknownDeclaration , EK :: UnknownDeclaration )
75+ | ( EK :: MissingSpace , EK :: MissingSpace )
76+ | ( EK :: InvalidName , EK :: InvalidName )
77+ | ( EK :: UnknownStartState , EK :: UnknownStartState )
78+ | ( EK :: DuplicateStartState , EK :: DuplicateStartState )
79+ | ( EK :: InvalidStartState , EK :: InvalidStartState )
80+ | ( EK :: InvalidStartStateName , EK :: InvalidStartStateName )
81+ | ( EK :: DuplicateName , EK :: DuplicateName )
82+ | ( EK :: InvalidGrmtoolsSectionValue , EK :: InvalidGrmtoolsSectionValue )
83+ | ( EK :: InvalidNumber , EK :: InvalidNumber )
84+ | ( EK :: DuplicateGrmtoolsSectionValue , EK :: DuplicateGrmtoolsSectionValue )
85+ | ( EK :: VerbatimNotSupported , EK :: VerbatimNotSupported ) => true ,
86+ ( EK :: RegexError ( e1) , EK :: RegexError ( e2) ) => e1. to_string ( ) == e2. to_string ( ) ,
87+
88+ _ => false ,
89+ }
90+ }
91+ }
92+
93+ impl Eq for LexErrorKind { }
94+
6895impl Spanned for LexBuildError {
6996 fn spans ( & self ) -> & [ Span ] {
7097 self . spans . as_slice ( )
@@ -83,7 +110,7 @@ impl Spanned for LexBuildError {
83110 | LexErrorKind :: InvalidGrmtoolsSectionValue
84111 | LexErrorKind :: InvalidNumber
85112 | LexErrorKind :: VerbatimNotSupported
86- | LexErrorKind :: RegexError => SpansKind :: Error ,
113+ | LexErrorKind :: RegexError ( _ ) => SpansKind :: Error ,
87114 LexErrorKind :: DuplicateName
88115 | LexErrorKind :: DuplicateStartState
89116 | LexErrorKind :: DuplicateGrmtoolsSectionValue => SpansKind :: DuplicationError ,
@@ -93,7 +120,7 @@ impl Spanned for LexBuildError {
93120
94121impl fmt:: Display for LexBuildError {
95122 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
96- let s = match self . kind {
123+ let s = match & self . kind {
97124 LexErrorKind :: VerbatimNotSupported => "Verbatim code not supported" ,
98125 LexErrorKind :: PrematureEnd => "File ends prematurely" ,
99126 LexErrorKind :: RoutinesNotSupported => "Routines not currently supported" ,
@@ -108,7 +135,7 @@ impl fmt::Display for LexBuildError {
108135 LexErrorKind :: InvalidNumber => "Invalid number" ,
109136 LexErrorKind :: DuplicateGrmtoolsSectionValue => "Duplicate grmtools section value" ,
110137 LexErrorKind :: DuplicateName => "Rule name already exists" ,
111- LexErrorKind :: RegexError => "Invalid regular expression" ,
138+ LexErrorKind :: RegexError ( e ) => return write ! ( f , "Invalid regular expression: {e}" ) ,
112139 } ;
113140 write ! ( f, "{s}" )
114141 }
0 commit comments