diff --git a/src/parser/stage/groupify.rs b/src/parser/stage/groupify.rs index 930909c..966bf3a 100644 --- a/src/parser/stage/groupify.rs +++ b/src/parser/stage/groupify.rs @@ -23,7 +23,10 @@ fn lookback_signs( => { if o == "-" { g.insert(i, Token::Operator(*l, String::from("neg"))); - } else if o == "+" { + } else if o == "+" && g.len() != 0 { + // Don't remove "+" if it's the only token, + // this is a syntax error that is caught later.e + continue; // We should not increment i if we remove a token } else {g.insert(i, a);} }, diff --git a/src/parser/stage/treeify.rs b/src/parser/stage/treeify.rs index 6d626c6..e988a9a 100644 --- a/src/parser/stage/treeify.rs +++ b/src/parser/stage/treeify.rs @@ -288,11 +288,16 @@ pub fn treeify( context: &Context ) -> Result { - let g_inner: &mut VecDeque = match g { - Token::Group(_, ref mut x) => x, + let (l, g_inner): (LineLocation, &mut VecDeque) = match g { + Token::Group(l, ref mut x) => (l, x), _ => panic!() }; + if g_inner.len() == 0 { + // This shouldn't ever happen. + return Err((l, ParserError::EmptyGroup)); + } + let mut left_associative = true; let mut j: i64 = 0; while g_inner.len() > 1 {