comparison modules/parser.tp @ 228:decdf28a8517

Implemented arrays in grammar
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 17:16:52 -0800
parents 8c16ef123aee
children 195f02ba349b
comparison
equal deleted inserted replaced
227:8c16ef123aee 228:decdf28a8517
819 }) join: "\n\t") . "\n]" 819 }) join: "\n\t") . "\n]"
820 } 820 }
821 } 821 }
822 } 822 }
823 823
824 arraylit <- match: "#[" . ws . Els . "]" where: {
825 Els <- zeroPlus: lexpr
826 } yield: {
827 //Handle limitation of zeroPlus macro
828 if: (Els length) = 0 {
829 Els <- []
830 }
831 #{
832 litval <- Els
833 string <- {
834 "#[\n\t". ((litval map: :el {
835 string: el
836 }) join: "\n\t") . "\n]"
837 }
838 }
839 }
840
824 primlitsym <- match: hws . Lit where: { 841 primlitsym <- match: hws . Lit where: {
825 Lit <- matchOne: [ 842 Lit <- matchOne: [
826 hexlit 843 hexlit
827 binary 844 binary
828 decimal 845 decimal
829 symexpr 846 symexpr
830 object 847 object
831 listlit 848 listlit
849 arraylit
832 ] 850 ]
833 } yield: { 851 } yield: {
834 Lit 852 Lit
835 } 853 }
836 854
881 testmatchintlit: "-567" :s {decimal: s} 899 testmatchintlit: "-567" :s {decimal: s}
882 testmatchintlit: "123u16" :s {decimal: s} 900 testmatchintlit: "123u16" :s {decimal: s}
883 testmatchintlit: "0x20" :s {hexlit: s} 901 testmatchintlit: "0x20" :s {hexlit: s}
884 testmatchintlit: "0x42u64" :s {hexlit: s} 902 testmatchintlit: "0x42u64" :s {hexlit: s}
885 testmatchintlit: "0b10101" :s {binary: s} 903 testmatchintlit: "0b10101" :s {binary: s}
886 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}" 904 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]}"
887 codem <- expr: code 905 codem <- expr: code
888 if: (codem matched?) { 906 if: (codem matched?) {
889 print: code . "\nmatched with yield:\n" . (codem yield) . "\n" 907 print: code . "\nmatched with yield:\n" . (codem yield) . "\n"
890 } else: { 908 } else: {
891 print: code . "\ndid not match\n" 909 print: code . "\ndid not match\n"