Mercurial > repos > tabletprog
comparison modules/ast.tp @ 247:b76f683d076e
Finish moving ast object definitions to a separate ast module
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 Jan 2014 19:27:19 -0800 |
parents | 8c81afd6d2d3 |
children | 004946743678 |
comparison
equal
deleted
inserted
replaced
246:8c81afd6d2d3 | 247:b76f683d076e |
---|---|
1 { | 1 { |
2 _binary <- 0 | 2 _binary <- 0 |
3 _string <- 1 | 3 _string <- 1 |
4 _int <- 2 | 4 _int <- 2 |
5 _symbol <- 3 | |
6 _call <- 4 | |
7 _object <- 5 | |
8 _sequence <- 6 | |
9 _assignment <- 7 | |
10 _lambda <- 8 | |
5 | 11 |
6 #{ | 12 #{ |
7 binary <- { _binary } | 13 binary <- { _binary } |
8 stringlit <- { _string } | 14 stringlit <- { _string } |
9 intlit <- { _int } | 15 intlit <- { _int } |
10 | 16 sym <- { _symbol } |
17 call <- { _call } | |
18 obj <- { _object } | |
19 sequence <- { _sequence } | |
20 assignment <- { _assignment } | |
21 lambda <- { _lambda } | |
11 | 22 |
12 binaryOp:withArgs <- :opname :_left _right { | 23 binaryOp:withArgs <- :opname :_left _right { |
13 #{ | 24 #{ |
14 nodeType <- { _binary } | 25 nodeType <- { _binary } |
15 left <- _left | 26 left <- _left |
78 string <- { | 89 string <- { |
79 stringIndent: "" | 90 stringIndent: "" |
80 } | 91 } |
81 } | 92 } |
82 } | 93 } |
94 | |
95 symbol <- :_name { | |
96 #{ | |
97 nodeType <- { _symbol } | |
98 name <- _name | |
99 stringIndent <- :indent { | |
100 name | |
101 } | |
102 string <- { | |
103 stringIndent: "" | |
104 } | |
105 } | |
106 } | |
107 | |
108 funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? { | |
109 #{ | |
110 tocall <- _tocall | |
111 args <- _args | |
112 hasReceiver? <- _receiver? | |
113 stringIndent <- :indent { | |
114 argparts <- [] | |
115 if: (tocall nodeType) = _symbol { | |
116 argparts <- (tocall name) splitOn: ":" | |
117 } else: { | |
118 argparts <- [tocall stringIndent: indent] | |
119 } | |
120 curarg <- args | |
121 str <- "" | |
122 if: hasReceiver? { | |
123 str <- ((curarg value) stringIndent: indent) . " " | |
124 curarg <- curarg tail | |
125 } | |
126 foreach: argparts :idx part { | |
127 str <- str . part . ":" | |
128 if: (not: (curarg empty?)) { | |
129 str <- str . " " . ((curarg value) stringIndent: indent) | |
130 curarg <- curarg tail | |
131 } | |
132 } | |
133 while: { not: (curarg empty?) } do: { | |
134 str <- str . " " . ((curarg value) stringIndent: indent) | |
135 curarg <- curarg tail | |
136 } | |
137 str | |
138 } | |
139 string <- { | |
140 stringIndent: "" | |
141 } | |
142 } | |
143 } | |
144 | |
145 object <- :_messages { | |
146 #{ | |
147 nodeType <- { _object } | |
148 messages <- _messages | |
149 stringIndent <- :indent { | |
150 nextindent <- "\t" . indent | |
151 (messages fold: "#{" with: :acc el { | |
152 acc . "\n" . nextindent . (el stringIndent: nextindent) | |
153 }) . "\n" . indent . "}" | |
154 } | |
155 string <- { | |
156 stringIndent: "" | |
157 } | |
158 } | |
159 } | |
160 | |
161 seqLit:array? <- :_els :_array? { | |
162 #{ | |
163 nodeType <- { _sequence } | |
164 els <- _els | |
165 array? <- _array? | |
166 stringIndent <- :indent { | |
167 nextIndent <- "\t" . indent | |
168 (els fold: (if: array? {"#["} else: {"["}) with: :acc el { | |
169 acc . "\n" . nextIndent . (el stringIndent: nextIndent) | |
170 }) . "\n" . indent . "]" | |
171 } | |
172 string <- { | |
173 stringIndent: "" | |
174 } | |
175 } | |
176 } | |
177 | |
178 assign:to <- :_expr :_sym { | |
179 #{ | |
180 nodeType <- { _assignment } | |
181 assign <- _expr | |
182 to <- _sym | |
183 stringIndent <- :indent { | |
184 (to stringIndent: indent) . " <- " . (assign stringIndent: indent) | |
185 } | |
186 string <- { | |
187 stringIndent: "" | |
188 } | |
189 } | |
190 } | |
191 | |
192 lambda:withArgs <- :_exprs :_args { | |
193 #{ | |
194 nodeType <- { _lambda } | |
195 args <- _args | |
196 expressions <- _exprs | |
197 stringIndent <- :indent { | |
198 argStr <- args join: " " | |
199 if: (argStr length) > 0 { | |
200 argStr <- argStr . " " | |
201 } | |
202 nextIndent <- "\t" . indent | |
203 (expressions fold: argStr . "{" with: :acc el { | |
204 acc . "\n" . nextIndent . (el stringIndent: nextIndent) | |
205 }) . "\n" . indent . "}" | |
206 } | |
207 string <- { | |
208 stringIndent: "" | |
209 } | |
210 } | |
211 } | |
83 } | 212 } |
84 } | 213 } |