# HG changeset patch # User Michael Pavone # Date 1388365761 28800 # Node ID 8c16ef123aeebf17bf6245a935ec52d4aa329cf4 # Parent 6055f56d0e457c9226341f700b66c47d0dd75bd8 Implement list literals in grammar diff -r 6055f56d0e45 -r 8c16ef123aee modules/parser.tp --- a/modules/parser.tp Sun Dec 29 14:56:46 2013 -0800 +++ b/modules/parser.tp Sun Dec 29 17:09:21 2013 -0800 @@ -454,6 +454,9 @@ left <- Left op <- "|" right <- Right + string <- { + (string: left) . " " . op . " " . right + } } } addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv @@ -703,16 +706,20 @@ } } + unarymeth <- match: Receiver . hws . Method where: { + Receiver <- match: opexpr + Method <- match: symexpr + } yield: { + #{ + receiver <- Receiver + name <- Method name + args <- [] + } + } + methcall <- match: Receiver . hws . Rest where: { Receiver <- match: opexpr - Rest <- matchOne: [funcall ( - match: Name where: { Name <- match: symexpr } yield: { - #{ - name <- Name name - args <- [] - } - } - )] + Rest <- match: funcall } yield: { #{ receiver <- Receiver @@ -754,6 +761,17 @@ Expr <- matchOne: [ funcall methcall + unarymeth + opexpr + ] + } yield: { + Expr + } + + lexpr <- match: (hws . Expr . ws) where: { + Expr <- matchOne: [ + funcall + methcall opexpr ] } yield: { @@ -786,6 +804,23 @@ } } + listlit <- match: "[" . ws . Els . "]" where: { + Els <- zeroPlus: lexpr + } yield: { + //Handle limitation of zeroPlus macro + if: (Els length) = 0 { + Els <- [] + } + #{ + litval <- Els + string <- { + "[\n\t". ((litval map: :el { + string: el + }) join: "\n\t") . "\n]" + } + } + } + primlitsym <- match: hws . Lit where: { Lit <- matchOne: [ hexlit @@ -793,6 +828,7 @@ decimal symexpr object + listlit ] } yield: { Lit @@ -847,7 +883,7 @@ testmatchintlit: "0x20" :s {hexlit: s} testmatchintlit: "0x42u64" :s {hexlit: s} testmatchintlit: "0b10101" :s {binary: s} - code <- "#{ foo <- 123 > 0x42 && 42 < 104\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 quine <- 123 | [4 5 6 fiddle sticks]\n}" codem <- expr: code if: (codem matched?) { print: code . "\nmatched with yield:\n" . (codem yield) . "\n"