PeekableStream.st
author Claus Gittinger <cg@exept.de>
Sat, 05 Feb 2011 11:40:33 +0100
changeset 13282 9b8542c8439e
parent 12785 0198461e00c7
child 14517 8650f504ca60
permissions -rw-r--r--
changed: #fileInNextChunkNotifying:passChunk:silent: do not allow undefined globals when filing in
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
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    14
Stream subclass:#PeekableStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    15
	instanceVariableNames:''
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    16
	classVariableNames:'ErrorDuringFileInSignal CurrentFileInDirectoryQuerySignal
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    17
		CurrentSourceContainerQuery'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    18
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	category:'Streams'
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    20
!
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
!PeekableStream class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
379
5b5a130ccd09 revision added
claus
parents: 369
diff changeset
    27
	      All Rights Reserved
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    abstract superclass for all Stream which support read-ahead
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    (i.e. peeking) of one element.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    Concrete subclasses must implement a peek method.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    43
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    44
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    45
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    48
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    49
!PeekableStream class methodsFor:'initialization'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    50
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    51
initialize
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    52
    "setup the signal used to handle errors during fileIn"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    53
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    54
    ErrorDuringFileInSignal isNil ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    55
        ErrorDuringFileInSignal := Error newSignalMayProceed:true.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    56
        ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    57
        ErrorDuringFileInSignal notifierString:'error during fileIn'.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    58
    ]
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    59
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
     self initialize
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    62
    "
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    63
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    64
    "Modified: / 23-10-2006 / 16:34:41 / cg"
8443
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
!PeekableStream class methodsFor:'Signal constants'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    68
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    69
currentFileInDirectoryQuerySignal
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    70
    "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
    71
     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
    72
     and in a fileBrowsers doIt.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    73
     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
    74
     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
    75
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    76
    CurrentFileInDirectoryQuerySignal isNil ifTrue:[
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    77
        CurrentFileInDirectoryQuerySignal := QuerySignal new.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    78
        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
    79
        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
    80
        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
    81
    ].
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
    82
    ^ CurrentFileInDirectoryQuerySignal
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    83
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    84
    "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
    85
!
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    86
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    87
currentSourceContainerQuery
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    88
    "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
    89
     during a fileIn 
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    90
     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
    91
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    92
    CurrentSourceContainerQuery isNil ifTrue:[
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    93
        CurrentSourceContainerQuery := QuerySignal new.
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    94
        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
    95
        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
    96
        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
    97
    ].
10002
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
    98
    ^ CurrentSourceContainerQuery
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
    99
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   100
    "Modified: / 23-10-2006 / 16:32:49 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   101
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   102
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   103
!PeekableStream class methodsFor:'queries'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   104
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   105
currentFileInDirectory
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   106
    "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
   107
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   108
    ^ self currentFileInDirectoryQuerySignal query
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   109
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   110
    "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
   111
!
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   112
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   113
currentSourceContainer
3a70c4f5afe0 Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents: 9356
diff changeset
   114
    "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
   115
10120
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   116
    ^ self currentSourceContainerQuery query
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   117
cc81848112f4 allow for currentFileInQueries to be used BEFORE the class is initialized
Claus Gittinger <cg@exept.de>
parents: 10002
diff changeset
   118
    "Modified: / 23-10-2006 / 16:33:40 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   119
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   120
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   121
!PeekableStream methodsFor:'chunk input/output'!
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   122
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   123
nextChunk
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   124
    "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
   125
     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
   126
     they are undoubled here.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   127
     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
   128
     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
   129
     external editors. However, this means, that other Smalltalks cannot always 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   130
     read chunks containing primitive code 
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   131
     - 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
   132
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   133
    |theString chunkSeparator newString done thisChar nextChar 
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   134
     atBeginOfLine inPrimitive  hasCR hasLF
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   135
     index    "{ Class:SmallInteger }"
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   136
     currSize "{ Class:SmallInteger }" |
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   137
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   138
    chunkSeparator := ChunkSeparator.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   139
    currSize := 500.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   140
    theString := String new:currSize.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   141
    self skipSeparators.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   142
    thisChar := self nextOrNil.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   143
    index := 0.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   144
    done := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   145
    atBeginOfLine := true.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   146
    inPrimitive := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   147
    hasCR := hasLF := false.
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   148
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   149
    [done not and:[thisChar notNil]] whileTrue:[
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   150
        ((index + 2) <= currSize) ifFalse:[
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   151
            newString := String new:(currSize * 2).
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   152
            newString replaceFrom:1 to:currSize with:theString.
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   153
            currSize := currSize * 2.
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   154
            theString := newString
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   155
        ].
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   156
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   157
        "match primitive only at beginning of line 
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   158
         (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
   159
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   160
        (atBeginOfLine and:[thisChar == $%]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   161
            nextChar := self peekOrNil.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   162
            (nextChar == ${ ) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   163
                inPrimitive := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   164
                index := index + 1.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   165
                theString at:index put:thisChar.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   166
                thisChar := self next
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   167
            ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   168
                (nextChar == $} ) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   169
                    inPrimitive := false.
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   170
                    index := index + 1.
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   171
                    theString at:index put:thisChar.
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   172
                    thisChar := self next
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   173
                ]
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   174
            ]
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   175
        ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   176
            "chunk can not end in primitive code"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   177
            (inPrimitive not and:[thisChar == chunkSeparator]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   178
                (self peekOrNil == chunkSeparator) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   179
                    "double chunkSeparator, make single"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   180
                    self next.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   181
                ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   182
                    "single chunkSeparator: end of chunk"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   183
                    done := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   184
                ].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   185
            ].
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   186
        ].
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   187
        done ifFalse:[
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   188
            "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
   189
            atBeginOfLine := false.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   190
            thisChar == Character return ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   191
                self peekOrNil == Character lf ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   192
                    self next.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   193
                    thisChar := Character lf.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   194
                    hasLF := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   195
                ] ifFalse:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   196
                    "CR without LF"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   197
                    hasCR := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   198
                ].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   199
                atBeginOfLine := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   200
            ] ifFalse:[thisChar == Character lf ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   201
                hasLF := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   202
                atBeginOfLine := true.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   203
            ]].
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   204
                
8192
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   205
            index := index + 1.
ade8d06d98eb *** empty log message ***
ca
parents: 7685
diff changeset
   206
            theString at:index put:thisChar.
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   207
            thisChar := self nextOrNil.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   208
        ].
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   209
    ].
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   210
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   211
    (index == 0) ifTrue:[^ ''].
10347
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   212
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   213
    theString := theString copyTo:index.
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   214
    (hasCR and:[hasLF not]) ifTrue:[
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   215
        "map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)"
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   216
        theString replaceAll:Character cr with:Character nl.
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
0d5ca408160f #nextChunk - same behavior as in ExternalStream>>#nextChunk
Stefan Vogel <sv@exept.de>
parents: 10120
diff changeset
   219
    ^ theString
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   220
! !
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   221
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   222
!PeekableStream methodsFor:'fileIn'!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   223
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   224
fileIn
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   225
    "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
   226
     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
   227
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   228
    |notifiedLoader lastValue|
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   229
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   230
    SourceFileLoader notNil ifTrue:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   231
        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
   232
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   233
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   234
    Class nameSpaceQuerySignal handle:[:ex |
12785
0198461e00c7 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 12783
diff changeset
   235
        ex proceedWith:Smalltalk
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   236
    ] do:[
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   237
        lastValue := self fileInNotifying:notifiedLoader passChunk:true.
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   238
    ].
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
   239
    ^ lastValue.
8867
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
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   242
fileInBinary
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   243
    "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
   244
     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
   245
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   246
    |bos obj|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   247
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   248
    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
   249
    Class nameSpaceQuerySignal 
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   250
	answer:Smalltalk
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   251
	do:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   252
	    [self atEnd] whileFalse:[
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   253
		obj := bos next.
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
	].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   256
    bos close.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   257
    ^ obj
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   258
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   259
    "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
   260
    "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
   261
! !
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   262
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   263
!PeekableStream methodsFor:'positioning'!
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   264
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   265
skipAny:skipCollection
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   266
    "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
   267
     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
   268
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   269
    |nextOne|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   270
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   271
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   272
    [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
   273
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   274
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   275
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   276
    ^ nextOne
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
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   279
     |s skipChars|
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   280
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   281
     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
   282
     skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   283
     s skipAny:skipChars.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   284
     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
   285
     s skipAny:skipChars.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   286
     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
   287
    "
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   288
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   289
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   290
skipSeparators
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   291
    "skip all whitespace; 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
   292
     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
   293
     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
   294
     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
   295
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   296
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   297
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   298
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   299
    [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
   300
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   301
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   302
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   303
    ^ nextOne
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
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   306
     |s|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   307
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   308
     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
   309
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   310
     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
   311
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   312
     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
   313
     s skipSeparators.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   314
     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
   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
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   318
skipSeparatorsExceptCR
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   319
    "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
   320
     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
   321
     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
   322
     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
   323
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   324
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   325
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   326
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   327
    [nextOne notNil 
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   328
     and:[nextOne isSeparator
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   329
     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
   330
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   331
        nextOne := self peekOrNil
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   332
    ].
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   333
    ^ nextOne
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
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   336
skipSpaces
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   337
    "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
   338
     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
   339
     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
   340
     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
   341
             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
   342
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   343
    |nextOne|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   344
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   345
    nextOne := self peekOrNil.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   346
    [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
   347
        self next.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   348
        nextOne := self peekOrNil
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   349
    ].
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   350
    ^ nextOne
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
    "
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   353
     |s|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   354
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   355
     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
   356
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   357
     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
   358
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   359
     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
   360
     s skipSpaces.
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   361
     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
   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
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   365
!PeekableStream methodsFor:'private fileIn'!
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   366
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   367
basicFileInNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   368
    "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
   369
     return the value of the last chunk.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   370
     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
   371
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   372
    |lastValue pkg nameSpace usedNameSpaces
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   373
     packageQuerySignal nameSpaceQuerySignal usedNameSpaceQuerySignal
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   374
     changeDefaultApplicationNotificationSignal
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   375
     defaultApplicationQuerySignal defaultApplication
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   376
     confirmationQuerySignal handledSignals passedSignals askSomeoneForPackage outerContext|
8443
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
    self skipSeparators.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   379
    lastValue := self peek.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   380
    lastValue == $< ifTrue:[
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   381
        "/ assume, it's an xml file
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   382
        ^ self fileInXMLNotifying:someone passChunk:passChunk.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   383
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   384
    lastValue == $# ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   385
        "assume unix interpreter name:
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   386
         '#!!stx -e' or something like this"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   387
        self nextPeek == $!! ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   388
            "skip the unix command line"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   389
            self nextLine
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   390
        ] ifFalse:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   391
             self error:'Invalid chunk start'
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
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   395
    Smalltalk::Compiler isNil ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   396
        self isFileStream ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   397
            Transcript show:('[' , self pathName , '] ').
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   398
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   399
        Transcript showCR:'cannot fileIn (no compiler).'.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   400
        ^ nil.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   401
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   402
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   403
    "/ support for V'Age applications
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   404
    defaultApplicationQuerySignal := Class defaultApplicationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   405
    changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   406
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   407
    "/ support for ST/X's nameSpaces & packages
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   408
    packageQuerySignal := Class packageQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   409
    nameSpaceQuerySignal := Class nameSpaceQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   410
    usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   411
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   412
    (someone respondsTo:#packageToInstall) ifTrue:[
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   413
        pkg := someone packageToInstall.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   414
        askSomeoneForPackage := true.
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   415
    ] ifFalse:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   416
        pkg := packageQuerySignal query.
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   417
        askSomeoneForPackage := false.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   418
    ].
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   419
    (someone respondsTo:#currentNameSpace) ifTrue:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   420
        nameSpace := someone currentNameSpace
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   421
    ] ifFalse:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   422
        nameSpace := nameSpaceQuerySignal query.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   423
    ].
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   424
    (someone respondsTo:#usedNameSpaces) ifTrue:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   425
        usedNameSpaces := someone usedNameSpaces
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   426
    ] ifFalse:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   427
        usedNameSpaces := usedNameSpaceQuerySignal query.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   428
    ].
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   429
    (someone respondsTo:#defaultApplication) ifTrue:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   430
        defaultApplication := someone defaultApplication
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   431
    ] ifFalse:[
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   432
        defaultApplication := defaultApplicationQuerySignal query.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   433
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   434
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   435
    confirmationQuerySignal := Metaclass confirmationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   436
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   437
    handledSignals := SignalSet new.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   438
    passedSignals := IdentitySet new.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   439
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   440
    handledSignals add:changeDefaultApplicationNotificationSignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   441
    passedSignals add:changeDefaultApplicationNotificationSignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   442
    handledSignals add:defaultApplicationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   443
    passedSignals add:defaultApplicationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   444
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   445
    handledSignals add:packageQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   446
    handledSignals add:usedNameSpaceQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   447
    handledSignals add:nameSpaceQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   448
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   449
    handledSignals add:confirmationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   450
    passedSignals add:confirmationQuerySignal.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   451
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   452
    outerContext := thisContext.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   453
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   454
    handledSignals handle:[:ex |
8867
436f86af36df Do not pop up dialogs on PackageRedefinitions when doing a fileIn
Stefan Vogel <sv@exept.de>
parents: 8719
diff changeset
   455
        |sig|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   456
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   457
        sig := ex signal.
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   458
        ((passedSignals includes:sig) and:[sig isHandledIn:outerContext]) ifTrue:[
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   459
            ex reject
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   460
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   461
        
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   462
        sig == changeDefaultApplicationNotificationSignal ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   463
            "/ invoked via #becomeDefault to set the defaultApp and the package.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   464
            "/ (only when filing in V'Age code)
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   465
            defaultApplication := ex parameter.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   466
            pkg := defaultApplication name asSymbol.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   467
            ex proceedWith:nil
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   468
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   469
        sig == defaultApplicationQuerySignal ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   470
            "/ query for the application to add classes & methods into
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   471
            "/ (only when filing in V'Age code)
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   472
            ex proceedWith:defaultApplication
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   473
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   474
        sig == packageQuerySignal ifTrue:[
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   475
            "answer the package to use for classes & methods"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   476
            askSomeoneForPackage ifTrue:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   477
                ex proceedWith:someone packageToInstall
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   478
            ] ifFalse:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   479
                ex proceedWith:pkg
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   480
            ]
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   481
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   482
        sig == usedNameSpaceQuerySignal ifTrue:[
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   483
            "answer the nameSpaces to be searched when encountering globals"
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   484
            ex proceedWith:usedNameSpaces
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   485
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   486
        sig == nameSpaceQuerySignal ifTrue:[
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   487
            "answer the nameSpace to install new classes in"
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   488
            ex proceedWith:nameSpace
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   489
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   490
        sig == confirmationQuerySignal ifTrue:[
8485
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   491
            "don't pop up dialogs"
d94728eaf4f0 Use access methods for oldPackage and newPackage in notifications.
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   492
            ex proceedWith:false
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   493
        ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   494
    ] do:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   495
        [self atEnd] whileFalse:[
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   496
            lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk
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
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   499
    ^ lastValue
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   500
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   501
    "Modified: / 10.9.1999 / 16:54:01 / stefan"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   502
    "Modified: / 16.11.2001 / 16:21:28 / cg"
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   503
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   504
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   505
fileInNextChunkNotifying:someone
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   506
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   507
     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
   508
     Filein is done as follows:
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   509
	read a chunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   510
	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
   511
	fileIn more chunks.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   512
	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
   513
	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
   514
	However, other than methodsFor expressions are possible - you can
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   515
	(in theory) create readers for any syntax.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   516
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   517
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   518
    ^ self fileInNextChunkNotifying:someone passChunk:false
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   519
!
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
fileInNextChunkNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   522
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   523
     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
   524
     Filein is done as follows:
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   525
	read a chunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   526
	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
   527
	fileIn more chunks.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   528
	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
   529
	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
   530
	However, other than methodsFor expressions are possible - you can
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   531
	(in theory) create readers for any syntax.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   532
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   533
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   534
    ^ self fileInNextChunkNotifying:someone passChunk:passChunk silent:nil
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   535
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   536
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   537
fileInNextChunkNotifying:someone passChunk:passChunk silent:beSilent
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   538
    "read next chunk, evaluate it and return the result;
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   539
     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
   540
     Filein is done as follows:
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   541
        read a chunk
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   542
        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
   543
        fileIn more chunks.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   544
        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
   545
        a ClassCategoryReader which reads and compiles chunks for its class.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   546
        However, other than methodsFor expressions are possible - you can
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   547
        (in theory) create readers for any syntax.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   548
    "
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   549
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   550
    |aString sawExcla rslt done compiler|
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   551
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   552
    self skipSeparators.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   553
    self atEnd ifFalse:[
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   554
        sawExcla := self peekFor:(self class chunkSeparator).
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   555
        aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   556
        "/
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   557
        "/ handle empty chunks;
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   558
        "/ this allows for Squeak code to be filedIn
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   559
        "/
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   560
        [aString size == 0
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   561
        and:[self atEnd not]] whileTrue:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   562
            aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   563
        ].
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   564
        aString size ~~ 0 ifTrue:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   565
            passChunk ifTrue:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   566
                someone notNil ifTrue:[someone source:aString]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   567
            ].
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   568
            compiler := Smalltalk::Compiler new.
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   569
            compiler allowUndeclaredVariables:false.
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   570
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   571
            sawExcla ifFalse:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   572
                "/ class definition chunks, etc., which are simply evaluated
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   573
                rslt := compiler evaluate:aString notifying:someone.
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   574
            ] ifTrue:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   575
                "/ methodsFor chunks, etc., which generate a reader
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   576
                Smalltalk::Compiler emptySourceNotificationSignal handle:[:ex |
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   577
                    ^ nil
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   578
                ] do:[
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   579
                    rslt := compiler 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   580
                                evaluate:aString 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   581
                                notifying:someone 
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   582
                                compile:false.
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   583
                ].
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   584
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   585
                "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   586
                 usually, the above chunk consists of some methodsFor:-expression
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   587
                 in this case, the returned value is a ClassCategoryReader,
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   588
                 which is used to load & compile the methods ...
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   589
                "
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   590
                (rslt isNil or:[rslt == #Error]) ifTrue:[
11497
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   591
                    "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   592
                     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
   593
                     up to the next empty chunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   594
                    "
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   595
                    Transcript showCR:'skipping chunks ...'.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   596
                    done := false.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   597
                    [done] whileFalse:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   598
                        aString := self nextChunk.
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   599
                        done := (aString size == 0).
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   600
                    ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   601
                ] ifFalse:[
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   602
                    rslt := rslt 
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   603
                                fileInFrom:self 
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   604
                                notifying:someone 
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   605
                                passChunk:passChunk
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   606
                                single:false
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   607
                                silent:beSilent
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   608
                ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   609
            ]
ac8024ede0ff changed #fileInNextChunkNotifying:passChunk:silent:
Stefan Vogel <sv@exept.de>
parents: 11139
diff changeset
   610
        ]
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   611
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   612
    ^ rslt
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   613
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
   614
    "Modified: / 05-02-2011 / 10:06:57 / cg"
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   615
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   616
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   617
fileInNotifying:notifiedLoader passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   618
    "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
   619
     return the value of the last chunk.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   620
     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
   621
10394
485f6c2d8db0 Do not refer to non-existant aspect
Stefan Vogel <sv@exept.de>
parents: 10356
diff changeset
   622
    ^ self basicFileInNotifying:notifiedLoader passChunk:passChunk.
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   623
!
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   624
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   625
fileInXMLNotifying:someone passChunk:passChunk
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   626
    "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
   627
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   628
    | builder parser|
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   629
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   630
    (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
   631
	Smalltalk loadPackage:'stx:goodies/xml/vw'.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   632
	(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
   633
	    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
   634
	]
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   635
    ].
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   636
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   637
    builder := XML::SourceNodeBuilder new.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   638
    parser := XML::XMLParser on:self.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   639
    parser builder:builder.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   640
    parser validate:false.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   641
    parser scanDocument.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   642
    "/ self halt.
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   643
! !
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
   644
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   645
!PeekableStream methodsFor:'reading'!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   646
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   647
nextDecimalInteger
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   648
    "read the next integer in radix 10. Does NOT skip initial whitespace.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   649
     The streams elements should be characters.
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   650
     Be careful - this method returns 0 if not posiioned on a digit intitially
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   651
     or if the end of the stream is encountered."
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   652
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   653
    |nextOne value|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   654
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   655
    nextOne := self peekOrNil.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   656
    value := 0.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   657
    [nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   658
        value := (value * 10) + nextOne digitValue.
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   659
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   660
        nextOne := self peekOrNil
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   661
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   662
    ^ value
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   663
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
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   666
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   667
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   668
     s nextDecimalInteger. 
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
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   671
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   672
     |s|
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
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   675
     s nextDecimalInteger.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   676
     s skipSpaces.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   677
     s nextDecimalInteger. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   678
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   679
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   680
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   681
nextDelimited:terminator
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   682
    "return the contents of the receiver, up to the next terminator character. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   683
     Doubled terminators indicate an embedded terminator character.  
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   684
     For example: 'this '' was a quote'. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   685
     Start postioned before the initial terminator."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   686
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   687
    | out ch |
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   688
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 5394
diff changeset
   689
    out := WriteStream on: (String uninitializedNew: 1000).
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   690
    self atEnd ifTrue: [^ ''].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   691
    self next == terminator ifFalse: [self skip: -1].       "absorb initial terminator"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   692
    [(ch := self next) == nil] whileFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   693
        (ch == terminator) ifTrue: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   694
            self peek == terminator ifFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   695
                ^ out contents  "terminator is not doubled; we're done!!"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   696
            ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   697
            self next.  "skip doubled terminator"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   698
        ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   699
        out nextPut: ch.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   700
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   701
    ^ out contents
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   702
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   703
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   704
     ('*foo bar baz* more foo' readStream nextDelimited:$*) 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   705
     ('*foo bar **baz***' readStream nextDelimited:$*)   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   706
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   707
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   708
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   709
nextPeek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   710
    "advance to next element and return the peeked element"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   711
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   712
    self next.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   713
    ^ self peek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   714
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   715
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   716
nextUpTo:anObject
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   717
    "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
   718
     elements, but excluding anObject. 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   719
     The next read operation will return anObject.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   720
     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
   721
     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
   722
     Compare this with #upTo: which positions behind anObject"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   723
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   724
    |answerStream element|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   725
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   726
    answerStream := WriteStream on:(self contentsSpecies new).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   727
    [self atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   728
	element := self peek.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   729
	(element = anObject) ifTrue: [
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   730
	    ^ answerStream contents
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   731
	].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   732
	answerStream nextPut:element.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   733
	self next.
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
    ^ answerStream contents
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   736
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   737
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   738
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   739
     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
   740
     Transcript showCR:(s nextUpTo:4).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   741
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   742
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   743
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   744
     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
   745
     Transcript showCR:(s upTo:4).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   746
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   747
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   748
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   749
     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
   750
     Transcript showCR:(s nextUpTo:9).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   751
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   752
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   753
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   754
     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
   755
     Transcript showCR:(s upTo:9).  
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   756
     Transcript showCR:s next
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   757
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   758
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   759
    "Created: 24.1.1997 / 14:08:35 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   760
    "Modified: 24.1.1997 / 14:09:49 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   761
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   762
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   763
peek 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   764
    "return the next element of the stream without advancing (i.e.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   765
     the following send of next will return this element again.)
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   766
     - 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
   767
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   768
    ^ self subclassResponsibility
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   769
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   770
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   771
peekFor:anObject 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   772
    "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
   773
     and return true. Otherwise, leave the receiver unaffected and return false."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   774
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   775
    self peek = anObject ifTrue:[
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   776
        self nextOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   777
        ^ true
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   778
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   779
    ^ false
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   780
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   781
    "
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   782
      #() readStream peekFor:nil
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   783
      #() readStream signalAtEnd:true; peekFor:nil
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   784
      #(nil) readStream peekFor:nil
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   785
    "
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   786
!
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   787
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   788
peekOrNil
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   789
    "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
   790
     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
   791
     if handled. Instead, nil is returned immediately."
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
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   794
    ^ self peek
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   795
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   796
    "Created: / 5.3.1998 / 02:56:49 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   797
    "Modified: / 5.3.1998 / 13:45:07 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   798
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   799
11139
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   800
throughAnyForWhich:checkBlock
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   801
    "read & return a collection of all objects up-to and including 
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   802
     the elements for which checkBlock returns true.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   803
     (i.e. read until checkBlock returns false on an element)
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   804
     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
   805
     and returned."
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   806
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   807
    |answerStream element|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   808
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   809
    answerStream := WriteStream on:(self contentsSpecies new).
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   810
    [self atEnd] whileFalse:[
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   811
        element := self peek.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   812
        (checkBlock value:element) ifFalse:[
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   813
            ^ answerStream contents
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   814
        ].
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   815
        answerStream nextPut:element.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   816
        self next.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   817
    ].
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   818
    ^ answerStream contents
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   819
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   820
    "
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   821
     |s|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   822
     s := ReadStream on:#(1 2 3 4 5 6 7 8).
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   823
     Transcript showCR:(s throughAny:#(3 4 5)).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   824
     Transcript showCR:s next
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   825
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   826
     |s|
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   827
     s := ReadStream on:'hello world, this is some text'.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   828
     Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   829
     Transcript showCR:(s throughAnyForWhich:[:ch | ch isSeparator not]).  
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   830
     Transcript showCR:s upToEnd.
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   831
    "
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   832
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   833
    "Modified: / 11.1.1998 / 15:28:04 / cg"
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   834
!
91f0a0b1b70a + #throughAnyForWhich:
Claus Gittinger <cg@exept.de>
parents: 10394
diff changeset
   835
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   836
upToMatching:aBlock
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   837
    "Return the next elements up to but not including the next element
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   838
     for which aBlock returns true.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   839
     The next read will return that matching element."
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   840
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   841
    |answerStream element|
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   842
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   843
    answerStream := WriteStream on:(self contentsSpecies new).
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   844
    [self atEnd] whileFalse: [
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   845
        element := self peek.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   846
        (aBlock value:element) ifTrue: [^ answerStream contents].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   847
        answerStream nextPut:element.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   848
        self next.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   849
    ].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   850
    ^ answerStream contents
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   851
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   852
    "
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   853
     'hello world' readStream upToMatching:[:c | c isSeparator].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   854
    "
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   855
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   856
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   857
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   858
     s := 'hello world' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   859
     s upToMatching:[:c | c isSeparator].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   860
     s upToEnd
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   861
    "
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   862
2421
0b8966d99a87 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2419
diff changeset
   863
    "Modified: 26.2.1997 / 12:20:57 / cg"
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   864
!
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   865
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   866
upToSeparator
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   867
    "Return the next elements up to but not including the next separator.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   868
     The next read will return the separator.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   869
     If no separator is encountered, the contents up to the end is returned.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   870
     The elements are supposed to understand #isSeparator 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   871
     (i.e. the receiver is supposed to be a character-stream)."
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   872
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   873
    ^ self upToMatching:[:ch | ch isSeparator]
2060
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   874
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   875
    "
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   876
     'hello world' readStream upToSeparator  
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   877
     'helloworld' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   878
     'helloworld' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   879
     '' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   880
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   881
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   882
     s := 'hello world' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   883
     s upToSeparator.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   884
     s upToEnd  
2060
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   885
    "
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   886
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   887
    "Modified: 4.1.1997 / 23:38:05 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   888
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
   889
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   890
!PeekableStream methodsFor:'reading-strings'!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   891
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   892
nextAlphaNumericWord
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   893
    "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
   894
     Return a string containing those characters.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   895
     Any leading non-alphaNumeric chars are skipped."
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   896
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   897
    |s c|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   898
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   899
    "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
   900
    [
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   901
        c := self nextOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   902
        c isNil ifTrue:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   903
            "end of stream"
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   904
            ^ nil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   905
        ].
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   906
        c isLetterOrDigit
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   907
    ] whileFalse.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   908
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   909
    "second: get the alphanumeric word"
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   910
    s := WriteStream on:(String new:128).
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   911
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   912
    [
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   913
        s nextPut:c.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   914
        c := self peekOrNil.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   915
        (c notNil and:[c isLetterOrDigit]) ifTrue:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   916
            self next.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   917
            true.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   918
        ] ifFalse:[
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   919
            false.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   920
        ]
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   921
    ] whileTrue.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   922
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   923
    ^ s contents.
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   924
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   925
    "Use UnicodString 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
   926
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   927
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   928
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   929
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   930
     s := 'hello world 1234 foo1 foo2' asUnicodeString readStream.
9356
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   931
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   932
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   933
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   934
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   935
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   936
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   937
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   938
10356
6f32850bdc81 speed up #nextAlphaNumericWord
Stefan Vogel <sv@exept.de>
parents: 10351
diff changeset
   939
     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
   940
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   941
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   942
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   943
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   944
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   945
    "Modified: 15.5.1996 / 17:51:42 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   946
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   947
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   948
nextMatching:matchBlock1 thenMatching:matchBlock2
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   949
    "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
   950
     remaining characters must match matchBlock2.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   951
     Return a string containing those characters."
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   952
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   953
    |s c|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   954
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   955
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   956
    (matchBlock1 value:self peek) ifFalse:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   957
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   958
    s := self next asString.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   959
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   960
    [self atEnd not
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   961
     and:[matchBlock2 value:(c := self peek)]] whileTrue:[ 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   962
        s := s copyWith:c. 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   963
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   964
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   965
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   966
    s size == 0 ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   967
    ^ s.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   968
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   969
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   970
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   971
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   972
     s := 'hello_world_1234 foo1 foo2' readStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   973
     s nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   974
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   975
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   976
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   977
nextSymbol
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   978
    "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
   979
     Return a string containing those characters.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   980
     Any leading non-alphaNumeric chars are skipped."
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   981
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   982
    |symbol c symbolStream|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   983
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   984
    [self atEnd
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   985
     or:[(c := self peek) isLetterOrDigit]] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   986
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   987
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   988
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   989
    self atEnd ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   990
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   991
    symbolStream := '' writeStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   992
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   993
    [self atEnd not
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   994
     and:[(c := self peek) isLetterOrDigit or:[c == $:]]] whileTrue:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   995
        symbolStream nextPut:c.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   996
        self next 
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   997
    ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   998
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
   999
    symbol := symbolStream contents.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1000
    symbol size == 0 ifTrue:[^ nil].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1001
    ^ symbol.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1002
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1003
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1004
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1005
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1006
     s := 'hello: world 1234 foo1 foo2:' readStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1007
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1008
        Transcript showCR:(s nextSymbol).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1009
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1010
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1011
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1012
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1013
     |s|
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1014
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1015
     s := 'hello +++ #world ###123###abc### 1234 foo1 foo2' readStream.
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1016
     [s atEnd] whileFalse:[
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1017
        Transcript showCR:(s nextAlphaNumericWord).
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1018
     ].
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1019
    "
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1020
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1021
    "Modified: 15.5.1996 / 17:51:42 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1022
!
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1023
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1024
nextWord
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1025
    "return the next characters which form an alphanumeric word
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1026
     (i.e. everything upTo (but excluding) the next non alphanumeric
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1027
      element)"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1028
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1029
    ^ self nextAlphaNumericWord
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1030
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1031
    "Modified: 15.5.1996 / 17:39:32 / cg"
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1032
! !
dfc36db0f470 Move 'peeking' methods to PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8867
diff changeset
  1033
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
  1034
!PeekableStream class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
  1035
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
  1036
version
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
  1037
    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.40 2011-02-05 10:40:33 cg Exp $'
12783
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
  1038
!
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
  1039
8dd61118e5f9 changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 11497
diff changeset
  1040
version_CVS
13282
9b8542c8439e changed: #fileInNextChunkNotifying:passChunk:silent:
Claus Gittinger <cg@exept.de>
parents: 12785
diff changeset
  1041
    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.40 2011-02-05 10:40:33 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
  1042
! !
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
  1043
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8192
diff changeset
  1044
PeekableStream initialize!