author | Claus Gittinger <cg@exept.de> |
Sat, 02 May 2020 21:40:13 +0200 | |
changeset 5476 | 7355a4b11cb6 |
parent 2385 | bc283bcaac72 |
permissions | -rw-r--r-- |
2385 | 1 |
"{ Package: 'stx:libbasic2' }" |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
2 |
|
476 | 3 |
" |
4 |
COPYRIGHT (c) 1996 by eXept Software AG |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
5 |
All Rights Reserved |
476 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
14 |
||
15 |
||
16 |
||
171 | 17 |
ReadStream subclass:#TokenizedStream |
476 | 18 |
instanceVariableNames:'inputStream token tokenType tokenPosition tokenName tokenLineNr |
171 | 19 |
tokenValue tokenRadix hereChar peekChar peekChar2 |
20 |
beginCommentCharacter endCommentCharacter eolCommentCharacter |
|
173 | 21 |
eolCharacter outStream outCol actions types eolIsSignificant |
176 | 22 |
allowFloatNumbers numbersAreSigned' |
171 | 23 |
classVariableNames:'DefaultActions DefaultTypes' |
24 |
poolDictionaries:'' |
|
475 | 25 |
category:'Streams-Misc' |
171 | 26 |
! |
27 |
||
28 |
!TokenizedStream class methodsFor:'documentation'! |
|
29 |
||
476 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 1996 by eXept Software AG |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
33 |
All Rights Reserved |
476 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
||
44 |
! |
|
45 |
||
175 | 46 |
documentation |
47 |
" |
|
48 |
a first version of a tokenStream. |
|
2385 | 49 |
This is still being constructed and will probably be enhanced |
176 | 50 |
and may finally help a simplified Scanner class. |
51 |
||
175 | 52 |
For now, it may be useful when textual input files are to be read and |
53 |
parsed. For example, ascii data files are often in a simple free form format |
|
54 |
which requires some little processing. |
|
176 | 55 |
Dont blame me, if its not powerful enough for your needs. |
175 | 56 |
|
57 |
operation: |
|
58 |
||
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
59 |
characters are read from a real input stream |
2385 | 60 |
and the tokenizer dispatches to a token reading method by the help |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
61 |
of an actionTable, which is indexed by the tokenType. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
62 |
The tokenType itself is aquired via another table via |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
63 |
the characters ascii code. |
176 | 64 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
65 |
By default, the table is setup to only read numbers |
2385 | 66 |
and identifiers. |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
67 |
Whitespace is ignored, and all other characters return themself. |
175 | 68 |
|
176 | 69 |
The returned tokens are either symbols (#Identifier, #Integer ..) or |
175 | 70 |
characters ($+ $, etc.) |
176 | 71 |
If its #Identifier, the name is found in tokenName (there is an access method for that). |
72 |
If its #Integer or #Float, the value is found in tokenValue. |
|
175 | 73 |
|
176 | 74 |
EndOfLine is either ignored or returned as #EOL (if eolIsSignificant is true). |
75 |
End of input as #EOF. |
|
175 | 76 |
Unrecognized input leads to #Error to be returned. |
176 | 77 |
|
78 |
Customized tokenizers can be setup, by modifying the action- or typeTables. |
|
79 |
See examples for more. |
|
476 | 80 |
|
81 |
[author:] |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
82 |
Claus Gittinger |
476 | 83 |
|
84 |
[see also:] |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
85 |
ReadStream |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
86 |
Scanner |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
87 |
Tgen::* |
175 | 88 |
" |
89 |
! |
|
171 | 90 |
|
91 |
examples |
|
92 |
" |
|
476 | 93 |
simple example; tokenizing some string: |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
94 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
95 |
|s| |
171 | 96 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
97 |
s := TokenizedStream on:'hello world, how much is 3 + 2'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
98 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
99 |
Transcript showCR:(s next). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
100 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
101 |
[exEnd] |
171 | 102 |
|
103 |
||
476 | 104 |
simple example2; tokenizing and checking: |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
105 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
106 |
|s token| |
171 | 107 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
108 |
s := TokenizedStream on:'foo bar baz 3 + 2'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
109 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
110 |
token := s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
111 |
token == #Identifier ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
112 |
Transcript showCR:(token , ' name=' , s tokenName). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
113 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
114 |
token == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
115 |
Transcript showCR:(token , ' value=' , s tokenValue printString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
116 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
117 |
Transcript showCR:token. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
118 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
119 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
120 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
121 |
[exEnd] |
171 | 122 |
|
123 |
||
476 | 124 |
reading simple expressions: |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
125 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
126 |
|s num1 num2| |
171 | 127 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
128 |
s := TokenizedStream on:' |
171 | 129 |
3 + 2 |
130 |
4 + 6 |
|
131 |
1 + 2 |
|
132 |
'. |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
133 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
134 |
s next == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
135 |
num1 := s tokenValue. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
136 |
s next == $+ ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
137 |
s next == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
138 |
num2 := s tokenValue. |
2385 | 139 |
Transcript showCR:num1 printString |
140 |
, ' + ' |
|
141 |
, num2 printString |
|
142 |
, ' => ' |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
143 |
, (num1 + num2) printString. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
144 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
145 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
146 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
147 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
148 |
[exEnd] |
171 | 149 |
|
150 |
||
151 |
with eol-comments: |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
152 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
153 |
|s num1 num2| |
171 | 154 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
155 |
s := TokenizedStream on:' |
171 | 156 |
3 + 2 |
157 |
; this is a comment |
|
158 |
4 + 6 |
|
159 |
1 + 2 |
|
160 |
'. |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
161 |
s eolCommentCharacter:$;. |
171 | 162 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
163 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
164 |
s next == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
165 |
num1 := s tokenValue. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
166 |
s next == $+ ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
167 |
s next == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
168 |
num2 := s tokenValue. |
2385 | 169 |
Transcript showCR:num1 printString |
170 |
, ' + ' |
|
171 |
, num2 printString |
|
172 |
, ' => ' |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
173 |
, (num1 + num2) printString. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
174 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
175 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
176 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
177 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
178 |
[exEnd] |
476 | 179 |
|
171 | 180 |
|
176 | 181 |
allowing float & negative numbers (the default): |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
182 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
183 |
|s| |
173 | 184 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
185 |
s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
186 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
187 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
188 |
Transcript showCR:(s tokenType displayString, ' value=' , s tokenValue printString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
189 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
190 |
[exEnd] |
173 | 191 |
|
192 |
||
193 |
not allowing float numbers : |
|
476 | 194 |
(notice, how the floats is scanned) |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
195 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
196 |
|s| |
173 | 197 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
198 |
s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0 '. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
199 |
s allowFloatNumbers:false. |
173 | 200 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
201 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
202 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
203 |
Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
204 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
205 |
[exEnd] |
173 | 206 |
|
207 |
||
176 | 208 |
not allowing negative numbers : |
476 | 209 |
(notice, how the signs is scanned) |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
210 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
211 |
|s| |
176 | 212 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
213 |
s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
214 |
s numbersAreSigned:false. |
176 | 215 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
216 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
217 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
218 |
Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
219 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
220 |
[exEnd] |
176 | 221 |
|
222 |
||
173 | 223 |
no radix numbers (the default): |
476 | 224 |
(notice, how the integer is scanned) |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
225 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
226 |
|s| |
173 | 227 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
228 |
s := TokenizedStream on:'1234 0x1234 16r1234'. |
173 | 229 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
230 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
231 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
232 |
Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
233 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
234 |
[exEnd] |
173 | 235 |
|
236 |
||
237 |
C-style radix numbers: |
|
476 | 238 |
(notice, how the ST-style integer is scanned) |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
239 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
240 |
|s| |
173 | 241 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
242 |
s := TokenizedStream on:'0x1234 16r1234'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
243 |
s actionTable at:#digit put:[:s :char | s nextCNumber]. |
173 | 244 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
245 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
246 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
247 |
Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
248 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
249 |
[exEnd] |
173 | 250 |
|
251 |
||
252 |
smalltalk-style radix numbers: |
|
476 | 253 |
(notice, how the C-style integer is scanned) |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
254 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
255 |
|s| |
173 | 256 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
257 |
s := TokenizedStream on:'0x1234 16r1234'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
258 |
s actionTable at:#digit put:[:s :char | s nextSmalltalkNumber]. |
173 | 259 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
260 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
261 |
s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
262 |
Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
263 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
264 |
[exEnd] |
173 | 265 |
|
266 |
||
267 |
scan the '/etc/services' file: |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
268 |
[exBegin] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
269 |
|s t service port protocol| |
171 | 270 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
271 |
s := TokenizedStream on:'/etc/services' asFilename readStream. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
272 |
s eolCommentCharacter:$#. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
273 |
s typeTable at:($- asciiValue) put:#letter. |
171 | 274 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
275 |
[s atEnd] whileFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
276 |
t := s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
277 |
t == #Identifier ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
278 |
service := s tokenName. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
279 |
t := s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
280 |
t == #Integer ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
281 |
port := s tokenValue. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
282 |
s next == $/ ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
283 |
t := s next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
284 |
t == #Identifier ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
285 |
protocol := s tokenName. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
286 |
Transcript showCR:('servive: ' , service , ' is ' , protocol , ' port=' , port printString). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
287 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
288 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
289 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
290 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
291 |
s skipToEol |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
292 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
293 |
[exEnd] |
171 | 294 |
" |
295 |
! ! |
|
296 |
||
297 |
!TokenizedStream class methodsFor:'initialization'! |
|
298 |
||
299 |
initialize |
|
173 | 300 |
DefaultActions := IdentityDictionary new. |
171 | 301 |
DefaultTypes := Array new:256. |
302 |
||
303 |
"kludge: action is nextColonOrAssign, but type is special" |
|
304 |
2 to:255 do:[:code | |
|
177 | 305 |
DefaultTypes at:code put:(Character value:code). |
171 | 306 |
]. |
307 |
||
308 |
($0 asciiValue) to:($9 asciiValue) do:[:index | |
|
177 | 309 |
DefaultTypes at:index put:#digit. |
171 | 310 |
]. |
311 |
||
312 |
($a asciiValue) to:($z asciiValue) do:[:index | |
|
177 | 313 |
DefaultTypes at:index put:#letter. |
171 | 314 |
]. |
315 |
($A asciiValue) to:($Z asciiValue) do:[:index | |
|
177 | 316 |
DefaultTypes at:index put:#letter. |
171 | 317 |
]. |
318 |
||
173 | 319 |
DefaultActions at:#letter put:[:s :char | s nextIdentifier]. |
320 |
DefaultActions at:#digit put:[:s :char | s nextNumber]. |
|
177 | 321 |
DefaultActions at:$- put:[:s :char | s nextSignedNumber]. |
173 | 322 |
|
171 | 323 |
" |
324 |
TokenizedStream initialize |
|
325 |
" |
|
326 |
! ! |
|
327 |
||
328 |
!TokenizedStream class methodsFor:'instance creation'! |
|
329 |
||
476 | 330 |
new |
331 |
^ self basicNew initialize |
|
332 |
||
333 |
"Modified: 11.1.1997 / 19:18:48 / cg" |
|
334 |
"Created: 11.1.1997 / 19:22:40 / cg" |
|
335 |
! |
|
336 |
||
175 | 337 |
on:aStream |
476 | 338 |
^ self readingFrom:(aStream readStream) |
339 |
||
340 |
"Modified: 11.1.1997 / 19:23:49 / cg" |
|
341 |
! |
|
342 |
||
343 |
readingFrom:aStream |
|
344 |
^ self new inputStream:aStream |
|
345 |
||
346 |
"Created: 11.1.1997 / 19:18:58 / cg" |
|
347 |
"Modified: 11.1.1997 / 19:23:17 / cg" |
|
171 | 348 |
! ! |
349 |
||
350 |
!TokenizedStream methodsFor:'accessing'! |
|
351 |
||
175 | 352 |
actionTable |
353 |
^ actions |
|
354 |
||
355 |
"Created: 1.2.1996 / 17:42:00 / cg" |
|
171 | 356 |
! |
357 |
||
173 | 358 |
allowFloatNumbers:aBoolean |
359 |
"if false, floating numbers are not read; a period is returned as |
|
360 |
a separate token. If true (the default), floating point numbers are allowed." |
|
361 |
||
362 |
allowFloatNumbers := aBoolean |
|
363 |
||
364 |
"Modified: 1.2.1996 / 18:14:27 / cg" |
|
365 |
"Created: 1.2.1996 / 18:27:41 / cg" |
|
366 |
! |
|
367 |
||
175 | 368 |
beginCommentCharacter:aCharacter |
369 |
beginCommentCharacter := aCharacter |
|
370 |
||
371 |
"Created: 1.2.1996 / 17:38:01 / cg" |
|
171 | 372 |
! |
373 |
||
175 | 374 |
endCommentCharacter:aCharacter |
375 |
endCommentCharacter := aCharacter |
|
376 |
||
377 |
"Created: 1.2.1996 / 17:38:06 / cg" |
|
171 | 378 |
! |
379 |
||
175 | 380 |
eolCommentCharacter:aCharacter |
381 |
eolCommentCharacter := aCharacter |
|
171 | 382 |
|
175 | 383 |
"Created: 1.2.1996 / 17:37:51 / cg" |
171 | 384 |
! |
385 |
||
175 | 386 |
eolIsSignificant:aBoolean |
387 |
"if false, EOL is treated like whiteSpace (the default); |
|
388 |
Otherwise, a #EOL token is returned" |
|
172 | 389 |
|
175 | 390 |
eolIsSignificant := aBoolean |
172 | 391 |
|
175 | 392 |
"Created: 1.2.1996 / 17:37:51 / cg" |
393 |
"Modified: 1.2.1996 / 18:14:27 / cg" |
|
394 |
! |
|
172 | 395 |
|
176 | 396 |
numbersAreSigned:aBoolean |
397 |
"if false, minus signs preceeding numbers are ignored. |
|
398 |
if true (the default) they are recognized" |
|
399 |
||
400 |
numbersAreSigned := aBoolean |
|
401 |
||
402 |
"Modified: 1.2.1996 / 18:14:27 / cg" |
|
403 |
"Created: 1.2.1996 / 18:56:34 / cg" |
|
404 |
! |
|
405 |
||
175 | 406 |
tokenName |
407 |
^ tokenName |
|
171 | 408 |
|
175 | 409 |
"Created: 1.2.1996 / 17:46:48 / cg" |
171 | 410 |
! |
411 |
||
175 | 412 |
tokenType |
413 |
^ tokenType |
|
171 | 414 |
|
175 | 415 |
"Created: 1.2.1996 / 17:26:24 / cg" |
171 | 416 |
! |
417 |
||
175 | 418 |
tokenValue |
419 |
^ tokenValue |
|
171 | 420 |
|
175 | 421 |
"Created: 1.2.1996 / 17:26:30 / cg" |
422 |
! |
|
171 | 423 |
|
175 | 424 |
typeTable |
425 |
^ types |
|
171 | 426 |
|
175 | 427 |
"Created: 1.2.1996 / 17:41:54 / cg" |
171 | 428 |
! ! |
429 |
||
430 |
!TokenizedStream methodsFor:'initialization'! |
|
431 |
||
432 |
initialize |
|
433 |
tokenLineNr := 1. |
|
476 | 434 |
|
171 | 435 |
eolCommentCharacter := beginCommentCharacter := endCommentCharacter := nil. |
436 |
eolCharacter := Character cr. |
|
437 |
eolIsSignificant := false. |
|
438 |
||
173 | 439 |
actions := DefaultActions shallowCopy. |
440 |
types := DefaultTypes shallowCopy. |
|
441 |
allowFloatNumbers := true. |
|
176 | 442 |
numbersAreSigned := true. |
171 | 443 |
|
476 | 444 |
"Modified: 11.1.1997 / 19:25:49 / cg" |
445 |
! |
|
446 |
||
447 |
inputStream:aStream |
|
448 |
inputStream := aStream |
|
449 |
||
450 |
"Created: 11.1.1997 / 19:25:41 / cg" |
|
171 | 451 |
! ! |
452 |
||
453 |
!TokenizedStream methodsFor:'private'! |
|
454 |
||
476 | 455 |
on:aStream |
175 | 456 |
self initialize. |
171 | 457 |
|
476 | 458 |
inputStream := aStream. |
175 | 459 |
|
476 | 460 |
"Modified: 11.1.1997 / 19:22:10 / cg" |
171 | 461 |
! ! |
462 |
||
463 |
!TokenizedStream methodsFor:'reading'! |
|
464 |
||
175 | 465 |
next |
466 |
^ self nextToken |
|
171 | 467 |
|
175 | 468 |
"Created: 1.2.1996 / 17:21:47 / cg" |
171 | 469 |
! |
470 |
||
173 | 471 |
nextCNumber |
472 |
|nextChar value s| |
|
473 |
||
474 |
tokenRadix := 10. |
|
476 | 475 |
inputStream peek == $0 ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
476 |
inputStream next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
477 |
inputStream peek == $x ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
478 |
inputStream next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
479 |
tokenRadix := 16. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
480 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
481 |
tokenRadix := 8 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
482 |
] |
173 | 483 |
]. |
484 |
||
476 | 485 |
value := Integer readFrom:inputStream radix:tokenRadix. |
486 |
nextChar := inputStream peek. |
|
173 | 487 |
|
488 |
(allowFloatNumbers and:[tokenRadix == 10]) ifTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
489 |
(nextChar == $.) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
490 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
491 |
(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
492 |
value := value asFloat + (self nextMantissa:tokenRadix). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
493 |
nextChar := inputStream peek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
494 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
495 |
nextChar == (Character cr) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
496 |
tokenLineNr := tokenLineNr + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
497 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
498 |
peekChar := $. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
499 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
500 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
501 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
502 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
503 |
(nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
504 |
s := 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
505 |
(nextChar == $+) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
506 |
nextChar := inputStream nextPeek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
507 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
508 |
(nextChar == $-) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
509 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
510 |
s := s negated |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
511 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
512 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
513 |
value := value asFloat |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
514 |
* (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s)) |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
515 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
516 |
]. |
173 | 517 |
]. |
518 |
tokenValue := value. |
|
519 |
(value isMemberOf:Float) ifTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
520 |
tokenType := #Float |
173 | 521 |
] ifFalse:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
522 |
tokenType := #Integer |
173 | 523 |
]. |
524 |
^ tokenType |
|
525 |
||
526 |
"Created: 1.2.1996 / 18:26:27 / cg" |
|
476 | 527 |
"Modified: 11.1.1997 / 19:24:19 / cg" |
173 | 528 |
! |
529 |
||
175 | 530 |
nextIdentifier |
2385 | 531 |
|nextChar string oldString |
175 | 532 |
index "{ Class: SmallInteger }" |
2385 | 533 |
max "{ Class: SmallInteger }" |
175 | 534 |
t done| |
535 |
||
476 | 536 |
nextChar := inputStream peek. |
175 | 537 |
string := String basicNew:20. |
538 |
index := 0. |
|
539 |
max := 10. |
|
171 | 540 |
|
175 | 541 |
done := false. |
542 |
[done] whileFalse:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
543 |
nextChar isNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
544 |
done := true |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
545 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
546 |
t := types at:(nextChar asciiValue). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
547 |
done := (t ~~ #letter and:[t ~~ #digit]). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
548 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
549 |
done ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
550 |
(index == max) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
551 |
oldString := string. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
552 |
string := String basicNew:(max * 2). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
553 |
string replaceFrom:1 to:max with:oldString. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
554 |
max := max * 2 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
555 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
556 |
index := index + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
557 |
string at:index put:nextChar. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
558 |
nextChar := inputStream nextPeek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
559 |
] |
175 | 560 |
]. |
561 |
tokenType := #Identifier. |
|
562 |
tokenName := string copyTo:index. |
|
563 |
^ tokenType |
|
171 | 564 |
|
175 | 565 |
"Created: 1.2.1996 / 16:35:53 / cg" |
476 | 566 |
"Modified: 11.1.1997 / 19:24:25 / cg" |
171 | 567 |
! |
568 |
||
175 | 569 |
nextInteger |
476 | 570 |
tokenValue := Integer readFrom:inputStream radix:10. |
175 | 571 |
tokenRadix := 10. |
572 |
tokenType := #Integer. |
|
573 |
^ tokenType |
|
171 | 574 |
|
175 | 575 |
"Created: 1.2.1996 / 16:37:03 / cg" |
476 | 576 |
"Modified: 11.1.1997 / 19:24:27 / cg" |
171 | 577 |
! |
578 |
||
173 | 579 |
nextMantissa:radix |
580 |
|nextChar value factor| |
|
581 |
||
582 |
value := 0. |
|
583 |
factor := 1.0 / radix. |
|
476 | 584 |
nextChar := inputStream peek. |
173 | 585 |
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
586 |
value := value + (nextChar digitValue * factor). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
587 |
factor := factor / radix. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
588 |
nextChar := inputStream nextPeek |
173 | 589 |
]. |
590 |
^ value |
|
591 |
||
592 |
"Created: 1.2.1996 / 18:31:38 / cg" |
|
476 | 593 |
"Modified: 11.1.1997 / 19:24:30 / cg" |
173 | 594 |
! |
595 |
||
596 |
nextNumber |
|
597 |
|nextChar value s| |
|
598 |
||
599 |
tokenRadix := 10. |
|
476 | 600 |
value := Integer readFrom:inputStream radix:tokenRadix. |
601 |
nextChar := inputStream peek. |
|
173 | 602 |
allowFloatNumbers ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
603 |
(nextChar == $.) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
604 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
605 |
(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
606 |
value := value asFloat + (self nextMantissa:tokenRadix). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
607 |
nextChar := inputStream peek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
608 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
609 |
nextChar == (Character cr) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
610 |
tokenLineNr := tokenLineNr + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
611 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
612 |
peekChar := $. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
613 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
614 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
615 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
616 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
617 |
(nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
618 |
s := 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
619 |
(nextChar == $+) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
620 |
nextChar := inputStream nextPeek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
621 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
622 |
(nextChar == $-) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
623 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
624 |
s := s negated |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
625 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
626 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
627 |
value := value asFloat |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
628 |
* (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s)) |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
629 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
630 |
]. |
173 | 631 |
]. |
632 |
tokenValue := value. |
|
633 |
(value isMemberOf:Float) ifTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
634 |
tokenType := #Float |
173 | 635 |
] ifFalse:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
636 |
tokenType := #Integer |
173 | 637 |
]. |
638 |
^ tokenType |
|
639 |
||
640 |
"Created: 1.2.1996 / 18:31:03 / cg" |
|
476 | 641 |
"Modified: 11.1.1997 / 19:24:34 / cg" |
173 | 642 |
! |
643 |
||
475 | 644 |
nextSignedNumber |
645 |
|next| |
|
646 |
||
476 | 647 |
inputStream next. |
475 | 648 |
numbersAreSigned ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
649 |
next := inputStream peek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
650 |
(next notNil and:[(types at:next asciiValue) == #digit]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
651 |
(actions at:#digit) value:self value:next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
652 |
tokenValue := tokenValue negated. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
653 |
] |
475 | 654 |
]. |
655 |
^ tokenType |
|
656 |
||
476 | 657 |
"Modified: 11.1.1997 / 19:24:40 / cg" |
475 | 658 |
! |
659 |
||
173 | 660 |
nextSmalltalkNumber |
661 |
|nextChar value s| |
|
662 |
||
663 |
tokenRadix := 10. |
|
476 | 664 |
value := Integer readFrom:inputStream radix:tokenRadix. |
665 |
nextChar := inputStream peek. |
|
173 | 666 |
(nextChar == $r) ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
667 |
tokenRadix := value. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
668 |
inputStream next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
669 |
s := 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
670 |
inputStream peek == $- ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
671 |
inputStream next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
672 |
s := -1 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
673 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
674 |
value := Integer readFrom:inputStream radix:tokenRadix. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
675 |
value := value * s. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
676 |
nextChar := inputStream peek |
173 | 677 |
]. |
678 |
allowFloatNumbers ifTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
679 |
(nextChar == $.) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
680 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
681 |
(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
682 |
value := value asFloat + (self nextMantissa:tokenRadix). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
683 |
nextChar := inputStream peek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
684 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
685 |
nextChar == (Character cr) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
686 |
tokenLineNr := tokenLineNr + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
687 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
688 |
peekChar := $. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
689 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
690 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
691 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
692 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
693 |
(nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
694 |
s := 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
695 |
(nextChar == $+) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
696 |
nextChar := inputStream nextPeek |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
697 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
698 |
(nextChar == $-) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
699 |
nextChar := inputStream nextPeek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
700 |
s := s negated |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
701 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
702 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
703 |
value := value asFloat |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
704 |
* (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s)) |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
705 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
706 |
]. |
173 | 707 |
]. |
708 |
tokenValue := value. |
|
709 |
(value isMemberOf:Float) ifTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
710 |
tokenType := #Float |
173 | 711 |
] ifFalse:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
712 |
tokenType := #Integer |
173 | 713 |
]. |
714 |
^ tokenType |
|
715 |
||
716 |
"Created: 1.2.1996 / 18:19:05 / cg" |
|
476 | 717 |
"Modified: 11.1.1997 / 19:24:49 / cg" |
173 | 718 |
! |
719 |
||
175 | 720 |
nextString:separator |
721 |
|nextChar string pos |
|
722 |
index "{ Class: SmallInteger }" |
|
723 |
len "{ Class: SmallInteger }" |
|
724 |
inString| |
|
725 |
||
726 |
string := String basicNew:20. |
|
727 |
len := 20. |
|
728 |
index := 1. |
|
476 | 729 |
pos := inputStream position. |
730 |
inputStream next. |
|
731 |
nextChar := inputStream next. |
|
175 | 732 |
inString := true. |
171 | 733 |
|
175 | 734 |
[inString] whileTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
735 |
nextChar isNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
736 |
self error:'unexpected end-of-input in String'. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
737 |
tokenType := #EOF. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
738 |
^ tokenType |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
739 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
740 |
(nextChar == Character cr) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
741 |
tokenLineNr := tokenLineNr + 1 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
742 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
743 |
(nextChar == separator) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
744 |
(inputStream peek == separator) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
745 |
inputStream next |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
746 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
747 |
inString := false |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
748 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
749 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
750 |
inString ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
751 |
string at:index put:nextChar. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
752 |
(index == len) ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
753 |
string := string , (String new:len). |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
754 |
len := len * 2 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
755 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
756 |
index := index + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
757 |
nextChar := inputStream next |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
758 |
] |
175 | 759 |
]. |
760 |
tokenValue := string copyTo:(index - 1). |
|
761 |
tokenType := #String. |
|
762 |
^ tokenType |
|
171 | 763 |
|
175 | 764 |
"Created: 1.2.1996 / 16:39:48 / cg" |
476 | 765 |
"Modified: 11.1.1997 / 19:24:53 / cg" |
171 | 766 |
! |
767 |
||
768 |
nextToken |
|
476 | 769 |
"return the next token from the inputStream-stream" |
171 | 770 |
|
771 |
|skipping actionBlock| |
|
772 |
||
173 | 773 |
tokenValue := tokenName := nil. |
774 |
||
171 | 775 |
peekChar notNil ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
776 |
hereChar := peekChar. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
777 |
peekChar := peekChar2. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
778 |
peekChar2 := nil |
171 | 779 |
] ifFalse:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
780 |
skipping := true. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
781 |
[skipping] whileTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
782 |
outStream notNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
783 |
[(hereChar := inputStream peek) == Character space] whileTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
784 |
inputStream next. |
2385 | 785 |
outStream space. |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
786 |
outCol := outCol + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
787 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
788 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
789 |
hereChar := inputStream skipSeparatorsExceptCR. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
790 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
791 |
hereChar isNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
792 |
tokenType := #EOF. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
793 |
^ tokenType |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
794 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
795 |
hereChar == eolCharacter ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
796 |
tokenLineNr := tokenLineNr + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
797 |
inputStream next. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
798 |
outStream notNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
799 |
outStream cr. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
800 |
outCol := 1 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
801 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
802 |
eolIsSignificant ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
803 |
tokenType := #EOL. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
804 |
^ tokenType |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
805 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
806 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
807 |
hereChar == beginCommentCharacter ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
808 |
"start of a comment" |
171 | 809 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
810 |
self skipComment. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
811 |
hereChar := inputStream peek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
812 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
813 |
hereChar == eolCommentCharacter ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
814 |
"start of an eol comment" |
171 | 815 |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
816 |
self skipEolComment. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
817 |
hereChar := inputStream peek. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
818 |
] ifFalse:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
819 |
skipping := false |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
820 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
821 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
822 |
] |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
823 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
824 |
hereChar isNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
825 |
tokenType := #EOF. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
826 |
^ tokenType |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
827 |
] |
171 | 828 |
]. |
476 | 829 |
tokenPosition := inputStream position. |
171 | 830 |
|
173 | 831 |
types notNil ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
832 |
tokenType := types at:(hereChar asciiValue). |
173 | 833 |
]. |
834 |
||
171 | 835 |
actions notNil ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
836 |
actionBlock := actions at:tokenType ifAbsent:nil. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
837 |
actionBlock notNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
838 |
^ actionBlock value:self value:hereChar |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
839 |
] |
171 | 840 |
]. |
841 |
||
476 | 842 |
inputStream next. |
173 | 843 |
tokenType isNil ifTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
844 |
tokenType := #Error. |
171 | 845 |
]. |
173 | 846 |
^ tokenType |
171 | 847 |
|
476 | 848 |
"Modified: 11.1.1997 / 19:25:00 / cg" |
171 | 849 |
! |
850 |
||
175 | 851 |
skipComment |
476 | 852 |
inputStream next. |
853 |
hereChar := inputStream peek. |
|
171 | 854 |
|
175 | 855 |
[hereChar notNil and:[hereChar ~~ endCommentCharacter]] whileTrue:[ |
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
856 |
hereChar == eolCharacter ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
857 |
tokenLineNr := tokenLineNr + 1. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
858 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
859 |
outStream notNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
860 |
outStream nextPut:hereChar. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
861 |
outCol := outCol + 1 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
862 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
863 |
hereChar := inputStream nextPeek |
175 | 864 |
]. |
174 | 865 |
|
175 | 866 |
"Created: 1.2.1996 / 17:35:24 / cg" |
476 | 867 |
"Modified: 11.1.1997 / 19:25:02 / cg" |
171 | 868 |
! |
869 |
||
175 | 870 |
skipEolComment |
476 | 871 |
inputStream next. |
175 | 872 |
self skipToEol |
873 |
||
874 |
"Created: 1.2.1996 / 17:34:17 / cg" |
|
476 | 875 |
"Modified: 11.1.1997 / 19:25:04 / cg" |
175 | 876 |
! |
877 |
||
878 |
skipToEol |
|
476 | 879 |
hereChar := inputStream peek. |
175 | 880 |
|
881 |
[hereChar notNil and:[hereChar ~~ eolCharacter]] whileTrue:[ |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
882 |
outStream notNil ifTrue:[ |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
883 |
outStream nextPut:hereChar. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
884 |
outCol := outCol + 1 |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
885 |
]. |
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
476
diff
changeset
|
886 |
hereChar := inputStream nextPeek. |
174 | 887 |
]. |
175 | 888 |
tokenLineNr := tokenLineNr + 1. |
171 | 889 |
|
175 | 890 |
"Created: 1.2.1996 / 18:06:09 / cg" |
476 | 891 |
"Modified: 11.1.1997 / 19:25:07 / cg" |
171 | 892 |
! ! |
893 |
||
894 |
!TokenizedStream methodsFor:'testing'! |
|
895 |
||
175 | 896 |
atEnd |
476 | 897 |
^ inputStream atEnd or:[tokenType == #Error or:[tokenType == #EOF]] |
171 | 898 |
|
175 | 899 |
"Created: 1.2.1996 / 17:21:28 / cg" |
476 | 900 |
"Modified: 11.1.1997 / 19:24:05 / cg" |
171 | 901 |
! ! |
902 |
||
903 |
!TokenizedStream class methodsFor:'documentation'! |
|
904 |
||
905 |
version |
|
2385 | 906 |
^ '$Header: /cvs/stx/stx/libbasic2/TokenizedStream.st,v 1.12 2009-12-11 09:28:13 cg Exp $' |
171 | 907 |
! ! |
908 |
TokenizedStream initialize! |