88 actionArray at:($% asciiValue) put:[:s :char | s nextPrimitive]. |
91 actionArray at:($% asciiValue) put:[:s :char | s nextPrimitive]. |
89 actionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign] |
92 actionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign] |
90 ] |
93 ] |
91 ! |
94 ! |
92 |
95 |
|
96 initialize |
|
97 "prepare a scan" |
|
98 |
|
99 errorFlag := false. |
|
100 tokenLineNr := 1. |
|
101 currentComments := nil. |
|
102 saveComments := false. |
|
103 ! |
|
104 |
93 notifying:anObject |
105 notifying:anObject |
94 "set the requestor to be notified" |
106 "set the requestor to be notified" |
95 |
107 |
96 requestor := anObject |
108 requestor := anObject |
97 ! |
|
98 |
|
99 initialize |
|
100 "prepare a scan" |
|
101 |
|
102 errorFlag := false. |
|
103 tokenLineNr := 1 |
|
104 ! |
109 ! |
105 |
110 |
106 backupPosition |
111 backupPosition |
107 "if reading from a stream, at the end we might have read |
112 "if reading from a stream, at the end we might have read |
108 one token too many" |
113 one token too many" |
182 ^ self warning:aMessage position:tokenPosition |
187 ^ self warning:aMessage position:tokenPosition |
183 ! ! |
188 ! ! |
184 |
189 |
185 !Scanner methodsFor:'reading next token'! |
190 !Scanner methodsFor:'reading next token'! |
186 |
191 |
|
192 skipComment |
|
193 |comment| |
|
194 |
|
195 comment := ''. |
|
196 |
|
197 source next. |
|
198 thisChar := source peek. |
|
199 [thisChar notNil and:[thisChar ~~ (Character doubleQuote)]] whileTrue:[ |
|
200 thisChar == (Character cr) ifTrue:[ |
|
201 tokenLineNr := tokenLineNr + 1. |
|
202 ]. |
|
203 saveComments ifTrue:[ |
|
204 comment := comment copyWith:thisChar |
|
205 ]. |
|
206 source next. |
|
207 thisChar := source peek |
|
208 ]. |
|
209 saveComments ifTrue:[ |
|
210 currentComments isNil ifTrue:[ |
|
211 currentComments := OrderedCollection with:comment |
|
212 ] ifFalse:[ |
|
213 currentComments add:comment |
|
214 ] |
|
215 ]. |
|
216 "skip final dQuote" |
|
217 source next. |
|
218 ! |
|
219 |
187 nextToken |
220 nextToken |
188 "return the next token from the source-stream" |
221 "return the next token from the source-stream" |
189 |
222 |
190 |skipping actionBlock| |
223 |skipping actionBlock comment| |
191 |
224 |
192 peekChar notNil ifTrue:[ |
225 peekChar notNil ifTrue:[ |
193 thisChar := peekChar. |
226 thisChar := peekChar. |
194 peekChar := nil |
227 peekChar := nil |
195 ] ifFalse:[ |
228 ] ifFalse:[ |
199 thisChar == (Character cr) ifTrue:[ |
232 thisChar == (Character cr) ifTrue:[ |
200 tokenLineNr := tokenLineNr + 1. |
233 tokenLineNr := tokenLineNr + 1. |
201 source next |
234 source next |
202 ] ifFalse:[ |
235 ] ifFalse:[ |
203 thisChar == (Character doubleQuote) ifTrue:[ |
236 thisChar == (Character doubleQuote) ifTrue:[ |
204 source next. |
237 "start of a comment" |
|
238 |
|
239 self skipComment. |
205 thisChar := source peek. |
240 thisChar := source peek. |
206 [thisChar notNil and:[thisChar ~~ (Character doubleQuote)]] whileTrue:[ |
|
207 thisChar == (Character cr) ifTrue:[ |
|
208 tokenLineNr := tokenLineNr + 1. |
|
209 ]. |
|
210 source next. |
|
211 thisChar := source peek |
|
212 ]. |
|
213 source next. |
|
214 thisChar := source peek. |
|
215 " |
|
216 thisChar == (Character cr) ifTrue:[ |
|
217 tokenLineNr := tokenLineNr + 1. |
|
218 ]. |
|
219 " |
|
220 "thisChar := source skipFor:(Character doubleQuote) " |
|
221 ] ifFalse:[ |
241 ] ifFalse:[ |
222 skipping := false |
242 skipping := false |
223 ] |
243 ] |
224 ] |
244 ] |
225 ]. |
245 ]. |
343 nextChar := source nextPeek. |
363 nextChar := source nextPeek. |
344 (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[ |
364 (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[ |
345 value := value asFloat + (self nextMantissa:radix). |
365 value := value asFloat + (self nextMantissa:radix). |
346 nextChar := source peek |
366 nextChar := source peek |
347 ] ifFalse:[ |
367 ] ifFalse:[ |
|
368 nextChar == (Character cr) ifTrue:[ |
|
369 tokenLineNr := tokenLineNr + 1. |
|
370 ]. |
348 peekChar := $. |
371 peekChar := $. |
349 ] |
372 ] |
350 ]. |
373 ]. |
351 (nextChar == $e) ifTrue:[ |
374 (nextChar == $e) ifTrue:[ |
352 nextChar := source nextPeek. |
375 nextChar := source nextPeek. |
485 ! |
508 ! |
486 |
509 |
487 nextHash |
510 nextHash |
488 |nextChar string| |
511 |nextChar string| |
489 |
512 |
490 tokenType := #Symbol. |
|
491 nextChar := source nextPeek. |
513 nextChar := source nextPeek. |
492 nextChar notNil ifTrue:[ |
514 nextChar notNil ifTrue:[ |
493 nextChar isAlphaNumeric ifTrue:[ |
515 nextChar isAlphaNumeric ifTrue:[ |
494 string := ''. |
516 string := ''. |
495 [nextChar notNil and:[nextChar isAlphaNumeric]] whileTrue:[ |
517 [nextChar notNil and:[nextChar isAlphaNumeric]] whileTrue:[ |
496 string := string , (source nextWord "self nextId"). |
518 string := string , (source nextWord "self nextId"). |
497 nextChar := source peek. |
519 nextChar := source peek. |
498 (nextChar == $:) ifFalse:[ |
520 (nextChar == $:) ifFalse:[ |
499 tokenValue := string asSymbol. |
521 tokenValue := string asSymbol. |
500 ^ self |
522 tokenType := #Symbol. |
|
523 ^ tokenType |
501 ]. |
524 ]. |
502 string := string copyWith:nextChar. |
525 string := string copyWith:nextChar. |
503 nextChar := source nextPeek |
526 nextChar := source nextPeek |
504 ]. |
527 ]. |
505 tokenValue := string asSymbol. |
528 tokenValue := string asSymbol. |
|
529 tokenType := #Symbol. |
506 ^ tokenType |
530 ^ tokenType |
507 ]. |
531 ]. |
508 (nextChar == $( ) ifTrue:[ |
532 (nextChar == $( ) ifTrue:[ |
509 source next. |
533 source next. |
510 tokenType := #HashLeftParen. |
534 tokenType := #HashLeftParen. |
533 source next. |
557 source next. |
534 string := string copyWith:nextChar |
558 string := string copyWith:nextChar |
535 ] |
559 ] |
536 ]. |
560 ]. |
537 tokenValue := string asSymbol. |
561 tokenValue := string asSymbol. |
|
562 tokenType := #Symbol. |
538 ^ tokenType |
563 ^ tokenType |
539 ] |
564 ] |
540 ]. |
565 ]. |
|
566 "this allows hash to be used as binop - |
|
567 I dont know, if this is correct ..." |
|
568 |
|
569 tokenName := '#'. |
|
570 tokenType := BinaryOperator. |
|
571 ^ tokenType |
|
572 " |
541 self syntaxError:'unexpected end-of-input in Symbol' |
573 self syntaxError:'unexpected end-of-input in Symbol' |
542 position:tokenPosition to:(tokenPosition + 1). |
574 position:tokenPosition to:(tokenPosition + 1). |
543 ^ #Error |
575 ^ #Error |
|
576 " |
544 ! |
577 ! |
545 |
578 |
546 nextString |
579 nextString |
547 |nextChar string pos |
580 |nextChar string pos |
548 index "{ Class: SmallInteger }" |
581 index "{ Class: SmallInteger }" |