brainfuck interpreter
brainfuck cli rust
5

Configure Feed

Select the types of activity you want to include in your feed.

feat: added positional context to bracket error variants

digi.rip (Jun 7, 2026, 1:22 PM EDT) 503b8dad 548bcabc

+13 -11
+13 -11
src/parser.rs
··· 3 3 4 4 #[derive(Debug)] 5 5 pub enum SyntaxError { 6 - MissingOpenBracket(usize), 7 - MissingClosingBracket(usize), 6 + MissingOpenBracket(usize, usize), 7 + MissingClosingBracket(usize, usize), 8 8 } 9 9 10 10 impl fmt::Display for SyntaxError { 11 11 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 12 12 match self { 13 - SyntaxError::MissingClosingBracket(pos) => { 14 - write!(f, "for open bracket at {:?}", pos) 13 + SyntaxError::MissingClosingBracket(line, col) => { 14 + write!(f, "for open bracket at line {:?}, col {:?}", line, col) 15 15 } 16 - SyntaxError::MissingOpenBracket(pos) => { 17 - write!(f, "for closing bracket at {:?}", pos) 16 + SyntaxError::MissingOpenBracket(line, col) => { 17 + write!(f, "for closing bracket at line {:?}, col {:?}", line, col) 18 18 } 19 19 } 20 20 } ··· 36 36 jump_map[pop] = pos; 37 37 } 38 38 None => { 39 - return Err(SyntaxError::MissingOpenBracket(pos)); 39 + return Err(SyntaxError::MissingOpenBracket(e.line, e.col)); 40 40 } 41 41 } 42 42 } 43 43 } 44 44 45 - if let Some(&pos) = balance.last() { 46 - return Err(SyntaxError::MissingClosingBracket(pos)); 45 + match balance.last() { 46 + Some(pos) => { 47 + let tok = &tokens[*pos]; 48 + return Err(SyntaxError::MissingClosingBracket(tok.line, tok.col)); 49 + } 50 + None => Ok(jump_map), 47 51 } 48 - 49 - Ok(jump_map) 50 52 } 51 53 52 54 #[cfg(test)]