File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ pub struct Lexer<T: Iterator<Item = char>> {
54
54
#[ derive( Debug ) ]
55
55
pub enum LexicalError {
56
56
StringError ,
57
+ NestingError ,
57
58
}
58
59
59
60
#[ derive( Clone , Debug , Default , PartialEq ) ]
@@ -428,9 +429,7 @@ where
428
429
self . next_char ( ) ;
429
430
loop {
430
431
match self . chr0 {
431
- Some ( '\n' ) => {
432
- return ;
433
- }
432
+ Some ( '\n' ) => return ,
434
433
Some ( _) => { }
435
434
None => return ,
436
435
}
@@ -904,6 +903,9 @@ where
904
903
}
905
904
Some ( ')' ) => {
906
905
let result = self . eat_single_char ( Tok :: Rpar ) ;
906
+ if self . nesting == 0 {
907
+ return Some ( Err ( LexicalError :: NestingError ) ) ;
908
+ }
907
909
self . nesting -= 1 ;
908
910
return Some ( result) ;
909
911
}
@@ -914,6 +916,9 @@ where
914
916
}
915
917
Some ( ']' ) => {
916
918
let result = self . eat_single_char ( Tok :: Rsqb ) ;
919
+ if self . nesting == 0 {
920
+ return Some ( Err ( LexicalError :: NestingError ) ) ;
921
+ }
917
922
self . nesting -= 1 ;
918
923
return Some ( result) ;
919
924
}
@@ -924,6 +929,9 @@ where
924
929
}
925
930
Some ( '}' ) => {
926
931
let result = self . eat_single_char ( Tok :: Rbrace ) ;
932
+ if self . nesting == 0 {
933
+ return Some ( Err ( LexicalError :: NestingError ) ) ;
934
+ }
927
935
self . nesting -= 1 ;
928
936
return Some ( result) ;
929
937
}
You can’t perform that action at this time.
0 commit comments