mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-31 07:21:04 +00:00
This fixes a problem in the newly added calculator7 test where error recovery would remove everything before the comma in `22 * 44 + 66, *3` as there would be no shift at that point. By first reducing the first expression the parser ends up in a state which properly has recovery installed and parsing can resume
39 lines
833 B
Rust
39 lines
833 B
Rust
use std::fmt::{Debug, Formatter, Error};
|
|
|
|
pub enum Expr {
|
|
Number(i32),
|
|
Op(Box<Expr>, Opcode, Box<Expr>),
|
|
Error,
|
|
}
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub enum Opcode {
|
|
Mul,
|
|
Div,
|
|
Add,
|
|
Sub,
|
|
}
|
|
|
|
impl Debug for Expr {
|
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
|
use self::Expr::*;
|
|
match *self {
|
|
Number(n) => write!(fmt, "{:?}", n),
|
|
Op(ref l, op, ref r) => write!(fmt, "({:?} {:?} {:?})", l, op, r),
|
|
Error => write!(fmt, "error"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Debug for Opcode {
|
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
|
use self::Opcode::*;
|
|
match *self {
|
|
Mul => write!(fmt, "*"),
|
|
Div => write!(fmt, "/"),
|
|
Add => write!(fmt, "+"),
|
|
Sub => write!(fmt, "-"),
|
|
}
|
|
}
|
|
}
|