Fixed
Raise syntax error rather than panicking on expected closing bracket.
* Fixed
@@ -54,6 +54,7 @@ pub struct Lexer<T: Iterator<Item = char>> {
#[derive(Debug)]
pub enum LexicalError {
StringError,
+ NestingError,
}
#[derive(Clone, Debug, Default, PartialEq)]
@@ -428,9 +429,7 @@ where
self.next_char();
loop {
match self.chr0 {
- Some('\n') => {
- return;
- }
+ Some('\n') => return,
Some(_) => {}
None => return,
}
@@ -904,6 +903,9 @@ where
}
Some(')') => {
let result = self.eat_single_char(Tok::Rpar);
+ if self.nesting == 0 {
+ return Some(Err(LexicalError::NestingError));
+ }
self.nesting -= 1;
return Some(result);
}
@@ -914,6 +916,9 @@ where
}
Some(']') => {
let result = self.eat_single_char(Tok::Rsqb);
+ if self.nesting == 0 {
+ return Some(Err(LexicalError::NestingError));
+ }
self.nesting -= 1;
return Some(result);
}
@@ -924,6 +929,9 @@ where
}
Some('}') => {
let result = self.eat_single_char(Tok::Rbrace);
+ if self.nesting == 0 {
+ return Some(Err(LexicalError::NestingError));
+ }
self.nesting -= 1;
return Some(result);
}
