@@ -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 ) ]
5050#[ non_exhaustive]
5151pub enum LexErrorKind {
5252 PrematureEnd ,
@@ -59,13 +59,37 @@ pub enum LexErrorKind {
5959 InvalidStartState ,
6060 InvalidStartStateName ,
6161 DuplicateName ,
62- RegexError ,
62+ RegexError ( regex :: Error ) ,
6363 InvalidGrmtoolsSectionValue ,
6464 InvalidNumber ,
6565 DuplicateGrmtoolsSectionValue ,
6666 VerbatimNotSupported ,
6767}
6868
69+ impl LexErrorKind {
70+ fn is_same_kind ( & self , other : & Self ) -> bool {
71+ use LexErrorKind as EK ;
72+ match ( self , other) {
73+ ( EK :: PrematureEnd , EK :: PrematureEnd )
74+ | ( EK :: RoutinesNotSupported , EK :: RoutinesNotSupported )
75+ | ( EK :: UnknownDeclaration , EK :: UnknownDeclaration )
76+ | ( EK :: MissingSpace , EK :: MissingSpace )
77+ | ( EK :: InvalidName , EK :: InvalidName )
78+ | ( EK :: UnknownStartState , EK :: UnknownStartState )
79+ | ( EK :: DuplicateStartState , EK :: DuplicateStartState )
80+ | ( EK :: InvalidStartState , EK :: InvalidStartState )
81+ | ( EK :: InvalidStartStateName , EK :: InvalidStartStateName )
82+ | ( EK :: DuplicateName , EK :: DuplicateName )
83+ | ( EK :: InvalidGrmtoolsSectionValue , EK :: InvalidGrmtoolsSectionValue )
84+ | ( EK :: InvalidNumber , EK :: InvalidNumber )
85+ | ( EK :: DuplicateGrmtoolsSectionValue , EK :: DuplicateGrmtoolsSectionValue )
86+ | ( EK :: RegexError ( _) , EK :: RegexError ( _) )
87+ | ( EK :: VerbatimNotSupported , EK :: VerbatimNotSupported ) => true ,
88+ _ => false ,
89+ }
90+ }
91+ }
92+
6993impl Spanned for LexBuildError {
7094 fn spans ( & self ) -> & [ Span ] {
7195 self . spans . as_slice ( )
@@ -84,7 +108,7 @@ impl Spanned for LexBuildError {
84108 | LexErrorKind :: InvalidGrmtoolsSectionValue
85109 | LexErrorKind :: InvalidNumber
86110 | LexErrorKind :: VerbatimNotSupported
87- | LexErrorKind :: RegexError => SpansKind :: Error ,
111+ | LexErrorKind :: RegexError ( _ ) => SpansKind :: Error ,
88112 LexErrorKind :: DuplicateName
89113 | LexErrorKind :: DuplicateStartState
90114 | LexErrorKind :: DuplicateGrmtoolsSectionValue => SpansKind :: DuplicationError ,
@@ -94,7 +118,7 @@ impl Spanned for LexBuildError {
94118
95119impl fmt:: Display for LexBuildError {
96120 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
97- let s = match self . kind {
121+ let s = match & self . kind {
98122 LexErrorKind :: VerbatimNotSupported => "Verbatim code not supported" ,
99123 LexErrorKind :: PrematureEnd => "File ends prematurely" ,
100124 LexErrorKind :: RoutinesNotSupported => "Routines not currently supported" ,
@@ -109,7 +133,7 @@ impl fmt::Display for LexBuildError {
109133 LexErrorKind :: InvalidNumber => "Invalid number" ,
110134 LexErrorKind :: DuplicateGrmtoolsSectionValue => "Duplicate grmtools section value" ,
111135 LexErrorKind :: DuplicateName => "Rule name already exists" ,
112- LexErrorKind :: RegexError => "Invalid regular expression" ,
136+ LexErrorKind :: RegexError ( e ) => return write ! ( f , "Invalid regular expression: {e}" ) ,
113137 } ;
114138 write ! ( f, "{s}" )
115139 }
0 commit comments