Mercurial > repos > tabletprog
changeset 226:6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 29 Dec 2013 14:56:46 -0800 |
parents | 262f5ae1bb1b |
children | 8c16ef123aee |
files | modules/parser.tp |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/parser.tp Sun Dec 29 14:39:54 2013 -0800 +++ b/modules/parser.tp Sun Dec 29 14:56:46 2013 -0800 @@ -440,11 +440,27 @@ }) } + opexpr <- binaryOps: ["&&" "||"] withHigherPrec: compare + compare <- binaryOps: ["<=" ">=" "<" ">" "=" "!="] withHigherPrec: maybecons + maybecons <- matchOne: [ + consop + addsub + ] + consop <- match: Left . hws . "|" . Right where: { + Left <- match: addsub + Right <- match: maybecons + } yield: { + #{ + left <- Left + op <- "|" + right <- Right + } + } addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym //TODO: Implement operator expressions - opexpr <- match: addsub + _alpha <- charClass: "a-zA-Z" alpha <- zeroPlus: _alpha @@ -831,7 +847,7 @@ testmatchintlit: "0x20" :s {hexlit: s} testmatchintlit: "0x42u64" :s {hexlit: s} testmatchintlit: "0b10101" :s {binary: s} - code <- "#{ foo <- 123\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}" + code <- "#{ foo <- 123 > 0x42 && 42 < 104\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}" codem <- expr: code if: (codem matched?) { print: code . "\nmatched with yield:\n" . (codem yield) . "\n"