# HG changeset patch # User Michael Pavone # Date 1388725450 28800 # Node ID 195f02ba349b2a72c2936e2744cad9c5c3f45786 # Parent 7435367a932ad308236f06adcf24d77090e9aa92 Implement lambdas in grammar. Make assignments an expression in grammar. diff -r 7435367a932a -r 195f02ba349b modules/parser.tp --- a/modules/parser.tp Thu Jan 02 21:02:11 2014 -0800 +++ b/modules/parser.tp Thu Jan 02 21:04:10 2014 -0800 @@ -427,8 +427,8 @@ quote: (match: Left . Pieces where: { Left <- match: higher Pieces <- zeroPlus: (match: hws . Op . Right where: { - Op <- matchOne: oplist - Right <- match: higher + Op <- matchOne: oplist + Right <- match: higher } yield: { #{ op <- Op @@ -762,6 +762,7 @@ funcall methcall unarymeth + assignment opexpr ] } yield: { @@ -838,12 +839,50 @@ } } + argname <- match: hws . Pre . Initial . Rest where: { + Pre <- matchOne: [":" ""] + Initial <- onePlus: (charClass: "a-zA-Z_!?@") + Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9") + } yield: { + Pre . Initial . Rest + } + + lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { + Arglist <- matchOne: [ + match: ":" . First . Rest where: { + First <- match: symexpr + Rest <- zeroPlus: argname + } yield: { + if: (Rest length) = 0 { + Rest <- [] + } + ":" . (First name) | Rest + } + match: "" yield: { [] } + ] + Exprs <- zeroPlus: expr + } yield: { + if: (Exprs length) = 0 { + Exprs <- [] + } + #{ + args <- Arglist + expressions <- Exprs + string <- { + (args join: " ") . "{\n\t" . + ((expressions map: :el { string: el }) join: "\n\t") . + "}" + } + } + } + primlitsym <- match: hws . Lit where: { Lit <- matchOne: [ hexlit binary decimal symexpr + lambda object listlit arraylit @@ -901,7 +940,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 quine <- 123 | [4 5 6 fiddle sticks]\nquizzle <- #[receiver meth: arg]}" + 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 quizzle <- #[receiver meth: arg]\n blah <- :arg arg2 :arg3 { arg + arg2 + arg3 }}" codem <- expr: code if: (codem matched?) { print: code . "\nmatched with yield:\n" . (codem yield) . "\n"