annotate src/requests.tp @ 22:a4837071b73d

some attempts at parsing an eval response
author William Morgan <bill@mrgn.org>
date Sat, 10 Aug 2013 03:31:50 -0700
parents a4ac42c69285
children fcd7ae66a9ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
1 #{
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
2
20
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
3 strJoin <- :str arr {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
4 acc <- ""
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
5 arr foreach: :i el {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
6 if: i = 0 {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
7 acc <- (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
8 } else: {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
9 acc <- acc . ", " . (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
10 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
11 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
12 acc
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
13 //arr fold: "" with: :acc el {acc . el}
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
14 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
15
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
16 quote <- :str {
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
17 "\"" . str . "\""
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
18 }
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
19
19
5a025e6c6f89 simple parallel requests limit test
William Morgan <bill@mrgn.org>
parents: 18
diff changeset
20 evalRequest <- :id args {
12
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
21 #{
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
22 string <- {
20
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
23 idStr <- (quote: "id") . ":" . (quote: id)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
24 argsStr <- (quote: "arguments") . ":" . (quote: (strJoin: "," args))
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
25 "{" . idStr . "," . argsStr . "}"
12
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
26 }
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
27 }
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
28 }
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
29
15
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
30 guessRequest <- :id :prog {
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
31 #{
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
32 string <- {
17
566960135ea1 Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
33 idStr <- "\"id\":\"" . id . "\""
566960135ea1 Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
34 progStr <- "\"program\":\"" . prog . "\""
566960135ea1 Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
35 "{" . idStr . "," . progStr . "}"
15
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
36 }
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
37 }
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
38 }
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
39
22
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
40
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
41
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
42
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
43
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
44
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
45 expect:in <- :target input {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
46 input find: target else: {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
47 print: "expected " . target . "!\n"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
48 -1
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
49 //exit, it's all fucked now
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
50 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
51 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
52
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
53 quotedVal <- :str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
54 str find: "\"" else: {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
55 "expected
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
56 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
57 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
58
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
59 jsonVal:in <- :target input {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
60 idx <- expect: target in: input
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
61 nextQuoteIdx <- idx +
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
62 quotedVal: idx
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
63 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
64
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
65 evalResponse <- :str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
66 str find: "status" else: {print: missing}
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
67 statIdx <- expect: "status" in: str
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
68 status <- requireK
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
69
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
70 #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
71 status <-
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
72 outputs <- parseArray(input)
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
73 message <-
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
74 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
75 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
76
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
77
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
78 println: str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
79 print: str . "\n"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
80 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
81
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
82 readObject <- :str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
83 expect "{"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
84 readObjectContents:
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
85 expect "}"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
86 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
87
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
88 readObject <- :str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
89 innerStr <- readEnclosed: "{" "}"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
90 elems <- split: ","
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
91 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
92
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
93 evalResponse <- :str {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
94 status <- readValForKey: "status" str
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
95 if status = "error" {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
96
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
97 } else {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
98 if status = "ok" {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
99 #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
100 readEvalOutputs:
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
101 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
102 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
103 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
104
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
105 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
106
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
107 expect:in:else <- :target src doElse {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
108 src find: target else: {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
109 print: "parse error: expected " . target . "!\n"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
110 doElse:
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
111 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
112 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
113
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
114 getStrForKey:from:else <- :key :src :doElse {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
115 idx <- expect: "\"" in: src else: doElse
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
116 idx + (key length):
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
117 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
118
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
119 getEval:else <- :str :fail {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
120 statusRest <- getStrForKey: "status" from: str else: fail
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
121 if (statusRest value) = 0 {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
122 outputsRest <- getOutputs: (statusRest rest) else: fail
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
123 #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
124 value <- #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
125 status <- statusRest.value
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
126 outputs <- outputsRest.value
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
127 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
128 rest <- outputsRest.rest
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
129 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
130 } else {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
131 print: "Status was error, message: " . message
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
132 #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
133 message <- getStrForKey: "message" from: (statusRest rest) else: fail
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
134 value <- #{
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
135 status <- statusRest.value
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
136 message <- outputsRest.value
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
137 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
138 rest <- outputsRest.rest
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
139 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
140 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
141 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
142
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
143
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
144
12
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
145 main <- {
20
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
146 print: ((evalRequest: "someId" #[1 2i64 3i64]) string) . "\n"
15
18ec9131f594 one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
147 print: ((guessRequest: "someId" "someProg") string) . "\n"
22
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
148
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
149 exampleEvalResponse <- "{\"status\":\"ok\",\"outputs\":[\"0x0000000000000002\",\"0x01DFFFFFFFFFFFFE\"]}"
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
150 resp <- getEval: exampleEvalResponse else: {
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
151 println: "failed to parse response."
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
152 }
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
153 println: ((resp value) status)
12
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
154 }
22
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
155
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
156 }