message: Resolve "Out of bounds panics on map assignments"
diff: @@ -20,9 +20,16 @@ pub fn assignment_lexer(statement: &str) -> (Option<&str>, Option<Operator>, Opt
  let as_bytes = statement.as_bytes();
  let mut bytes = statement.bytes().peekable();
  let mut operator = None;
  + let mut delimiter_stack = Vec::new();
  while let Some(byte) = bytes.next() {
  operator = Some(Operator::Equal);
  +
  + if is_open_delimiter(byte) {
  + delimiter_stack.push(byte);
  + } else if delimiter_stack.last().map_or(false, |open| delimiters_match(*open, byte)) {
  + delimiter_stack.pop();
  + } else if delimiter_stack.is_empty() {
  if b'=' == byte {
  if bytes.peek().is_none() {
  return (Some(&statement[..read].trim()), Some(Operator::Equal), None);
  @@ -38,6 +45,7 @@ pub fn assignment_lexer(statement: &str) -> (Option<&str>, Option<Operator>, Opt
  read = found;
  break;
  }
  + }
  read += 1;
  }
  @@ -64,6 +72,15 @@ fn find_operator(bytes: &[u8], read: usize) -> Option<(Operator, usize)> {
  }
  }
  +fn is_open_delimiter(byte: u8) -> bool { byte == b'[' }
  +
  +fn delimiters_match(open: u8, close: u8) -> bool {
  + match (open, close) {
  + (b'[', b']') => true,
  + _ => false,
  + }
  +}
  +
  #[cfg(test)]
  mod tests {
  use super::*;
  @@ -159,4 +176,19 @@ mod tests {
  (Some("abc"), Some(Operator::Filter), Some("def"))
  )
  }
  +
  + #[test]
  + fn map_assignment() {
  + assert_eq!(assignment_lexer("abc[=]"), (Some("abc[=]"), None, None));
  +
  + assert_eq!(
  + assignment_lexer("abc['='] = '='"),
  + (Some("abc['=']"), Some(Operator::Equal), Some("'='"))
  + );
  +
  + assert_eq!(
  + assignment_lexer("abc[=] = []=[]"),
  + (Some("abc[=]"), Some(Operator::Equal), Some("[]=[]"))
  + );
  + }
  }
  