--- a/FilteringLineStream.st Fri Feb 18 15:40:57 2000 +0100
+++ b/FilteringLineStream.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,6 +1,8 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT (c) 1996 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -24,7 +26,7 @@
copyright
"
COPYRIGHT (c) 1996 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -53,10 +55,10 @@
[author:]
- Claus Gittinger
+ Claus Gittinger
[See also:]
- FilteringStream ReadStream WriteStream
+ FilteringStream ReadStream WriteStream
"
@@ -67,17 +69,17 @@
pushing the contents of a stream onto another stream
(here, the Transcript) without a need to read everyting into a
buffer or to reinvent the read-loop:
- [exBegin]
+ [exBegin]
|in pusher|
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:Transcript.
pusher filterUpToEnd
- [exEnd]
+ [exEnd]
filter all comments (starting with '#') from a Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -88,11 +90,11 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
the inverse - remove all comments from the Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -103,12 +105,12 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
feed a second filter from the first filters output;
(the remains are all lines starting with '#' and ending with '-'):
- [exBegin]
+ [exBegin]
|in filter1 filter2|
in := 'Makefile' asFilename readStream.
@@ -122,7 +124,7 @@
filter2 outputStream:Transcript.
filter2 filterUpToEnd
- [exEnd]
+ [exEnd]
"
! !
@@ -134,7 +136,7 @@
push it filtered into the outputStream."
[inputStream atEnd] whileFalse:[
- self nextPutLine:(inputStream nextLine)
+ self nextPutLine:(inputStream nextLine)
].
"Created: 11.1.1997 / 16:09:05 / cg"
@@ -148,18 +150,18 @@
|output|
lineFilter isNil ifTrue:[
- lineBuffer notNil ifTrue:[
- outputStream nextPutAll:lineBuffer
- ].
- outputStream cr
+ lineBuffer notNil ifTrue:[
+ outputStream nextPutAll:lineBuffer
+ ].
+ outputStream cr
] ifFalse:[
- lineBuffer isNil ifTrue:[lineBuffer := ''].
+ lineBuffer isNil ifTrue:[lineBuffer := ''].
- output := lineFilter value:lineBuffer.
- output notNil ifTrue:[
- outputStream nextPutAll:output.
- outputStream cr.
- ]
+ output := lineFilter value:lineBuffer.
+ output notNil ifTrue:[
+ outputStream nextPutAll:output.
+ outputStream cr.
+ ]
].
lineBuffer := ''.
@@ -170,10 +172,10 @@
"collect a line and push it when a cr arrives"
something == Character cr ifTrue:[
- self cr
+ self cr
] ifFalse:[
- lineBuffer isNil ifTrue:[lineBuffer := ''].
- lineBuffer := lineBuffer copyWith:something.
+ lineBuffer isNil ifTrue:[lineBuffer := ''].
+ lineBuffer := lineBuffer copyWith:something.
]
"Created: 2.7.1996 / 20:54:38 / cg"
@@ -184,9 +186,9 @@
"collect a line and push it when a cr arrives"
lineBuffer isNil ifTrue:[
- lineBuffer := something
+ lineBuffer := something
] ifFalse:[
- lineBuffer := lineBuffer , something.
+ lineBuffer := lineBuffer , something.
]
"Modified: 11.1.1997 / 16:31:28 / cg"
@@ -213,5 +215,5 @@
!FilteringLineStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.4 1997-01-11 15:51:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.5 2000-03-02 14:15:07 cg Exp $'
! !
--- a/FilteringStream.st Fri Feb 18 15:40:57 2000 +0100
+++ b/FilteringStream.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,6 +1,8 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT (c) 1996 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -23,7 +25,7 @@
copyright
"
COPYRIGHT (c) 1996 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -62,16 +64,16 @@
(a Transcript, a RandomNumber generator or even a Plug will do as well).
[instance variables:]
- inputStream <Stream> the stream from which elements are read
- outputStream <Stream> the stream to which elements are written
- filter <Block> the filter block;
- unbound <Boolean> if true, the stream is unbound.
+ inputStream <Stream> the stream from which elements are read
+ outputStream <Stream> the stream to which elements are written
+ filter <Block> the filter block;
+ unbound <Boolean> if true, the stream is unbound.
[author:]
- Claus Gittinger
+ Claus Gittinger
[See also:]
- ReadStream WriteStream
+ ReadStream WriteStream
"
!
@@ -83,17 +85,17 @@
buffer or to reinvent the read-loop:
(notice, a FilteringLineStream does this with less overhead,
due to the byte-wise reading done here)
- [exBegin]
+ [exBegin]
|in pusher|
in := 'Makefile' asFilename readStream.
pusher := FilteringStream readingFrom:in writingTo:Transcript.
pusher filterUpToEnd
- [exEnd]
+ [exEnd]
filter random numbers:
- [exBegin]
+ [exBegin]
|in filter|
in := Random new.
@@ -102,44 +104,44 @@
filter filter:[:num | ((num >= 0.5) and:[num <= 0.6]) ifTrue:[num] ifFalse:[nil]].
20 timesRepeat:[
- Transcript showCR:(filter next printString).
+ Transcript showCR:(filter next printString).
]
- [exEnd]
+ [exEnd]
filtering prime numbers:
- [exBegin]
+ [exBegin]
|num generator primeFilter addFilter|
num := 1.
generator := Plug new.
generator respondTo:#next
- with:[num := num + 1. num].
+ with:[num := num + 1. num].
generator respondTo:#atEnd
- with:[false].
+ with:[false].
addFilter := [:prime | |newFilter|
- newFilter := FilteringLineStream basicNew.
- newFilter filter:[:num | (num \\ prime) == 0 ifTrue:[
- nil
- ] ifFalse:[
- num
- ]
- ].
- newFilter inputStream:primeFilter.
- primeFilter := newFilter
+ newFilter := FilteringLineStream basicNew.
+ newFilter filter:[:num | (num \\ prime) == 0 ifTrue:[
+ nil
+ ] ifFalse:[
+ num
+ ]
+ ].
+ newFilter inputStream:primeFilter.
+ primeFilter := newFilter
].
addFilter value:2.
primeFilter inputStream:generator.
10000 timesRepeat:[
- |nextPrime|
+ |nextPrime|
- nextPrime := primeFilter next.
- addFilter value:nextPrime.
- Transcript showCR:nextPrime.
+ nextPrime := primeFilter next.
+ addFilter value:nextPrime.
+ Transcript showCR:nextPrime.
]
- [exEnd]
+ [exEnd]
"
@@ -207,7 +209,7 @@
push it filtered into the outputStream."
[inputStream atEnd] whileFalse:[
- self nextPut:(inputStream next)
+ self nextPut:(inputStream next)
].
"Created: 2.7.1996 / 21:06:42 / cg"
@@ -224,24 +226,24 @@
"/ (see #atEnd)
readAhead notNil ifTrue:[
- input := readAhead.
- readAhead := nil.
- ^ input
+ input := readAhead.
+ readAhead := nil.
+ ^ input
].
[inputStream atEnd] whileFalse:[
- "/ get an element
- input := inputStream next.
- filter isNil ifTrue:[
- ^ input
- ].
+ "/ get an element
+ input := inputStream next.
+ filter isNil ifTrue:[
+ ^ input
+ ].
- "/ filter it - this may return nil, to eat it
- output := filter value:input.
- output notNil ifTrue:[
- "/ good - output it
- ^ output.
- ].
+ "/ filter it - this may return nil, to eat it
+ output := filter value:input.
+ output notNil ifTrue:[
+ "/ good - output it
+ ^ output.
+ ].
].
^ nil
@@ -258,12 +260,12 @@
"/ filter it
filter isNil ifTrue:[
- outputStream nextPut:something
+ outputStream nextPut:something
] ifFalse:[
- output := filter value:something.
- output notNil ifTrue:[
- outputStream nextPut:output
- ]
+ output := filter value:something.
+ output notNil ifTrue:[
+ outputStream nextPut:output
+ ]
]
"Modified: 11.1.1997 / 16:12:52 / cg"
@@ -331,7 +333,7 @@
"when I am closed, close my input - if any"
inputStream notNil ifTrue:[
- inputStream close
+ inputStream close
]
"Created: 11.1.1997 / 15:27:17 / cg"
@@ -347,8 +349,8 @@
readAhead notNil ifTrue:[^ false].
filter isNil ifTrue:[
- "/ then, its easy
- ^ inputStream atEnd
+ "/ then, its easy
+ ^ inputStream atEnd
].
"/ with a filter, things are more complicated,
@@ -356,9 +358,9 @@
[inputStream atEnd] whileFalse:[
- nextElement := inputStream next.
- readAhead := filter value:nextElement.
- readAhead notNil ifTrue:[^ false].
+ nextElement := inputStream next.
+ readAhead := filter value:nextElement.
+ readAhead notNil ifTrue:[^ false].
].
^ true
@@ -378,5 +380,5 @@
!FilteringStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FilteringStream.st,v 1.5 1997-01-11 18:55:14 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FilteringStream.st,v 1.6 2000-03-02 14:15:08 cg Exp $'
! !
--- a/Future.st Fri Feb 18 15:40:57 2000 +0100
+++ b/Future.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,4 +1,4 @@
-"{ Package: 'goodies/Parallelism-Futures' }"
+"{ Package: 'stx:goodies' }"
" NAME Parallelism
AUTHOR tph@cs.man.ac.uk
@@ -164,7 +164,7 @@
!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.5 1997-01-16 13:45:49 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.6 2000-03-02 14:14:58 cg Exp $'
! !
!Future methodsFor: 'synchronising'!
--- a/Iterator.st Fri Feb 18 15:40:57 2000 +0100
+++ b/Iterator.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,3 +1,5 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT.
The above file is a Manchester Goodie protected by copyright.
@@ -100,78 +102,78 @@
examples
"
an iterator, simulating the collection of all classes in the system:
- [exBegin]
+ [exBegin]
|i b|
b := [:whatToDo |
- Smalltalk allClassesDo:[:cls |
- whatToDo value:cls
- ]
- ].
+ Smalltalk allClassesDo:[:cls |
+ whatToDo value:cls
+ ]
+ ].
i := Iterator on:b.
i do:[:cls |
- Transcript showCR:cls name
+ Transcript showCR:cls name
].
- [exEnd]
+ [exEnd]
much like above, one that simulates the collection of all methodNames starting with 'a':
- [exBegin]
+ [exBegin]
|i b|
b := [:whatToDo |
- Smalltalk allClassesDo:[:cls |
- cls methodDictionary keysAndValuesDo:[:nm :mthd |
- (nm startsWith:$a) ifTrue:[
- whatToDo value:nm
- ]
- ]
- ]
- ].
+ Smalltalk allClassesDo:[:cls |
+ cls methodDictionary keysAndValuesDo:[:nm :mthd |
+ (nm startsWith:$a) ifTrue:[
+ whatToDo value:nm
+ ]
+ ]
+ ]
+ ].
i := Iterator on:b.
i do:[:nm |
- Transcript showCR:nm
+ Transcript showCR:nm
].
- [exEnd]
+ [exEnd]
an iterator, simulating a collection of 100 random values:
- [exBegin]
+ [exBegin]
|i b|
b := [:whatToDo |
- |rnd|
+ |rnd|
- rnd := Random new.
- 1 to:100 do:[:i |
- whatToDo value:(rnd next)
- ]
- ].
+ rnd := Random new.
+ 1 to:100 do:[:i |
+ whatToDo value:(rnd next)
+ ]
+ ].
i := Iterator on:b.
i do:[:j |
- j printNL
+ j printNL
].
- [exEnd]
+ [exEnd]
an iterator, simulating a collection of the lines
in a file:
- [exBegin]
+ [exBegin]
|i b|
b := [:whatToDo |
- |s line|
+ |s line|
- s := 'smalltalk.rc' asFilename readStream.
- [s atEnd] whileFalse:[
- line := s nextLine.
- whatToDo value:line.
- ].
- s close
- ].
+ s := 'smalltalk.rc' asFilename readStream.
+ [s atEnd] whileFalse:[
+ line := s nextLine.
+ whatToDo value:line.
+ ].
+ s close
+ ].
i := Iterator on:b.
i do:[:j |
- j printNL
+ j printNL
].
- [exEnd]
+ [exEnd]
"
! !
@@ -357,5 +359,5 @@
!Iterator class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Iterator.st,v 1.7 2000-02-05 14:29:07 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Iterator.st,v 1.8 2000-03-02 14:14:24 cg Exp $'
! !
--- a/Lazy.st Fri Feb 18 15:40:57 2000 +0100
+++ b/Lazy.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,4 +1,4 @@
-"{ Package: 'goodies/Parallelism-Lazy' }"
+"{ Package: 'stx:goodies' }"
" NAME Parallelism
AUTHOR tph@cs.man.ac.uk
--- a/LineNumberReadStream.st Fri Feb 18 15:40:57 2000 +0100
+++ b/LineNumberReadStream.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,6 +1,8 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT (c) 1996 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -24,7 +26,7 @@
copyright
"
COPYRIGHT (c) 1996 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -46,18 +48,18 @@
input stream, and let it keep track of the lineNumber.
[see also:]
- ReadStream WriteStream ExternalStream FileStream
- FilteringStream FilteringLineStream
+ ReadStream WriteStream ExternalStream FileStream
+ FilteringStream FilteringLineStream
[author:]
- Claus Gittinger
+ Claus Gittinger
"
!
examples
"
count lines in a Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -68,12 +70,12 @@
filter close.
Transcript showCR:('Makefile has %1 lines' bindWith:(filter lineNumber - 1)).
- [exEnd]
+ [exEnd]
find a specific string and output its lineNr:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -84,7 +86,7 @@
filter close.
Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
- [exEnd]
+ [exEnd]
"
@@ -118,11 +120,11 @@
lineNumber := 1.
filter := [:char |
- char == Character cr ifTrue:[
- lineNumber := lineNumber + 1.
- ].
- char
- ].
+ char == Character cr ifTrue:[
+ lineNumber := lineNumber + 1.
+ ].
+ char
+ ].
"Modified: 11.1.1997 / 16:58:42 / cg"
! !
@@ -130,5 +132,5 @@
!LineNumberReadStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.1 1997-01-11 18:54:37 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.2 2000-03-02 14:14:53 cg Exp $'
! !
--- a/OrderedDictionary.st Fri Feb 18 15:40:57 2000 +0100
+++ b/OrderedDictionary.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,3 +1,5 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT.
This is a Manchester Goodie protected by copyright.
@@ -775,6 +777,6 @@
!OrderedDictionary class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Attic/OrderedDictionary.st,v 1.12 1999-10-28 13:20:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Attic/OrderedDictionary.st,v 1.13 2000-03-02 14:14:27 cg Exp $'
! !
--- a/TokenizedStream.st Fri Feb 18 15:40:57 2000 +0100
+++ b/TokenizedStream.st Thu Mar 02 15:15:13 2000 +0100
@@ -1,6 +1,8 @@
+"{ Package: 'stx:goodies' }"
+
"
COPYRIGHT (c) 1996 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -28,7 +30,7 @@
copyright
"
COPYRIGHT (c) 1996 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -54,15 +56,15 @@
operation:
- characters are read from a real input stream
- and the tokenizer dispatches to a token reading method by the help
- of an actionTable, which is indexed by the tokenType.
- The tokenType itself is aquired via another table via
- the characters ascii code.
+ characters are read from a real input stream
+ and the tokenizer dispatches to a token reading method by the help
+ of an actionTable, which is indexed by the tokenType.
+ The tokenType itself is aquired via another table via
+ the characters ascii code.
- By default, the table is setup to only read numbers
- and identifiers.
- Whitespace is ignored, and all other characters return themself.
+ By default, the table is setup to only read numbers
+ and identifiers.
+ Whitespace is ignored, and all other characters return themself.
The returned tokens are either symbols (#Identifier, #Integer ..) or
characters ($+ $, etc.)
@@ -77,218 +79,218 @@
See examples for more.
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- ReadStream
- Scanner
- Tgen::*
+ ReadStream
+ Scanner
+ Tgen::*
"
!
examples
"
simple example; tokenizing some string:
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'hello world, how much is 3 + 2'.
- [s atEnd] whileFalse:[
- Transcript showCR:(s next).
- ].
- [exEnd]
+ s := TokenizedStream on:'hello world, how much is 3 + 2'.
+ [s atEnd] whileFalse:[
+ Transcript showCR:(s next).
+ ].
+ [exEnd]
simple example2; tokenizing and checking:
- [exBegin]
- |s token|
+ [exBegin]
+ |s token|
- s := TokenizedStream on:'foo bar baz 3 + 2'.
- [s atEnd] whileFalse:[
- token := s next.
- token == #Identifier ifTrue:[
- Transcript showCR:(token , ' name=' , s tokenName).
- ] ifFalse:[
- token == #Integer ifTrue:[
- Transcript showCR:(token , ' value=' , s tokenValue printString).
- ] ifFalse:[
- Transcript showCR:token.
- ]
- ]
- ].
- [exEnd]
+ s := TokenizedStream on:'foo bar baz 3 + 2'.
+ [s atEnd] whileFalse:[
+ token := s next.
+ token == #Identifier ifTrue:[
+ Transcript showCR:(token , ' name=' , s tokenName).
+ ] ifFalse:[
+ token == #Integer ifTrue:[
+ Transcript showCR:(token , ' value=' , s tokenValue printString).
+ ] ifFalse:[
+ Transcript showCR:token.
+ ]
+ ]
+ ].
+ [exEnd]
reading simple expressions:
- [exBegin]
- |s num1 num2|
+ [exBegin]
+ |s num1 num2|
- s := TokenizedStream on:'
+ s := TokenizedStream on:'
3 + 2
4 + 6
1 + 2
'.
- [s atEnd] whileFalse:[
- s next == #Integer ifTrue:[
- num1 := s tokenValue.
- s next == $+ ifTrue:[
- s next == #Integer ifTrue:[
- num2 := s tokenValue.
- Transcript showCR:num1 printString
- , ' + '
- , num2 printString
- , ' => '
- , (num1 + num2) printString.
- ]
- ]
- ]
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next == #Integer ifTrue:[
+ num1 := s tokenValue.
+ s next == $+ ifTrue:[
+ s next == #Integer ifTrue:[
+ num2 := s tokenValue.
+ Transcript showCR:num1 printString
+ , ' + '
+ , num2 printString
+ , ' => '
+ , (num1 + num2) printString.
+ ]
+ ]
+ ]
+ ].
+ [exEnd]
with eol-comments:
- [exBegin]
- |s num1 num2|
+ [exBegin]
+ |s num1 num2|
- s := TokenizedStream on:'
+ s := TokenizedStream on:'
3 + 2
; this is a comment
4 + 6
1 + 2
'.
- s eolCommentCharacter:$;.
+ s eolCommentCharacter:$;.
- [s atEnd] whileFalse:[
- s next == #Integer ifTrue:[
- num1 := s tokenValue.
- s next == $+ ifTrue:[
- s next == #Integer ifTrue:[
- num2 := s tokenValue.
- Transcript showCR:num1 printString
- , ' + '
- , num2 printString
- , ' => '
- , (num1 + num2) printString.
- ]
- ]
- ]
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next == #Integer ifTrue:[
+ num1 := s tokenValue.
+ s next == $+ ifTrue:[
+ s next == #Integer ifTrue:[
+ num2 := s tokenValue.
+ Transcript showCR:num1 printString
+ , ' + '
+ , num2 printString
+ , ' => '
+ , (num1 + num2) printString.
+ ]
+ ]
+ ]
+ ].
+ [exEnd]
allowing float & negative numbers (the default):
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'.
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString, ' value=' , s tokenValue printString).
- ].
- [exEnd]
+ s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'.
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString, ' value=' , s tokenValue printString).
+ ].
+ [exEnd]
not allowing float numbers :
(notice, how the floats is scanned)
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0 '.
- s allowFloatNumbers:false.
+ s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0 '.
+ s allowFloatNumbers:false.
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString).
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString).
+ ].
+ [exEnd]
not allowing negative numbers :
(notice, how the signs is scanned)
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'.
- s numbersAreSigned:false.
+ s := TokenizedStream on:'1.23 4.56 7 8 9 -5 5 -5.0 5.0'.
+ s numbersAreSigned:false.
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString).
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString).
+ ].
+ [exEnd]
no radix numbers (the default):
(notice, how the integer is scanned)
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'1234 0x1234 16r1234'.
+ s := TokenizedStream on:'1234 0x1234 16r1234'.
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
+ ].
+ [exEnd]
C-style radix numbers:
(notice, how the ST-style integer is scanned)
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'0x1234 16r1234'.
- s actionTable at:#digit put:[:s :char | s nextCNumber].
+ s := TokenizedStream on:'0x1234 16r1234'.
+ s actionTable at:#digit put:[:s :char | s nextCNumber].
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
+ ].
+ [exEnd]
smalltalk-style radix numbers:
(notice, how the C-style integer is scanned)
- [exBegin]
- |s|
+ [exBegin]
+ |s|
- s := TokenizedStream on:'0x1234 16r1234'.
- s actionTable at:#digit put:[:s :char | s nextSmalltalkNumber].
+ s := TokenizedStream on:'0x1234 16r1234'.
+ s actionTable at:#digit put:[:s :char | s nextSmalltalkNumber].
- [s atEnd] whileFalse:[
- s next.
- Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
- ].
- [exEnd]
+ [s atEnd] whileFalse:[
+ s next.
+ Transcript showCR:(s tokenType displayString , ' value= ' , s tokenValue printString , ' name=' , s tokenName displayString).
+ ].
+ [exEnd]
scan the '/etc/services' file:
- [exBegin]
- |s t service port protocol|
+ [exBegin]
+ |s t service port protocol|
- s := TokenizedStream on:'/etc/services' asFilename readStream.
- s eolCommentCharacter:$#.
- s typeTable at:($- asciiValue) put:#letter.
+ s := TokenizedStream on:'/etc/services' asFilename readStream.
+ s eolCommentCharacter:$#.
+ s typeTable at:($- asciiValue) put:#letter.
- [s atEnd] whileFalse:[
- t := s next.
- t == #Identifier ifTrue:[
- service := s tokenName.
- t := s next.
- t == #Integer ifTrue:[
- port := s tokenValue.
- s next == $/ ifTrue:[
- t := s next.
- t == #Identifier ifTrue:[
- protocol := s tokenName.
- Transcript showCR:('servive: ' , service , ' is ' , protocol , ' port=' , port printString).
- ]
- ]
- ]
- ].
- s skipToEol
- ]
- [exEnd]
+ [s atEnd] whileFalse:[
+ t := s next.
+ t == #Identifier ifTrue:[
+ service := s tokenName.
+ t := s next.
+ t == #Integer ifTrue:[
+ port := s tokenValue.
+ s next == $/ ifTrue:[
+ t := s next.
+ t == #Identifier ifTrue:[
+ protocol := s tokenName.
+ Transcript showCR:('servive: ' , service , ' is ' , protocol , ' port=' , port printString).
+ ]
+ ]
+ ]
+ ].
+ s skipToEol
+ ]
+ [exEnd]
"
! !
@@ -471,53 +473,53 @@
tokenRadix := 10.
inputStream peek == $0 ifTrue:[
- inputStream next.
- inputStream peek == $x ifTrue:[
- inputStream next.
- tokenRadix := 16.
- ] ifFalse:[
- tokenRadix := 8
- ]
+ inputStream next.
+ inputStream peek == $x ifTrue:[
+ inputStream next.
+ tokenRadix := 16.
+ ] ifFalse:[
+ tokenRadix := 8
+ ]
].
value := Integer readFrom:inputStream radix:tokenRadix.
nextChar := inputStream peek.
(allowFloatNumbers and:[tokenRadix == 10]) ifTrue:[
- (nextChar == $.) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
- value := value asFloat + (self nextMantissa:tokenRadix).
- nextChar := inputStream peek
- ] ifFalse:[
- nextChar == (Character cr) ifTrue:[
- tokenLineNr := tokenLineNr + 1.
- ].
- peekChar := $.
- ]
- ].
- ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
- s := 1.
- (nextChar == $+) ifTrue:[
- nextChar := inputStream nextPeek
- ] ifFalse:[
- (nextChar == $-) ifTrue:[
- nextChar := inputStream nextPeek.
- s := s negated
- ]
- ].
- value := value asFloat
- * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
- ]
- ].
+ (nextChar == $.) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
+ value := value asFloat + (self nextMantissa:tokenRadix).
+ nextChar := inputStream peek
+ ] ifFalse:[
+ nextChar == (Character cr) ifTrue:[
+ tokenLineNr := tokenLineNr + 1.
+ ].
+ peekChar := $.
+ ]
+ ].
+ ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
+ s := 1.
+ (nextChar == $+) ifTrue:[
+ nextChar := inputStream nextPeek
+ ] ifFalse:[
+ (nextChar == $-) ifTrue:[
+ nextChar := inputStream nextPeek.
+ s := s negated
+ ]
+ ].
+ value := value asFloat
+ * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
+ ]
+ ].
].
tokenValue := value.
(value isMemberOf:Float) ifTrue:[
- tokenType := #Float
+ tokenType := #Float
] ifFalse:[
- tokenType := #Integer
+ tokenType := #Integer
].
^ tokenType
@@ -538,23 +540,23 @@
done := false.
[done] whileFalse:[
- nextChar isNil ifTrue:[
- done := true
- ] ifFalse:[
- t := types at:(nextChar asciiValue).
- done := (t ~~ #letter and:[t ~~ #digit]).
- ].
- done ifFalse:[
- (index == max) ifTrue:[
- oldString := string.
- string := String basicNew:(max * 2).
- string replaceFrom:1 to:max with:oldString.
- max := max * 2
- ].
- index := index + 1.
- string at:index put:nextChar.
- nextChar := inputStream nextPeek
- ]
+ nextChar isNil ifTrue:[
+ done := true
+ ] ifFalse:[
+ t := types at:(nextChar asciiValue).
+ done := (t ~~ #letter and:[t ~~ #digit]).
+ ].
+ done ifFalse:[
+ (index == max) ifTrue:[
+ oldString := string.
+ string := String basicNew:(max * 2).
+ string replaceFrom:1 to:max with:oldString.
+ max := max * 2
+ ].
+ index := index + 1.
+ string at:index put:nextChar.
+ nextChar := inputStream nextPeek
+ ]
].
tokenType := #Identifier.
tokenName := string copyTo:index.
@@ -581,9 +583,9 @@
factor := 1.0 / radix.
nextChar := inputStream peek.
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[
- value := value + (nextChar digitValue * factor).
- factor := factor / radix.
- nextChar := inputStream nextPeek
+ value := value + (nextChar digitValue * factor).
+ factor := factor / radix.
+ nextChar := inputStream nextPeek
].
^ value
@@ -598,40 +600,40 @@
value := Integer readFrom:inputStream radix:tokenRadix.
nextChar := inputStream peek.
allowFloatNumbers ifTrue:[
- (nextChar == $.) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
- value := value asFloat + (self nextMantissa:tokenRadix).
- nextChar := inputStream peek
- ] ifFalse:[
- nextChar == (Character cr) ifTrue:[
- tokenLineNr := tokenLineNr + 1.
- ].
- peekChar := $.
- ]
- ].
- ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
- s := 1.
- (nextChar == $+) ifTrue:[
- nextChar := inputStream nextPeek
- ] ifFalse:[
- (nextChar == $-) ifTrue:[
- nextChar := inputStream nextPeek.
- s := s negated
- ]
- ].
- value := value asFloat
- * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
- ]
- ].
+ (nextChar == $.) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
+ value := value asFloat + (self nextMantissa:tokenRadix).
+ nextChar := inputStream peek
+ ] ifFalse:[
+ nextChar == (Character cr) ifTrue:[
+ tokenLineNr := tokenLineNr + 1.
+ ].
+ peekChar := $.
+ ]
+ ].
+ ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
+ s := 1.
+ (nextChar == $+) ifTrue:[
+ nextChar := inputStream nextPeek
+ ] ifFalse:[
+ (nextChar == $-) ifTrue:[
+ nextChar := inputStream nextPeek.
+ s := s negated
+ ]
+ ].
+ value := value asFloat
+ * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
+ ]
+ ].
].
tokenValue := value.
(value isMemberOf:Float) ifTrue:[
- tokenType := #Float
+ tokenType := #Float
] ifFalse:[
- tokenType := #Integer
+ tokenType := #Integer
].
^ tokenType
@@ -644,11 +646,11 @@
inputStream next.
numbersAreSigned ifTrue:[
- next := inputStream peek.
- (next notNil and:[(types at:next asciiValue) == #digit]) ifTrue:[
- (actions at:#digit) value:self value:next.
- tokenValue := tokenValue negated.
- ]
+ next := inputStream peek.
+ (next notNil and:[(types at:next asciiValue) == #digit]) ifTrue:[
+ (actions at:#digit) value:self value:next.
+ tokenValue := tokenValue negated.
+ ]
].
^ tokenType
@@ -662,52 +664,52 @@
value := Integer readFrom:inputStream radix:tokenRadix.
nextChar := inputStream peek.
(nextChar == $r) ifTrue:[
- tokenRadix := value.
- inputStream next.
- s := 1.
- inputStream peek == $- ifTrue:[
- inputStream next.
- s := -1
- ].
- value := Integer readFrom:inputStream radix:tokenRadix.
- value := value * s.
- nextChar := inputStream peek
+ tokenRadix := value.
+ inputStream next.
+ s := 1.
+ inputStream peek == $- ifTrue:[
+ inputStream next.
+ s := -1
+ ].
+ value := Integer readFrom:inputStream radix:tokenRadix.
+ value := value * s.
+ nextChar := inputStream peek
].
allowFloatNumbers ifTrue:[
- (nextChar == $.) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
- value := value asFloat + (self nextMantissa:tokenRadix).
- nextChar := inputStream peek
- ] ifFalse:[
- nextChar == (Character cr) ifTrue:[
- tokenLineNr := tokenLineNr + 1.
- ].
- peekChar := $.
- ]
- ].
- ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
- nextChar := inputStream nextPeek.
- (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
- s := 1.
- (nextChar == $+) ifTrue:[
- nextChar := inputStream nextPeek
- ] ifFalse:[
- (nextChar == $-) ifTrue:[
- nextChar := inputStream nextPeek.
- s := s negated
- ]
- ].
- value := value asFloat
- * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
- ]
- ].
+ (nextChar == $.) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
+ value := value asFloat + (self nextMantissa:tokenRadix).
+ nextChar := inputStream peek
+ ] ifFalse:[
+ nextChar == (Character cr) ifTrue:[
+ tokenLineNr := tokenLineNr + 1.
+ ].
+ peekChar := $.
+ ]
+ ].
+ ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
+ nextChar := inputStream nextPeek.
+ (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
+ s := 1.
+ (nextChar == $+) ifTrue:[
+ nextChar := inputStream nextPeek
+ ] ifFalse:[
+ (nextChar == $-) ifTrue:[
+ nextChar := inputStream nextPeek.
+ s := s negated
+ ]
+ ].
+ value := value asFloat
+ * (10.0 raisedToInteger:((Integer readFrom:inputStream radix:tokenRadix) * s))
+ ]
+ ].
].
tokenValue := value.
(value isMemberOf:Float) ifTrue:[
- tokenType := #Float
+ tokenType := #Float
] ifFalse:[
- tokenType := #Integer
+ tokenType := #Integer
].
^ tokenType
@@ -730,30 +732,30 @@
inString := true.
[inString] whileTrue:[
- nextChar isNil ifTrue:[
- self error:'unexpected end-of-input in String'.
- tokenType := #EOF.
- ^ tokenType
- ].
- (nextChar == Character cr) ifTrue:[
- tokenLineNr := tokenLineNr + 1
- ].
- (nextChar == separator) ifTrue:[
- (inputStream peek == separator) ifTrue:[
- inputStream next
- ] ifFalse:[
- inString := false
- ]
- ].
- inString ifTrue:[
- string at:index put:nextChar.
- (index == len) ifTrue:[
- string := string , (String new:len).
- len := len * 2
- ].
- index := index + 1.
- nextChar := inputStream next
- ]
+ nextChar isNil ifTrue:[
+ self error:'unexpected end-of-input in String'.
+ tokenType := #EOF.
+ ^ tokenType
+ ].
+ (nextChar == Character cr) ifTrue:[
+ tokenLineNr := tokenLineNr + 1
+ ].
+ (nextChar == separator) ifTrue:[
+ (inputStream peek == separator) ifTrue:[
+ inputStream next
+ ] ifFalse:[
+ inString := false
+ ]
+ ].
+ inString ifTrue:[
+ string at:index put:nextChar.
+ (index == len) ifTrue:[
+ string := string , (String new:len).
+ len := len * 2
+ ].
+ index := index + 1.
+ nextChar := inputStream next
+ ]
].
tokenValue := string copyTo:(index - 1).
tokenType := #String.
@@ -771,75 +773,75 @@
tokenValue := tokenName := nil.
peekChar notNil ifTrue:[
- hereChar := peekChar.
- peekChar := peekChar2.
- peekChar2 := nil
+ hereChar := peekChar.
+ peekChar := peekChar2.
+ peekChar2 := nil
] ifFalse:[
- skipping := true.
- [skipping] whileTrue:[
- outStream notNil ifTrue:[
- [(hereChar := inputStream peek) == Character space] whileTrue:[
- inputStream next.
- outStream space.
- outCol := outCol + 1.
- ]
- ] ifFalse:[
- hereChar := inputStream skipSeparatorsExceptCR.
- ].
- hereChar isNil ifTrue:[
- tokenType := #EOF.
- ^ tokenType
- ].
- hereChar == eolCharacter ifTrue:[
- tokenLineNr := tokenLineNr + 1.
- inputStream next.
- outStream notNil ifTrue:[
- outStream cr.
- outCol := 1
- ].
- eolIsSignificant ifTrue:[
- tokenType := #EOL.
- ^ tokenType
- ]
- ] ifFalse:[
- hereChar == beginCommentCharacter ifTrue:[
- "start of a comment"
+ skipping := true.
+ [skipping] whileTrue:[
+ outStream notNil ifTrue:[
+ [(hereChar := inputStream peek) == Character space] whileTrue:[
+ inputStream next.
+ outStream space.
+ outCol := outCol + 1.
+ ]
+ ] ifFalse:[
+ hereChar := inputStream skipSeparatorsExceptCR.
+ ].
+ hereChar isNil ifTrue:[
+ tokenType := #EOF.
+ ^ tokenType
+ ].
+ hereChar == eolCharacter ifTrue:[
+ tokenLineNr := tokenLineNr + 1.
+ inputStream next.
+ outStream notNil ifTrue:[
+ outStream cr.
+ outCol := 1
+ ].
+ eolIsSignificant ifTrue:[
+ tokenType := #EOL.
+ ^ tokenType
+ ]
+ ] ifFalse:[
+ hereChar == beginCommentCharacter ifTrue:[
+ "start of a comment"
- self skipComment.
- hereChar := inputStream peek.
- ] ifFalse:[
- hereChar == eolCommentCharacter ifTrue:[
- "start of an eol comment"
+ self skipComment.
+ hereChar := inputStream peek.
+ ] ifFalse:[
+ hereChar == eolCommentCharacter ifTrue:[
+ "start of an eol comment"
- self skipEolComment.
- hereChar := inputStream peek.
- ] ifFalse:[
- skipping := false
- ]
- ]
- ]
- ].
- hereChar isNil ifTrue:[
- tokenType := #EOF.
- ^ tokenType
- ]
+ self skipEolComment.
+ hereChar := inputStream peek.
+ ] ifFalse:[
+ skipping := false
+ ]
+ ]
+ ]
+ ].
+ hereChar isNil ifTrue:[
+ tokenType := #EOF.
+ ^ tokenType
+ ]
].
tokenPosition := inputStream position.
types notNil ifTrue:[
- tokenType := types at:(hereChar asciiValue).
+ tokenType := types at:(hereChar asciiValue).
].
actions notNil ifTrue:[
- actionBlock := actions at:tokenType ifAbsent:nil.
- actionBlock notNil ifTrue:[
- ^ actionBlock value:self value:hereChar
- ]
+ actionBlock := actions at:tokenType ifAbsent:nil.
+ actionBlock notNil ifTrue:[
+ ^ actionBlock value:self value:hereChar
+ ]
].
inputStream next.
tokenType isNil ifTrue:[
- tokenType := #Error.
+ tokenType := #Error.
].
^ tokenType
@@ -851,14 +853,14 @@
hereChar := inputStream peek.
[hereChar notNil and:[hereChar ~~ endCommentCharacter]] whileTrue:[
- hereChar == eolCharacter ifTrue:[
- tokenLineNr := tokenLineNr + 1.
- ].
- outStream notNil ifTrue:[
- outStream nextPut:hereChar.
- outCol := outCol + 1
- ].
- hereChar := inputStream nextPeek
+ hereChar == eolCharacter ifTrue:[
+ tokenLineNr := tokenLineNr + 1.
+ ].
+ outStream notNil ifTrue:[
+ outStream nextPut:hereChar.
+ outCol := outCol + 1
+ ].
+ hereChar := inputStream nextPeek
].
"Created: 1.2.1996 / 17:35:24 / cg"
@@ -877,11 +879,11 @@
hereChar := inputStream peek.
[hereChar notNil and:[hereChar ~~ eolCharacter]] whileTrue:[
- outStream notNil ifTrue:[
- outStream nextPut:hereChar.
- outCol := outCol + 1
- ].
- hereChar := inputStream nextPeek.
+ outStream notNil ifTrue:[
+ outStream nextPut:hereChar.
+ outCol := outCol + 1
+ ].
+ hereChar := inputStream nextPeek.
].
tokenLineNr := tokenLineNr + 1.
@@ -901,6 +903,6 @@
!TokenizedStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/TokenizedStream.st,v 1.10 1997-01-11 18:44:30 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/TokenizedStream.st,v 1.11 2000-03-02 14:15:13 cg Exp $'
! !
TokenizedStream initialize!