# HG changeset patch # User Michael Pavone # Date 1388356794 28800 # Node ID 262f5ae1bb1bdf70b615252788fa92a42568b3ec # Parent 97c3e33cd3f467f4a1962e7e1e123b248c38890a Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar diff -r 97c3e33cd3f4 -r 262f5ae1bb1b modules/parser.tp --- a/modules/parser.tp Sun Dec 29 14:38:56 2013 -0800 +++ b/modules/parser.tp Sun Dec 29 14:39:54 2013 -0800 @@ -423,6 +423,28 @@ } } + binaryOps:withHigherPrec <- macro: :oplist :higher { + quote: (match: Left . Pieces where: { + Left <- match: higher + Pieces <- zeroPlus: (match: hws . Op . Right where: { + Op <- matchOne: oplist + Right <- match: higher + } yield: { + #{ + op <- Op + right <- Right + } + }) + } yield: { + _processOpPieces: Left Pieces + }) + } + + addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv + muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym + + //TODO: Implement operator expressions + opexpr <- match: addsub _alpha <- charClass: "a-zA-Z" alpha <- zeroPlus: _alpha @@ -712,39 +734,6 @@ } } - addsub <- match: Left . Pieces where: { - Left <- match: muldiv - Pieces <- zeroPlus: (match: hws . Op . Right where: { - Op <- matchOne: ["+" "-" "."] - Right <- match: muldiv - } yield: { - #{ - op <- Op - right <- Right - } - }) - } yield: { - _processOpPieces: Left Pieces - } - - muldiv <- match: Left . Pieces where: { - Left <- match: primlitsym - Pieces <- zeroPlus: (match: hws . Op . Right where: { - Op <- matchOne: ["*" "/" "%"] - Right <- match: primlitsym - } yield: { - #{ - op <- Op - right <- Right - } - }) - } yield: { - _processOpPieces: Left Pieces - } - - //TODO: Implement operator expressions - opexpr <- match: addsub - expr <- match: (hws . Expr . ws) where: { Expr <- matchOne: [ funcall