@preprocessor typescript @{% import { Expr } from "./parsed"; %} expr -> term {% id %} term -> term _ "+" _ factor {% ([left, _0, _1, _2, right]): Expr => ({ exprType: "binary", binaryType: "add", left, right }) %} | term _ "-" _ factor {% ([left, _0, _1, _2, right]): Expr => ({ exprType: "binary", binaryType: "subtract", left, right }) %} | factor {% id %} factor -> factor _ "*" _ unary {% ([left, _0, _1, _2, right]): Expr => ({ exprType: "binary", binaryType: "multiply", left, right }) %} | factor _ "/" _ unary {% ([left, _0, _1, _2, right]): Expr => ({ exprType: "binary", binaryType: "divide", left, right }) %} | unary {% id %} unary -> "+" _ unary {% ([_0, _1, subject]): Expr => ({ exprType: "unary", unaryType: "plus", subject }) %} | "-" _ unary {% ([_0, _1, subject]): Expr => ({ exprType: "unary", unaryType: "negate", subject }) %} | operand {% id %} operand -> "(" _ expr _ ")" {% ([_0, _1, expr]): Expr => expr %} | [0-9]:+ {% ([token]): Expr => ({ exprType: "int", value: parseInt(token.join("")) }) %} _ -> __:? __ -> ws:+ ws -> [ \t\r\n]