# HG changeset patch # User Michael Pavone # Date 1388731791 28800 # Node ID e48c74a7539eee68e46298630511463a058ba106 # Parent 195f02ba349b2a72c2936e2744cad9c5c3f45786 Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file. diff -r 195f02ba349b -r e48c74a7539e modules/parser.tp --- a/modules/parser.tp Thu Jan 02 21:04:10 2014 -0800 +++ b/modules/parser.tp Thu Jan 02 22:49:51 2014 -0800 @@ -492,10 +492,13 @@ string <- match: "\"" . Chars . "\"" where: { Chars <- zeroPlus: (matchOne: [ - (charClass: "^\"\\") + match: Reg where: { Reg <- charClass: "^\"\\" } yield: { Reg } escape ]) } yield: { + if: (Chars length) = 0 { + Chars <- [] + } Chars join: "" } @@ -876,6 +879,12 @@ } } + parenexp <- match: "(" . ws . Expr . ws . ")" where: { + Expr <- match: expr + } yield: { + Expr + } + primlitsym <- match: hws . Lit where: { Lit <- matchOne: [ hexlit @@ -886,11 +895,18 @@ object listlit arraylit + string + parenexp ] } yield: { Lit } + top <- matchOne: [ + object + lambda + ] + testmatchintlit <- :val matchfun { res <- matchfun: val if: (res matched?) { @@ -901,7 +917,7 @@ } } - main <- { + main <- :args { cmatch <- alpha: "czx0123" zeromatch <- alpha: "01234" if: (cmatch matched?) { @@ -941,7 +957,11 @@ 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]\n quizzle <- #[receiver meth: arg]\n blah <- :arg arg2 :arg3 { arg + arg2 + arg3 }}" - codem <- expr: code + if: (args length) > 1 { + file <- os open: (args get: 1) (os O_RDONLY) + code <- os read: file 1024 + } + codem <- top: code if: (codem matched?) { print: code . "\nmatched with yield:\n" . (codem yield) . "\n" } else: {