PeekableStream.st
author Stefan Vogel <sv@exept.de>
Fri, 27 Oct 2017 16:14:37 +0200
branchexpecco_2_11_1_branch
changeset 22329 20662662693b
parent 21033 c31725b2b658
child 21042 edb2e7f82c62
child 21135 7a598959b48e
permissions -rw-r--r--
Add 2.11.0 Patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     1
"
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
379
5b5a130ccd09 revision added
claus
parents: 369
diff changeset
     3
	      All Rights Reserved
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     4
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    11
"
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    12
"{ Package: 'stx:libbasic' }"
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    13
17560
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    14
"{ NameSpace: Smalltalk }"
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    15
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    16
Stream subclass:#PeekableStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	instanceVariableNames:''
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    18
	classVariableNames:'ErrorDuringFileInSignal CurrentFileInDirectoryQuerySignal
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    19
		CurrentSourceContainerQuery'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    20
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    21
	category:'Streams'
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    22
!
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
!PeekableStream class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 COPYRIGHT (c) 1994 by Claus Gittinger
379
5b5a130ccd09 revision added
claus
parents: 369
diff changeset
    29
	      All Rights Reserved
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    30
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
!
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    39
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    abstract superclass for all Stream which support read-ahead
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
    (i.e. peeking) of one element.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
    Concrete subclasses must implement a peek method.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    45
17560
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    46
    [caveat:]
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    47
        Basing capabilities like readability/writability/positionability/peekability on inheritance makes
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    48
        the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    49
        below PositionableStream or ExternalReadStream under WriteStream)
7af6b7f75d05 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16883
diff changeset
    50
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    51
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    52
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    53
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    54
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    55
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    56
!PeekableStream class methodsFor:'initialization'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    57
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    58
initialize
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    59
    "setup the signal used to handle errors during fileIn"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    60
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    61
    ErrorDuringFileInSignal isNil ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    62
        ErrorDuringFileInSignal := Error newSignalMayProceed:true.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    63
        ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    64
        ErrorDuringFileInSignal notifierString:'error during fileIn'.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    65
    ]
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    66
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    67
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    68
     self initialize
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    69
    "
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    70
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    71
    "Modified: / 23-10-2006 / 16:34:41 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    72
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    73
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    74
!PeekableStream class methodsFor:'Signal constants'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    75
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    76
currentFileInDirectoryQuerySignal
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    77
    "return the querySignal, which can be used to ask for the current directory
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    78
     during a fileIn (that is the directory where the filed-in file resides),
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    79
     and in a fileBrowsers doIt.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    80
     Using this, allows for the loaded code or doIts to ask for the fileBrowsers
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    81
     current directory, by asking this querySignal (which is nice sometimes)."
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    82
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    83
    CurrentFileInDirectoryQuerySignal isNil ifTrue:[
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    84
        CurrentFileInDirectoryQuerySignal := QuerySignal new.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    85
        CurrentFileInDirectoryQuerySignal nameClass:self message:#currentFileInDirectoryQuerySignal.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    86
        CurrentFileInDirectoryQuerySignal notifierString:'query for current directory when filing in'.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    87
        CurrentFileInDirectoryQuerySignal handlerBlock:[:ex | ex proceedWith:Filename currentDirectory].
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    88
    ].
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    89
    ^ CurrentFileInDirectoryQuerySignal
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    90
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    91
    "Modified: / 23-10-2006 / 16:34:37 / cg"
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    92
!
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    93
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    94
currentSourceContainerQuery
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    95
    "return the querySignal, which can be used to ask for the current source container filename
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    96
     during a fileIn 
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    97
     Using this, allows for the loaded code to remember the classes file name."
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    98
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    99
    CurrentSourceContainerQuery isNil ifTrue:[
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   100
        CurrentSourceContainerQuery := QuerySignal new.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   101
        CurrentSourceContainerQuery nameClass:self message:#currentClassFilenameQuery.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   102
        CurrentSourceContainerQuery notifierString:'query for current sorce container name when filing in'.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   103
        CurrentSourceContainerQuery handlerBlock:[:ex | ex proceedWith:nil].
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   104
    ].
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   105
    ^ CurrentSourceContainerQuery
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   106
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   107
    "Modified: / 23-10-2006 / 16:32:49 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   108
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   109
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   110
!PeekableStream class methodsFor:'queries'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   111
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   112
currentFileInDirectory
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   113
    "during a fileIn (if a script), the script can ask for the current directory"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   114
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   115
    ^ self currentFileInDirectoryQuerySignal query
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   116
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   117
    "Modified: / 23-10-2006 / 16:34:47 / cg"
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   118
!
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   119
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   120
currentSourceContainer
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   121
    "during a fileIn (if a script), the script can ask for the current filename"
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   122
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   123
    ^ self currentSourceContainerQuery query
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   124
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   125
    "Modified: / 23-10-2006 / 16:33:40 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   126
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   127
21033
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   128
!PeekableStream class methodsFor:'testing'!
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   129
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   130
isAbstract
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   131
    ^ self == PeekableStream
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   132
! !
c31725b2b658 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20128
diff changeset
   133
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   134
!PeekableStream methodsFor:'chunk input/output'!
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   135
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   136
nextChunk
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   137
    "return the next chunk, i.e. all characters up to the next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   138
     exclamation mark. Within the chunk, exclamation marks have to be doubled,
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   139
     they are undoubled here.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   140
     Except for primitive code, in which doubling is not needed (allowed).
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   141
     This exception was added to make it easier to edit primitive code with 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   142
     external editors. However, this means, that other Smalltalks cannot always 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   143
     read chunks containing primitive code 
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   144
     - but that doesn't really matter, since C-primitives are an ST/X feature anyway."
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   145
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   146
    |buffer theString chunkSeparator newString done thisChar nextChar 
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   147
     atBeginOfLine inPrimitive  hasCR hasLF
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   148
     index    "{ Class:SmallInteger }"
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   149
     currSize "{ Class:SmallInteger }" |
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   150
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   151
    chunkSeparator := ChunkSeparator.
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   152
    buffer := CharacterWriteStream on:(String new:100).
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   153
    self skipSeparators.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   154
    thisChar := self nextOrNil.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   155
    done := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   156
    atBeginOfLine := true.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   157
    inPrimitive := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   158
    hasCR := hasLF := false.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   159
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   160
    [done not and:[thisChar notNil]] whileTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   161
        "match primitive only at beginning of line 
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   162
         (ExternalStream>>#nextChunk did this, although stc allows primitive to start anywhere)"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   163
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   164
        (atBeginOfLine and:[thisChar == $%]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   165
            nextChar := self peekOrNil.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   166
            (nextChar == ${ ) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   167
                inPrimitive := true.
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   168
                buffer nextPut:thisChar.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   169
                thisChar := self next
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   170
            ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   171
                (nextChar == $} ) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   172
                    inPrimitive := false.
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   173
                    buffer nextPut:thisChar.
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   174
                    thisChar := self next
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   175
                ]
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   176
            ]
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   177
        ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   178
            "chunk can not end in primitive code"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   179
            (inPrimitive not and:[thisChar == chunkSeparator]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   180
                (self peekOrNil == chunkSeparator) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   181
                    "double chunkSeparator, make single"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   182
                    self next.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   183
                ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   184
                    "single chunkSeparator: end of chunk"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   185
                    done := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   186
                ].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   187
            ].
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   188
        ].
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   189
        done ifFalse:[
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   190
            "now map CR LF to LF (ExternalStream>>#nextChunk did this)"
10351
132061a1ad3f Fix %{ detection in #nextChunk
Stefan Vogel <sv@exept.de>
parents: 10347
diff changeset
   191
            atBeginOfLine := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   192
            thisChar == Character return ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   193
                self peekOrNil == Character lf ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   194
                    self next.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   195
                    thisChar := Character lf.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   196
                    hasLF := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   197
                ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   198
                    "CR without LF"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   199
                    hasCR := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   200
                ].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   201
                atBeginOfLine := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   202
            ] ifFalse:[thisChar == Character lf ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   203
                hasLF := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   204
                atBeginOfLine := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   205
            ]].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   206
                
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   207
            buffer nextPut:thisChar.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   208
            thisChar := self nextOrNil.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   209
        ].
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   210
    ].
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   211
18213
c0d479ac5af6 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17636
diff changeset
   212
    theString := buffer contents.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   213
    (hasCR and:[hasLF not]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   214
        "map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)"
19642
4f1dabe3a949 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19122
diff changeset
   215
        theString replaceAll:Character return with:Character nl.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   216
    ].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   217
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   218
    ^ theString
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   219
! !
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   220
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   221
!PeekableStream methodsFor:'fileIn'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   222
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   223
fileIn
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   224
    "file in from the receiver, i.e. read chunks and evaluate them -
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   225
     return the value of the last chunk."
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   226
15965
8e5396a9141f class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15120
diff changeset
   227
    |notifiedLoader lastValue|
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   228
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   229
    SourceFileLoader notNil ifTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   230
        notifiedLoader := SourceFileLoader on:self.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   231
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   232
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   233
    Class nameSpaceQuerySignal handle:[:ex |
12785
0198461e00c7 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 12783
diff changeset
   234
        ex proceedWith:Smalltalk
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   235
    ] do:[
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   236
        lastValue := self fileInNotifying:notifiedLoader passChunk:true.
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   237
    ].
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   238
    ^ lastValue.
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   239
!
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   240
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   241
fileInBinary
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   242
    "file in from the receiver, i.e. read binary stored classes and/or objects.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   243
     Return the last object."
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   244
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   245
    |bos obj|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   246
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   247
    bos := BinaryObjectStorage onOld:self.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   248
    Class nameSpaceQuerySignal 
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   249
	answer:Smalltalk
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   250
	do:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   251
	    [self atEnd] whileFalse:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   252
		obj := bos next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   253
	    ]
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   254
	].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   255
    bos close.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   256
    ^ obj
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   257
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   258
    "Created: / 13.11.2001 / 10:12:30 / cg"
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   259
    "Modified: / 13.11.2001 / 10:14:04 / cg"
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   260
! !
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   261
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   262
!PeekableStream methodsFor:'positioning'!
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   263
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   264
skipAny:skipCollection
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   265
    "skip all characters included in the argument-set.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   266
     returns the next peeked element or nil, if the end-of-stream was reached."
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   267
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   268
    |nextOne|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   269
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   270
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   271
    [nextOne notNil and:[skipCollection includes:nextOne]] whileTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   272
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   273
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   274
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   275
    ^ nextOne
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   276
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   277
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   278
     |s skipChars|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   279
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   280
     s := ReadStream on:'some numbers1234with\in other99 stuff' withCRs.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   281
     skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   282
     s skipAny:skipChars.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   283
     Transcript showCR:(Integer readFrom:s).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   284
     s skipAny:skipChars.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   285
     Transcript showCR:(Integer readFrom:s).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   286
    "
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   287
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   288
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   289
skipSeparators
16502
d80457997839 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16376
diff changeset
   290
    "skip all whitespace; 
d80457997839 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16376
diff changeset
   291
     return the next peeked element or nil, if the end-of-stream was reached.
d80457997839 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16376
diff changeset
   292
     The stream's elements should be characters.
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   293
     Notice: compare this method to skipSpaces"
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   294
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   295
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   296
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   297
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   298
    [nextOne notNil and:[nextOne isSeparator]] whileTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   299
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   300
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   301
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   302
    ^ nextOne
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   303
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   304
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   305
     |s|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   306
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   307
     s := ReadStream on:'one      two\three' withCRs.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   308
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   309
     Transcript showCR:(s nextWord).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   310
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   311
     Transcript showCR:(s nextWord).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   312
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   313
     Transcript showCR:(s next displayString).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   314
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   315
!
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   316
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   317
skipSeparatorsExceptCR
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   318
    "skip all whitespace except carriage return; returns the 
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   319
     next peeked element or nil, if the end-of-stream was reached.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   320
     The streams elements should be characters.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   321
     Notice: compare this method to skipSpaces and skipSeparators"
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   322
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   323
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   324
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   325
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   326
    [nextOne notNil 
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   327
     and:[nextOne isSeparator
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   328
     and:[nextOne ~~ Character cr]]] whileTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   329
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   330
        nextOne := self peekOrNil
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   331
    ].
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   332
    ^ nextOne
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   333
!
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   334
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   335
skipSpaces
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   336
    "skip all spaces; returns the next peeked element or
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   337
     nil, if the end-of-stream was reached.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   338
     The streams elements should be characters.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   339
     Notice: this one skips only spaces (i.e. no cr, tabs etc)
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   340
             usually, skipSeparators is what you want."
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   341
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   342
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   343
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   344
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   345
    [nextOne notNil and:[nextOne == Character space]] whileTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   346
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   347
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   348
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   349
    ^ nextOne
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   350
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   351
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   352
     |s|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   353
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   354
     s := ReadStream on:'one      two\three' withCRs.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   355
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   356
     Transcript showCR:(s nextWord).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   357
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   358
     Transcript showCR:(s nextWord).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   359
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   360
     Transcript showCR:(s next displayString).
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   361
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   362
! !
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   363
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   364
!PeekableStream methodsFor:'private fileIn'!
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   365
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   366
basicFileInNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   367
    "central method to file in from the receiver, i.e. read chunks and evaluate them -
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   368
     return the value of the last chunk.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   369
     Someone (which is usually some codeView) is notified of errors."
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   370
15965
8e5396a9141f class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15120
diff changeset
   371
     ^(EncodedStream decodedStreamFor:self) basicFileInNotifying:someone passChunk:passChunk
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   372
15965
8e5396a9141f class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15120
diff changeset
   373
    "Modified: / 10-09-1999 / 16:54:01 / stefan"
8e5396a9141f class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15120
diff changeset
   374
    "Modified: / 16-11-2001 / 16:21:28 / cg"
8e5396a9141f class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15120
diff changeset
   375
    "Modified: / 25-03-2013 / 22:57:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   376
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   377
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   378
fileInNextChunkNotifying:someone
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   379
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   380
     someone (which is usually some codeView) is notified of errors.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   381
     Filein is done as follows:
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   382
	read a chunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   383
	if it started with an excla, evaluate it, and let the resulting object
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   384
	fileIn more chunks.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   385
	This is a nice trick, since the methodsFor: expression evaluates to
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   386
	a ClassCategoryReader which reads and compiles chunks for its class.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   387
	However, other than methodsFor expressions are possible - you can
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   388
	(in theory) create readers for any syntax.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   389
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   390
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   391
    ^ self fileInNextChunkNotifying:someone passChunk:false
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   392
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   393
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   394
fileInNextChunkNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   395
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   396
     someone (which is usually some codeView) is notified of errors.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   397
     Filein is done as follows:
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   398
	read a chunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   399
	if it started with an excla, evaluate it, and let the resulting object
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   400
	fileIn more chunks.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   401
	This is a nice trick, since the methodsFor: expression evaluates to
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   402
	a ClassCategoryReader which reads and compiles chunks for its class.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   403
	However, other than methodsFor expressions are possible - you can
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   404
	(in theory) create readers for any syntax.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   405
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   406
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   407
    ^ self fileInNextChunkNotifying:someone passChunk:passChunk silent:nil
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   408
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   409
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   410
fileInNextChunkNotifying:someone passChunk:passChunk silent:beSilent
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   411
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   412
     someone (which is usually some codeView) is notified of errors.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   413
     Filein is done as follows:
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   414
        read a chunk
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   415
        if it started with an excla, evaluate it, and let the resulting object
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   416
        fileIn more chunks.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   417
        This is a nice trick, since the methodsFor: expression evaluates to
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   418
        a ClassCategoryReader which reads and compiles chunks for its class.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   419
        However, other than methodsFor expressions are possible - you can
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   420
        (in theory) create readers for any syntax.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   421
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   422
19122
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   423
    |aString sawExcla rslt done compiler lastClass|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   424
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   425
    self skipSeparators.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   426
    self atEnd ifFalse:[
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   427
        sawExcla := self peekFor:(self class chunkSeparator).
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   428
        aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   429
        "/
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   430
        "/ handle empty chunks;
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   431
        "/ this allows for Squeak code to be filedIn
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   432
        "/
19122
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   433
        [aString size == 0 and:[self atEnd not]] whileTrue:[
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   434
            aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   435
        ].
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   436
        aString size ~~ 0 ifTrue:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   437
            passChunk ifTrue:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   438
                someone notNil ifTrue:[someone source:aString]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   439
            ].
17636
b1f2d32a9931 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17560
diff changeset
   440
            someone perform:#reader: with:(SourceFileLoader::SourceFileReader new) ifNotUnderstood:[].
18877
9c305830c1ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18479
diff changeset
   441
            compiler := (Smalltalk at:#Compiler) new.
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   442
            compiler allowUndeclaredVariables:false.
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   443
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   444
            sawExcla ifFalse:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   445
                "/ class definition chunks, etc., which are simply evaluated
17636
b1f2d32a9931 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 17560
diff changeset
   446
                rslt := compiler evaluate:aString receiver:someone notifying:someone compile:false.
19122
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   447
                rslt isBehavior ifTrue:[ 
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   448
                    lastClass := rslt 
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   449
                ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   450
                    lastClass := nil 
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   451
                ].
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   452
            ] ifTrue:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   453
                "/ methodsFor chunks, etc., which generate a reader
18877
9c305830c1ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18479
diff changeset
   454
                (Smalltalk at:#Compiler) emptySourceNotificationSignal handle:[:ex |
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   455
                    ^ nil
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   456
                ] do:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   457
                    rslt := compiler 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   458
                                evaluate:aString 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   459
                                notifying:someone 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   460
                                compile:false.
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   461
                ].
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   462
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   463
                "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   464
                 usually, the above chunk consists of some methodsFor:-expression
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   465
                 in this case, the returned value is a ClassCategoryReader,
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   466
                 which is used to load & compile the methods ...
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   467
                "
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   468
                (rslt isNil or:[rslt == #Error]) ifTrue:[
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   469
                    "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   470
                     however, if that was nil (i.e. some error), we skip chunks
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   471
                     up to the next empty chunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   472
                    "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   473
                    Transcript showCR:'skipping chunks ...'.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   474
                    done := false.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   475
                    [done] whileFalse:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   476
                        aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   477
                        done := (aString size == 0).
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   478
                    ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   479
                ] ifFalse:[
19122
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   480
                    Class packageQuerySignal handle:[:ex |
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   481
                        lastClass notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   482
                            ex proceedWith:lastClass package
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   483
                        ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   484
                            ex reject
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   485
                        ].    
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   486
                    ] do:[    
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   487
                        rslt := rslt 
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   488
                                fileInFrom:self 
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   489
                                notifying:someone 
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   490
                                passChunk:passChunk
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   491
                                single:false
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   492
                                silent:beSilent
19122
Claus Gittinger <cg@exept.de>
parents: 18877
diff changeset
   493
                    ].            
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   494
                ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   495
            ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   496
        ]
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   497
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   498
    ^ rslt
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   499
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   500
    "Modified: / 05-02-2011 / 10:06:57 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   501
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   502
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   503
fileInNotifying:notifiedLoader passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   504
    "central method to file in from the receiver, i.e. read chunks and evaluate them -
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   505
     return the value of the last chunk.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   506
     Someone (which is usually some codeView) is notified of errors."
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   507
10394
485f6c2d8db0 Do not refer to non-existant aspect
Stefan Vogel <sv@exept.de>
parents: 10356
diff changeset
   508
    ^ self basicFileInNotifying:notifiedLoader passChunk:passChunk.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   509
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   510
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   511
fileInXMLNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   512
    "filein an XML source file (format as in campSmalltalk DTD)"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   513
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   514
    | builder parser|
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   515
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   516
    (XML isNil or:[XML::SourceNodeBuilder isNil or:[XML::XMLParser isNil]]) ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   517
	Smalltalk loadPackage:'stx:goodies/xml/vw'.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   518
	(XML isNil or:[XML::SourceNodeBuilder isNil or:[XML::XMLParser isNil]]) ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   519
	    self error:'Could not load XML package(s) from ''stx:goodies/xml/vw'''.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   520
	]
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   521
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   522
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   523
    builder := XML::SourceNodeBuilder new.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   524
    parser := XML::XMLParser on:self.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   525
    parser builder:builder.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   526
    parser validate:false.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   527
    parser scanDocument.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   528
    "/ self halt.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   529
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   530
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   531
!PeekableStream methodsFor:'reading'!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   532
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   533
nextDecimalInteger
16883
3a1d9376ec32 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16609
diff changeset
   534
    "read the next integer in radix 10. 
3a1d9376ec32 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16609
diff changeset
   535
     Does NOT skip initial whitespace.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   536
     The streams elements should be characters.
16883
3a1d9376ec32 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16609
diff changeset
   537
3a1d9376ec32 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16609
diff changeset
   538
     Be careful - this method returns 0 if not positioned on a digit intitially
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   539
     or if the end of the stream is encountered."
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   540
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   541
    |nextOne value|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   542
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   543
    nextOne := self peekOrNil.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   544
    value := 0.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   545
    [nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   546
        value := (value * 10) + nextOne digitValue.
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   547
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   548
        nextOne := self peekOrNil
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   549
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   550
    ^ value
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   551
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   552
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   553
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   554
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   555
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   556
     s nextDecimalInteger. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   557
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   558
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   559
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   560
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   561
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   562
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   563
     s nextDecimalInteger.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   564
     s skipSpaces.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   565
     s nextDecimalInteger. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   566
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   567
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   568
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   569
nextDelimited:terminator
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   570
    "return the contents of the receiver, up to the next terminator character. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   571
     Doubled terminators indicate an embedded terminator character.  
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   572
     For example: 'this '' was a quote'. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   573
     Start postioned before the initial terminator."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   574
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   575
    | out ch |
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   576
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   577
    self atEnd ifTrue: [^ ''].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   578
    self next == terminator ifFalse: [self skip: -1].       "absorb initial terminator"
18273
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   579
    out := WriteStream on:(self contentsSpecies new).
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   580
    [(ch := self next) == nil] whileFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   581
        (ch == terminator) ifTrue: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   582
            self peek == terminator ifFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   583
                ^ out contents  "terminator is not doubled; we're done!!"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   584
            ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   585
            self next.  "skip doubled terminator"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   586
        ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   587
        out nextPut: ch.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   588
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   589
    ^ out contents
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   590
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   591
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   592
     ('*foo bar baz* more foo' readStream nextDelimited:$*) 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   593
     ('*foo bar **baz***' readStream nextDelimited:$*)   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   594
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   595
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   596
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   597
nextPeek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   598
    "advance to next element and return the peeked element"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   599
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   600
    self next.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   601
    ^ self peek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   602
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   603
20128
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   604
nextPeekOrNil
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   605
    "advance to next element and return the peeked element"
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   606
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   607
    self nextOrNil.
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   608
    ^ self peekOrNil
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   609
!
a9a3a8af994f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19642
diff changeset
   610
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   611
nextUpTo:anObject
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   612
    "read a collection of all objects up-to anObject and return these
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   613
     elements, but excluding anObject. 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   614
     The next read operation will return anObject.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   615
     If anObject is not encountered, all elements up to the end are read
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   616
     and returned, and the stream is positioned at the end.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   617
     Compare this with #upTo: which positions behind anObject"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   618
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   619
    |answerStream element|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   620
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   621
    answerStream := WriteStream on:(self contentsSpecies new).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   622
    [self atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   623
	element := self peek.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   624
	(element = anObject) ifTrue: [
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   625
	    ^ answerStream contents
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   626
	].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   627
	answerStream nextPut:element.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   628
	self next.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   629
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   630
    ^ answerStream contents
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   631
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   632
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   633
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   634
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   635
     Transcript showCR:(s nextUpTo:4).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   636
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   637
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   638
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   639
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   640
     Transcript showCR:(s upTo:4).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   641
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   642
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   643
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   644
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   645
     Transcript showCR:(s nextUpTo:9).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   646
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   647
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   648
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   649
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   650
     Transcript showCR:(s upTo:9).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   651
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   652
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   653
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   654
    "Created: 24.1.1997 / 14:08:35 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   655
    "Modified: 24.1.1997 / 14:09:49 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   656
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   657
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   658
peek 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   659
    "return the next element of the stream without advancing (i.e.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   660
     the following send of next will return this element again.)
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   661
     - we do not know here how to do it, it must be redefined in subclass"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   662
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   663
    ^ self subclassResponsibility
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   664
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   665
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   666
peekFor:anObject 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   667
    "if the next-to-be-read object is equal to the argument, anObject, read it
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   668
     and return true. Otherwise, leave the receiver unaffected and return false."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   669
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   670
    self peek = anObject ifTrue:[
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   671
        self nextOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   672
        ^ true
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   673
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   674
    ^ false
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   675
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   676
    "
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   677
      #() readStream peekFor:nil
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   678
      #() readStream signalAtEnd:true; peekFor:nil
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   679
      #(nil) readStream peekFor:nil
18479
edff93c290bb class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 18273
diff changeset
   680
      'abc' readStream next; peekFor:$b.
edff93c290bb class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 18273
diff changeset
   681
      'abc' readStream next; peekFor:$c.
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   682
    "
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   683
!
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   684
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   685
peekOrNil
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   686
    "like #peek, this returns the next readAhead element, if available.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   687
     However, unlike #peek, this does not raise an atEnd-query signal - even
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   688
     if handled. Instead, nil is returned immediately."
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   689
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   690
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   691
    ^ self peek
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   692
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   693
    "Created: / 5.3.1998 / 02:56:49 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   694
    "Modified: / 5.3.1998 / 13:45:07 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   695
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   696
11139
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   697
throughAnyForWhich:checkBlock
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   698
    "read & return a collection of all objects up-to and including 
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   699
     the elements for which checkBlock returns true.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   700
     (i.e. read until checkBlock returns false on an element)
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   701
     If no such element is encountered, all elements up to the end are read
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   702
     and returned."
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   703
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   704
    |answerStream element|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   705
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   706
    answerStream := WriteStream on:(self contentsSpecies new).
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   707
    [self atEnd] whileFalse:[
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   708
        element := self peek.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   709
        (checkBlock value:element) ifFalse:[
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   710
            ^ answerStream contents
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   711
        ].
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   712
        answerStream nextPut:element.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   713
        self next.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   714
    ].
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   715
    ^ answerStream contents
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   716
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   717
    "
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   718
     |s|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   719
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   720
     Transcript showCR:(s throughAny:#(3 4 5)).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   721
     Transcript showCR:s next
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   722
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   723
     |s|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   724
     s := ReadStream on:'hello world, this is some text'.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   725
     Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   726
     Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   727
     Transcript showCR:s upToEnd.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   728
    "
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   729
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   730
    "Modified: / 11.1.1998 / 15:28:04 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   731
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
   732
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   733
!PeekableStream methodsFor:'reading-strings'!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   734
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   735
nextAlphaNumericWord
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   736
    "read the next word (i.e. up to non letter-or-digit).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   737
     Return a string containing those characters.
18273
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   738
     Any leading non-alphaNumeric chars are skipped.
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   739
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   740
     National letters or digits in unicode are not treated as letters."
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   741
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   742
    |s c|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   743
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   744
    "first: skip white space and other garbage, leave first character in c"
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   745
    [
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   746
        c := self nextOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   747
        c isNil ifTrue:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   748
            "end of stream"
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   749
            ^ nil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   750
        ].
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   751
        c isLetterOrDigit
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   752
    ] whileFalse.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   753
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   754
    "second: get the alphanumeric word"
18273
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   755
    s := WriteStream on:(self contentsSpecies new:100).
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   756
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   757
    [
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   758
        s nextPut:c.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   759
        c := self peekOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   760
        (c notNil and:[c isLetterOrDigit]) ifTrue:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   761
            self next.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   762
            true.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   763
        ] ifFalse:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   764
            false.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   765
        ]
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   766
    ] whileTrue.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   767
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   768
    ^ s contents.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   769
18273
7f1f1a4eef6b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 18213
diff changeset
   770
    "Use UnicodeString in the examples, to avoid the optimization in ReadStream for Strings"
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   771
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   772
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   773
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   774
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   775
     s := 'hello world 1234 foo1 foo2' asUnicodeString readStream.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   776
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   777
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   778
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   779
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   780
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   781
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   782
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   783
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   784
     s := 'hello +++ #world ###123###abc### 1234 foo1 foo2++++' asUnicodeString readStream.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   785
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   786
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   787
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   788
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   789
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   790
    "Modified: 15.5.1996 / 17:51:42 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   791
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   792
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   793
nextMatching:matchBlock1 thenMatching:matchBlock2
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   794
    "read the next word. The first character must match matchBlock1,
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   795
     remaining characters must match matchBlock2.
16376
f96538a5ea67 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16375
diff changeset
   796
     Return a string containing those characters.
f96538a5ea67 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16375
diff changeset
   797
     Useful to read identifiers, where the first char is from a different
f96538a5ea67 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 16375
diff changeset
   798
     set than the remaining (letter vs. letterOrDigit)"
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   799
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   800
    |s c|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   801
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   802
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   803
    (matchBlock1 value:self peek) ifFalse:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   804
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   805
    s := self next asString.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   806
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   807
    [self atEnd not
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   808
     and:[matchBlock2 value:(c := self peek)]] whileTrue:[ 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   809
        s := s copyWith:c. 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   810
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   811
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   812
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   813
    s size == 0 ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   814
    ^ s.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   815
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   816
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   817
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   818
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   819
     s := 'hello_world_1234 foo1 foo2' readStream.
16375
340f80bcd892 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15965
diff changeset
   820
     s nextMatching:[:c | c isLetter] 
340f80bcd892 class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 15965
diff changeset
   821
       thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   822
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   823
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   824
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   825
nextSymbol
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   826
    "read the next selector-symbol (i.e. up to non letter-or-digit).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   827
     Return a string containing those characters.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   828
     Any leading non-alphaNumeric chars are skipped."
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   829
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   830
    |symbol c symbolStream|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   831
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   832
    [self atEnd
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   833
     or:[(c := self peek) isLetterOrDigit]] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   834
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   835
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   836
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   837
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   838
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   839
    symbolStream := '' writeStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   840
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   841
    [self atEnd not
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   842
     and:[(c := self peek) isLetterOrDigit or:[c == $:]]] whileTrue:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   843
        symbolStream nextPut:c.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   844
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   845
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   846
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   847
    symbol := symbolStream contents.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   848
    symbol size == 0 ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   849
    ^ symbol.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   850
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   851
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   852
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   853
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   854
     s := 'hello: world 1234 foo1 foo2:' readStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   855
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   856
        Transcript showCR:(s nextSymbol).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   857
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   858
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   859
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   860
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   861
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   862
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   863
     s := 'hello +++ #world ###123###abc### 1234 foo1 foo2' readStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   864
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   865
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   866
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   867
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   868
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   869
    "Modified: 15.5.1996 / 17:51:42 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   870
! !
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   871
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   872
!PeekableStream class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   873
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   874
version
18479
edff93c290bb class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 18273
diff changeset
   875
    ^ '$Header$'
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   876
!
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   877
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   878
version_CVS
18479
edff93c290bb class: PeekableStream
Claus Gittinger <cg@exept.de>
parents: 18273
diff changeset
   879
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   880
! !
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   881
14900
4279d13fca9b class: PeekableStream
Stefan Vogel <sv@exept.de>
parents: 14517
diff changeset
   882
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   883
PeekableStream initialize!