10 ! |
10 ! |
11 |
11 |
12 !PPCSmalltalkNoopParser methodsFor:'accessing'! |
12 !PPCSmalltalkNoopParser methodsFor:'accessing'! |
13 |
13 |
14 startExpression |
14 startExpression |
15 "Make the sequence node has a method node as its parent and that the source is set." |
15 "Make the sequence node has a method node as its parent and that the source is set." |
16 |
16 |
17 ^ ([ :stream | stream collection ] asParser and , super startExpression) map: [ :source :node | |
17 ^ ([ :stream | stream collection ] asParser and , super startExpression) map: [ :source :node | |
18 (RBMethodNode selector: #doIt body: node) |
18 (RBMethodNode selector: #doIt body: node) |
19 source: source. |
19 source: source. |
20 (node statements size = 1 and: [ node temporaries isEmpty ]) |
20 (node statements size = 1 and: [ node temporaries isEmpty ]) |
21 ifTrue: [ node statements first ] |
21 ifTrue: [ node statements first ] |
22 ifFalse: [ node ] ] |
22 ifFalse: [ node ] ] |
23 ! |
23 ! |
24 |
24 |
25 startMethod |
25 startMethod |
26 "Make sure the method node has the source code properly set." |
26 "Make sure the method node has the source code properly set." |
27 |
27 |
28 ^ ([ :stream | stream collection ] asParser and , super startMethod) |
28 ^ ([ :stream | stream collection ] asParser and , super startMethod) |
29 map: [ :source :node | node source: source ] |
29 map: [ :source :node | node source: source ] |
30 ! ! |
30 ! ! |
31 |
31 |
32 !PPCSmalltalkNoopParser methodsFor:'grammar'! |
32 !PPCSmalltalkNoopParser methodsFor:'grammar'! |
33 |
33 |
34 array |
34 array |
211 ! ! |
211 ! ! |
212 |
212 |
213 !PPCSmalltalkNoopParser methodsFor:'private'! |
213 !PPCSmalltalkNoopParser methodsFor:'private'! |
214 |
214 |
215 addStatements: aCollection into: aNode |
215 addStatements: aCollection into: aNode |
216 aCollection isNil |
216 aCollection isNil |
217 ifTrue: [ ^ aNode ]. |
217 ifTrue: [ ^ aNode ]. |
218 aCollection do: [ :each | |
218 aCollection do: [ :each | |
219 each class == PPSmalltalkToken |
219 each class == PPSmalltalkToken |
220 ifFalse: [ aNode addNode: each ] |
220 ifFalse: [ aNode addNode: each ] |
221 ifTrue: [ |
221 ifTrue: [ |
222 aNode statements isEmpty |
222 aNode statements isEmpty |
223 ifTrue: [ aNode addComments: each comments ] |
223 ifTrue: [ aNode addComments: each comments ] |
224 ifFalse: [ aNode statements last addComments: each comments ]. |
224 ifFalse: [ aNode statements last addComments: each comments ]. |
225 aNode periods: (aNode periods asOrderedCollection |
225 aNode periods: (aNode periods asOrderedCollection |
226 addLast: each start; |
226 addLast: each start; |
227 yourself) ] ]. |
227 yourself) ] ]. |
228 ^ aNode |
228 ^ aNode |
229 ! |
229 ! |
230 |
230 |
231 build: aNode assignment: anArray |
231 build: aNode assignment: anArray |
232 ^ anArray isEmpty |
232 ^ anArray isEmpty |
233 ifTrue: [ aNode ] |
233 ifTrue: [ aNode ] |
234 ifFalse: [ |
234 ifFalse: [ |
235 anArray reverse |
235 anArray reverse |
236 inject: aNode |
236 inject: aNode |
237 into: [ :result :each | |
237 into: [ :result :each | |
238 RBAssignmentNode |
238 RBAssignmentNode |
239 variable: each first |
239 variable: each first |
240 value: result |
240 value: result |
241 position: each second start ] ] |
241 position: each second start ] ] |
242 ! |
242 ! |
243 |
243 |
244 build: aNode cascade: anArray |
244 build: aNode cascade: anArray |
245 | messages semicolons | |
245 | messages semicolons | |
246 ^ (anArray isNil or: [ anArray isEmpty ]) |
246 ^ (anArray isNil or: [ anArray isEmpty ]) |
247 ifTrue: [ aNode ] |
247 ifTrue: [ aNode ] |
248 ifFalse: [ |
248 ifFalse: [ |
249 messages := OrderedCollection new: anArray size + 1. |
249 messages := OrderedCollection new: anArray size + 1. |
250 messages addLast: aNode. |
250 messages addLast: aNode. |
251 semicolons := OrderedCollection new. |
251 semicolons := OrderedCollection new. |
252 anArray do: [ :each | |
252 anArray do: [ :each | |
253 messages addLast: (self |
253 messages addLast: (self |
254 build: aNode receiver |
254 build: aNode receiver |
255 messages: (Array with: each second)). |
255 messages: (Array with: each second)). |
256 semicolons addLast: each first start ]. |
256 semicolons addLast: each first start ]. |
257 RBCascadeNode messages: messages semicolons: semicolons ] |
257 RBCascadeNode messages: messages semicolons: semicolons ] |
258 ! |
258 ! |
259 |
259 |
260 build: aNode messages: anArray |
260 build: aNode messages: anArray |
261 ^ (anArray isNil or: [ anArray isEmpty ]) |
261 ^ (anArray isNil or: [ anArray isEmpty ]) |
262 ifTrue: [ aNode ] |
262 ifTrue: [ aNode ] |
263 ifFalse: [ |
263 ifFalse: [ |
264 anArray |
264 anArray |
265 inject: aNode |
265 inject: aNode |
266 into: [ :rec :msg | |
266 into: [ :rec :msg | |
267 msg isNil |
267 msg isNil |
268 ifTrue: [ rec ] |
268 ifTrue: [ rec ] |
269 ifFalse: [ |
269 ifFalse: [ |
270 RBMessageNode |
270 RBMessageNode |
271 receiver: rec |
271 receiver: rec |
272 selectorParts: msg first |
272 selectorParts: msg first |
273 arguments: msg second ] ] ] |
273 arguments: msg second ] ] ] |
274 ! |
274 ! |
275 |
275 |
276 build: aTempCollection sequence: aStatementCollection |
276 build: aTempCollection sequence: aStatementCollection |
277 | result | |
277 | result | |
278 result := self |
278 result := self |
279 addStatements: aStatementCollection |
279 addStatements: aStatementCollection |
280 into: RBSequenceNode new. |
280 into: RBSequenceNode new. |
281 aTempCollection isEmpty ifFalse: [ |
281 aTempCollection isEmpty ifFalse: [ |
282 result |
282 result |
283 leftBar: aTempCollection first start |
283 leftBar: aTempCollection first start |
284 temporaries: aTempCollection second |
284 temporaries: aTempCollection second |
285 rightBar: aTempCollection last start ]. |
285 rightBar: aTempCollection last start ]. |
286 ^ result |
286 ^ result |
287 ! |
287 ! |
288 |
288 |
289 buildArray: aStatementCollection |
289 buildArray: aStatementCollection |
290 ^ self addStatements: aStatementCollection into: RBArrayNode new |
290 ^ self addStatements: aStatementCollection into: RBArrayNode new |
291 ! |
291 ! |
292 |
292 |
293 buildMethod: aMethodNode |
293 buildMethod: aMethodNode |
294 aMethodNode selectorParts |
294 aMethodNode selectorParts |
295 do: [ :each | aMethodNode addComments: each comments ]. |
295 do: [ :each | aMethodNode addComments: each comments ]. |
296 aMethodNode arguments |
296 aMethodNode arguments |
297 do: [ :each | aMethodNode addComments: each token comments ]. |
297 do: [ :each | aMethodNode addComments: each token comments ]. |
298 aMethodNode pragmas do: [ :pragma | |
298 aMethodNode pragmas do: [ :pragma | |
299 aMethodNode addComments: pragma comments. |
299 aMethodNode addComments: pragma comments. |
300 pragma selectorParts |
300 pragma selectorParts |
301 do: [ :each | aMethodNode addComments: each comments ]. |
301 do: [ :each | aMethodNode addComments: each comments ]. |
302 pragma arguments do: [ :each | |
302 pragma arguments do: [ :each | |
303 each isLiteralArray |
303 each isLiteralArray |
304 ifFalse: [ aMethodNode addComments: each token comments ] ]. |
304 ifFalse: [ aMethodNode addComments: each token comments ] ]. |
305 pragma comments: nil ]. |
305 pragma comments: nil ]. |
306 ^ aMethodNode |
306 ^ aMethodNode |
307 ! |
307 ! |
308 |
308 |
309 buildString: aString |
309 buildString: aString |
310 (aString isEmpty or: [ aString first ~= $' or: [ aString last ~= $' ] ]) |
310 (aString isEmpty or: [ aString first ~= $' or: [ aString last ~= $' ] ]) |
311 ifTrue: [ ^ aString ]. |
311 ifTrue: [ ^ aString ]. |
312 ^ (aString |
312 ^ (aString |
313 copyFrom: 2 |
313 copyFrom: 2 |
314 to: aString size - 1) |
314 to: aString size - 1) |
315 copyReplaceAll: '''''' |
315 copyReplaceAll: '''''' |
316 with: '''' |
316 with: '''' |
317 ! ! |
317 ! ! |
318 |
318 |
319 !PPCSmalltalkNoopParser methodsFor:'token'! |
319 !PPCSmalltalkNoopParser methodsFor:'token'! |
320 |
320 |
321 binaryToken |
321 binaryToken |