diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-07-22 20:28:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-07-22 20:28:51 -0700 |
commit | 050a93aca8840087b702dbd5b39565f56da00569 (patch) | |
tree | 1f4aa7d346f3af1ae7cc8df0b705ce859875d99c | |
parent | ae6d8f0335360886d79e6b0581e90bd0e0b2397d (diff) | |
download | mu-050a93aca8840087b702dbd5b39565f56da00569.tar.gz |
3131
Reorganize parser to make room for parsing pairs. But first test for pairs is still failing.
-rw-r--r-- | 067stream.mu | 14 | ||||
-rw-r--r-- | lambda-to-mu.mu | 45 |
2 files changed, 55 insertions, 4 deletions
diff --git a/067stream.mu b/067stream.mu index e55d5986..585878bc 100644 --- a/067stream.mu +++ b/067stream.mu @@ -23,11 +23,25 @@ def read in:address:stream -> result:character, in:address:stream [ load-ingredients idx:number <- get *in, index:offset s:address:array:character <- get *in, data:offset + len:number <- length *s + at-end?:boolean <- greater-or-equal idx len + reply-if at-end?, 0/nul, in result <- index *s, idx idx <- add idx, 1 *in <- put *in, index:offset, idx ] +def peek in:address:stream -> result:character [ + local-scope + load-ingredients + idx:number <- get *in, index:offset + s:address:array:character <- get *in, data:offset + len:number <- length *s + at-end?:boolean <- greater-or-equal idx len + reply-if at-end?, 0/nul + result <- index *s, idx +] + def read-line in:address:stream -> result:address:array:character, in:address:stream [ local-scope load-ingredients diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu index 8731f324..1c564db7 100644 --- a/lambda-to-mu.mu +++ b/lambda-to-mu.mu @@ -135,16 +135,33 @@ def parse in:address:array:character -> out:address:cell [ def parse in:address:stream -> out:address:cell, in:address:stream [ local-scope load-ingredients - b:address:buffer <- new-buffer 30 { done?:boolean <- end-of-stream? in break-if done? + c:character <- peek in + pair?:boolean <- equal c, 40/open-paren + { + break-if pair? + # atom + b:address:buffer <- new-buffer 30 + { + done?:boolean <- end-of-stream? in + break-if done? + c:character, in <- read in + b <- append b, c + loop + } + s:address:array:character <- buffer-to-array b + out <- new-atom s + } + { + break-unless pair? + # pair + out <- new-pair 0, 0 + } c:character, in <- read in - b <- append b, c loop } - s:address:array:character <- buffer-to-array b - out <- new-atom s ] scenario parse-single-letter-atom [ @@ -170,3 +187,23 @@ scenario parse-atom [ 11:array:character <- [abc] ] ] + +scenario parse-list [ + local-scope + s:address:array:character <- new [(abc def)] + x:address:cell <- parse s + p:pair, 10:boolean/raw <- maybe-convert *x, pair:variant + x1:address:cell <- get p, first:offset + x2:address:cell <- get p, rest:offset + s1:address:array:character, 11:boolean/raw <- maybe-convert *x1, atom:variant + s2:address:array:character, 12:boolean/raw <- maybe-convert *x2, atom:variant + 20:array:character/raw <- copy *s1 + 30:array:character/raw <- copy *s2 + memory-should-contain [ + 10 <- 1 # parse result is a pair + 11 <- 1 # result.first is an atom + 12 <- 1 # result.rest is an atom + 20:array:character <- [abc] # result.first + 30:array:character <- [def] # result.rest + ] +] |