|
|
Class: PeekableStream
Object
|
+--Stream
|
+--PeekableStream
|
+--ActorStream
|
+--EncodedStream
|
+--FilteringStream
|
+--PositionableStream
|
+--ZipArchive::AbstractZipStream
- Package:
- stx:libbasic
- Category:
- Streams
- Version:
- rev:
1.39
date: 2010/03/12 12:39:13
- user: cg
- file: PeekableStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
abstract superclass for all Stream which support read-ahead
(i.e. peeking) of one element.
Concrete subclasses must implement a peek method.
Signal constants
-
currentFileInDirectoryQuerySignal
-
return the querySignal, which can be used to ask for the current directory
during a fileIn (that is the directory where the filed-in file resides),
and in a fileBrowsers doIt.
Using this, allows for the loaded code or doIts to ask for the fileBrowsers
current directory, by asking this querySignal (which is nice sometimes).
-
currentSourceContainerQuery
-
return the querySignal, which can be used to ask for the current source container filename
during a fileIn
Using this, allows for the loaded code to remember the classes file name.
initialization
-
initialize
-
setup the signal used to handle errors during fileIn
queries
-
currentFileInDirectory
-
during a fileIn (if a script), the script can ask for the current directory
-
currentSourceContainer
-
during a fileIn (if a script), the script can ask for the current filename
chunk input/output
-
nextChunk
-
return the next chunk, i.e. all characters up to the next
exclamation mark. Within the chunk, exclamation marks have to be doubled,
they are undoubled here.
Except for primitive code, in which doubling is not needed (allowed).
This exception was added to make it easier to edit primitive code with
external editors. However, this means, that other Smalltalks cannot always
read chunks containing primitive code
- but that doesn't really matter, since C-primitives are an ST/X feature anyway.
fileIn
-
fileIn
-
file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.
-
fileInBinary
-
file in from the receiver, i.e. read binary stored classes and/or objects.
Return the last object.
positioning
-
skipAny: skipCollection
-
skip all characters included in the argument-set.
returns the next peeked element or nil, if the end-of-stream was reached.
-
skipSeparators
-
skip all whitespace; returns the next peeked element or
nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: compare this method to skipSpaces
-
skipSeparatorsExceptCR
-
skip all whitespace except carriage return; returns the
next peeked element or nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: compare this method to skipSpaces and skipSeparators
-
skipSpaces
-
skip all spaces; returns the next peeked element or
nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: this one skips only spaces (i.e. no cr, tabs etc)
usually, skipSeparators is what you want.
private fileIn
-
basicFileInNotifying: someone passChunk: passChunk
-
central method to file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.
Someone (which is usually some codeView) is notified of errors.
-
fileInNextChunkNotifying: someone
-
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.
-
fileInNextChunkNotifying: someone passChunk: passChunk
-
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.
-
fileInNextChunkNotifying: someone passChunk: passChunk silent: beSilent
-
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.
-
fileInNotifying: notifiedLoader passChunk: passChunk
-
central method to file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.
Someone (which is usually some codeView) is notified of errors.
-
fileInXMLNotifying: someone passChunk: passChunk
-
filein an XML source file (format as in campSmalltalk DTD)
reading
-
nextDecimalInteger
-
read the next integer in radix 10. Does NOT skip initial whitespace.
The streams elements should be characters.
Be careful - this method returns 0 if not posiioned on a digit intitially
or if the end of the stream is encountered.
-
nextDelimited: terminator
-
return the contents of the receiver, up to the next terminator character.
Doubled terminators indicate an embedded terminator character.
For example: 'this '' was a quote'.
Start postioned before the initial terminator.
-
nextPeek
-
advance to next element and return the peeked element
-
nextUpTo: anObject
-
read a collection of all objects up-to anObject and return these
elements, but excluding anObject.
The next read operation will return anObject.
If anObject is not encountered, all elements up to the end are read
and returned, and the stream is positioned at the end.
Compare this with #upTo: which positions behind anObject
-
peek
-
return the next element of the stream without advancing (i.e.
the following send of next will return this element again.)
- we do not know here how to do it, it must be redefined in subclass
** This method raises an error - it must be redefined in concrete classes **
-
peekFor: anObject
-
if the next-to-be-read object is equal to the argument, anObject, read it
and return true. Otherwise, leave the receiver unaffected and return false.
-
peekOrNil
-
like #peek, this returns the next readAhead element, if available.
However, unlike #peek, this does not raise an atEnd-query signal - even
if handled. Instead, nil is returned immediately.
-
throughAnyForWhich: checkBlock
-
read & return a collection of all objects up-to and including
the elements for which checkBlock returns true.
(i.e. read until checkBlock returns false on an element)
If no such element is encountered, all elements up to the end are read
and returned.
-
upToMatching: aBlock
-
Return the next elements up to but not including the next element
for which aBlock returns true.
The next read will return that matching element.
-
upToSeparator
-
Return the next elements up to but not including the next separator.
The next read will return the separator.
If no separator is encountered, the contents up to the end is returned.
The elements are supposed to understand #isSeparator
(i.e. the receiver is supposed to be a character-stream).
reading-strings
-
nextAlphaNumericWord
-
read the next word (i.e. up to non letter-or-digit).
Return a string containing those characters.
Any leading non-alphaNumeric chars are skipped.
-
nextMatching: matchBlock1 thenMatching: matchBlock2
-
read the next word. The first character must match matchBlock1,
remaining characters must match matchBlock2.
Return a string containing those characters.
-
nextSymbol
-
read the next selector-symbol (i.e. up to non letter-or-digit).
Return a string containing those characters.
Any leading non-alphaNumeric chars are skipped.
-
nextWord
-
return the next characters which form an alphanumeric word
(i.e. everything upTo (but excluding) the next non alphanumeric
element)
|