annotate modules/json.tp @ 263:98147071baf6

Add support for llMessage definitions in buildMethodTables
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Jul 2014 09:30:31 -0700
parents 9d8ae39e8e67
children bb4723fec05e
rev   line source
pavone@154 1 {
pavone@154 2 startArr <- "[" byte: 0
pavone@154 3 endArr <- "]" byte: 0
pavone@154 4 startObj <- "{" byte: 0
pavone@154 5 endObj <- "}" byte: 0
pavone@154 6 quote <- "\"" byte: 0
pavone@154 7 esc <- "\\" byte: 0
pavone@154 8 zero <- "0" byte: 0
pavone@154 9 nine <- "9" byte: 0
pavone@154 10 neg <- "-" byte: 0
pavone@154 11 space <- " " byte: 0
pavone@154 12 comma <- "," byte: 0
pavone@169 13 period <- "." byte: 0
pavone@167 14 tab <- " " byte: 0
pavone@166 15 nl <- "\n" byte: 0
pavone@166 16 cr <- "\r" byte: 0
pavone@154 17 colon <- ":" byte: 0
pavone@165 18 t <- "t" byte: 0
pavone@165 19 f <- "f" byte: 0
pavone@154 20
pavone@154 21 parseNumAt <- :str :at :recvResult {
pavone@154 22 num <- 0
pavone@154 23 l <- str length
pavone@154 24 minus <- false
pavone@154 25 aft <- -1
pavone@169 26 ignore <- false
pavone@154 27 while: { at < l } do: {
pavone@154 28 b <- str byte: at
pavone@154 29 if: b = neg {
pavone@154 30 minus <- true
pavone@154 31 } else: {
pavone@169 32 if: b = period {
pavone@169 33 ignore <- true
pavone@154 34 } else: {
pavone@169 35 if: b >= zero && b <= nine {
pavone@169 36 if: (not: ignore) {
pavone@169 37 num <- num * 10 + (str byte: at) - zero
pavone@169 38 }
pavone@169 39 } else: {
pavone@169 40 aft <- at
pavone@169 41 at <- l
pavone@169 42 }
pavone@154 43 }
pavone@154 44 }
pavone@154 45 at <- at + 1
pavone@154 46 }
pavone@154 47 if: aft < 0 {
pavone@154 48 aft <- at
pavone@154 49 }
pavone@154 50 if: minus {
pavone@154 51 num <- 0 - num
pavone@154 52 }
pavone@154 53 #{
pavone@154 54 value <- num
pavone@154 55 after <- aft
pavone@154 56 }
pavone@154 57 }
pavone@154 58
pavone@154 59 parseStrAt <- :src :at :recvResult {
pavone@154 60 //TODO: Deal with escaped characters
pavone@154 61 end <- src find: "\"" startingAt: at + 1 else: { src length }
pavone@154 62 #{
pavone@154 63 value <- src from: (at + 1) withLength: (end - at - 1)
pavone@154 64 after <- end + 1
pavone@154 65 }
pavone@154 66 }
pavone@154 67
pavone@154 68 _decode:at <- :text :cur {
pavone@154 69 ret <- false
pavone@154 70 b <- text byte: cur
pavone@154 71 if: b = neg || b >= zero && b <= nine {
pavone@154 72 text parseNumAt: cur
pavone@154 73 } else: {
pavone@154 74 if: b = quote {
pavone@154 75 text parseStrAt: cur
pavone@154 76 } else: {
pavone@154 77 if: b = startArr {
pavone@154 78 len <- text length
pavone@154 79 val <- #[]
pavone@154 80 cur <- cur + 1
pavone@154 81 aft <- -1
pavone@154 82 while: { cur < len } do: {
pavone@154 83 b <- text byte: cur
pavone@154 84 if: b = endArr {
pavone@154 85 aft <- cur + 1
pavone@154 86 cur <- len
pavone@154 87 } else: {
pavone@166 88 if: b = comma || b = space || b = tab || b = nl || b = cr {
pavone@154 89 cur <- cur + 1
pavone@154 90 } else: {
pavone@154 91 el <- _decode: text at: cur
pavone@154 92 cur <- el after
pavone@154 93 val append: (el value)
pavone@154 94 }
pavone@154 95 }
pavone@154 96 }
pavone@154 97 #{
pavone@154 98 value <- val
pavone@154 99 after <- aft
pavone@154 100 }
pavone@154 101 } else: {
pavone@154 102 if: b = startObj {
pavone@154 103 len <- text length
pavone@154 104 val <- dict linear
pavone@154 105 cur <- cur + 1
pavone@154 106 aft <- -1
pavone@154 107 expectKey <- true
pavone@154 108 key <- ""
pavone@154 109 while: { cur < len } do: {
pavone@154 110 b <- text byte: cur
pavone@166 111 if: b = comma || b = space || b = tab || b = colon || b = nl || b = cr {
pavone@154 112 cur <- cur + 1
pavone@154 113 } else: {
pavone@154 114 if: expectKey {
pavone@154 115 if: b = endObj {
pavone@154 116 aft <- cur + 1
pavone@154 117 cur <- len
pavone@154 118 } else: {
pavone@154 119 kd <- _decode: text at: cur
pavone@154 120 key <- kd value
pavone@154 121 cur <- kd after
pavone@167 122
pavone@154 123 expectKey <- false
pavone@154 124 }
pavone@154 125 } else: {
pavone@154 126 el <- _decode: text at: cur
pavone@154 127 val set: key (el value)
pavone@154 128 cur <- el after
pavone@154 129 expectKey <- true
pavone@154 130 }
pavone@154 131 }
pavone@154 132 }
pavone@154 133 #{
pavone@154 134 after <- aft
pavone@154 135 value <- val
pavone@154 136 }
pavone@154 137 } else: {
pavone@165 138 if: b = t && (text from: cur withLength: 4) = "true" {
pavone@165 139 #{
pavone@165 140 value <- true
pavone@165 141 after <- cur + 4
pavone@165 142 }
pavone@165 143 } else: {
pavone@165 144 if: b = f && (text from: cur withLength: 5) = "false" {
pavone@165 145 #{
pavone@165 146 value <- false
pavone@165 147 after <- cur + 5
pavone@165 148 }
pavone@165 149 } else: {
pavone@165 150 #{
pavone@165 151 value <- "foobar"
pavone@165 152 after <- (text length)
pavone@165 153 }
pavone@165 154 }
pavone@154 155 }
pavone@165 156
pavone@154 157 }
pavone@154 158 }
pavone@154 159 }
pavone@154 160 }
pavone@154 161 }
pavone@154 162 #{
pavone@154 163 decode <- :text {
pavone@154 164 (_decode: text at: 0) value
pavone@154 165 }
pavone@154 166 }
pavone@154 167 }