comparison modules/parser.tp @ 236:c463a891ccd3

Support reading files larger than 1024 bytes in parser module
author Michael Pavone <pavone@retrodev.com>
date Fri, 03 Jan 2014 22:13:34 -0800
parents cc1260872322
children dae093baf36c
comparison
equal deleted inserted replaced
235:cc1260872322 236:c463a891ccd3
968 testmatchintlit: "0x42u64" :s {hexlit: s} 968 testmatchintlit: "0x42u64" :s {hexlit: s}
969 testmatchintlit: "0b10101" :s {binary: s} 969 testmatchintlit: "0b10101" :s {binary: s}
970 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 }}" 970 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 }}"
971 if: (args length) > 1 { 971 if: (args length) > 1 {
972 file <- os open: (args get: 1) (os O_RDONLY) 972 file <- os open: (args get: 1) (os O_RDONLY)
973 code <- os read: file 1024 973 code <- ""
974 chunksize <- 1024
975 readsize <- chunksize
976 while: { readsize = chunksize} do: {
977 seg <- os read: file chunksize
978 code <- code . seg
979 readsize <- seg byte_length
980 }
974 } 981 }
975 codem <- top: code 982 codem <- top: code
976 if: (codem matched?) { 983 if: (codem matched?) {
977 print: code . "\nmatched with yield:\n" . (codem yield) . "\n" 984 print: code . "\nmatched with yield:\n" . (codem yield) . "\n"
978 } else: { 985 } else: {