# Simplified grammar for testing LBox capabilities. # LBox can be used as the abstract syntax type, which effectively # allows attributes of different types to be associated with grammar symbols. !use rustlr::{lbup,lbdown,lbget,LBox}; !use crate::Expr::*; !use std::any::Any; ! !pub enum Expr { ! Var(String), ! Val(i32), ! Binop(&'static str,LBox,LBox), !} ! ! fn main() {} //just so it compiles ! absyntype LBox nonterminal E nonterminal ES mut terminals num var + ( ) ; topsym ES E --> E:a + E:b {parser.lba(Binop("+",lbdown!(a,Expr),lbdown!(b,Expr)))} E --> ( E:e ) {e} E --> num:n {parser.lba(Val(*lbdown!(n,i32)))} E --> var:v {parser.lba(Var(*lbget!(v,String)))} ES --> {parser.lba(Vec::>::new())} ES ==> ES:es E:e ; { let mut down = lbdown!(es,Vec>); down.push(lbdown!(e,Expr)); lbup!(down) } <== EOF parser.lba takes any expression and places it inside a LBox along with the line, column and source_id numbers that are current to the parser.