--- a/Scanner.st Thu Aug 11 23:42:09 1994 +0200
+++ b/Scanner.st Fri Aug 12 01:27:27 1994 +0200
@@ -13,7 +13,7 @@
Object subclass:#Scanner
instanceVariableNames:'source
token tokenType tokenPosition tokenValue
- tokenName tokenLineNr
+ tokenName tokenLineNr tokenRadix
thisChar peekChar
requestor exitBlock
errorFlag
@@ -29,6 +29,8 @@
Scanner comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
+
+$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.9 1994-08-11 23:27:27 claus Exp $
'!
!Scanner class methodsFor:'documentation'!
@@ -49,7 +51,7 @@
version
"
-$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.8 1994-06-02 20:26:16 claus Exp $
+$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.9 1994-08-11 23:27:27 claus Exp $
"
!
@@ -61,15 +63,15 @@
!Scanner class methodsFor:'instance creation'!
-for:aStream
- "return a new scanner reading from aStream"
+for:aStringOrStream
+ "return a new scanner reading from aStringOrStream"
- ^ (super new) initializeFor:aStream
+ ^ (super new) initializeFor:aStringOrStream
! !
!Scanner methodsFor:'private'!
-initializeFor:aStream
+initializeFor:aStringOrStream
"initialize -
if this is the first time, setup character- and action tables"
@@ -77,7 +79,11 @@
errorFlag := false.
tokenLineNr := 1.
- source := aStream.
+ aStringOrStream isStream ifFalse:[
+ source := ReadStream on:aStringOrStream
+ ] ifTrue:[
+ source := aStringOrStream.
+ ].
currentComments := nil.
saveComments := false.
ignoreErrors := false.
@@ -238,7 +244,7 @@
warning:aMessage position:position to:endPos
"a warning"
- ^ self notifyWarning:(' Warning:' , aMessage) position:position to:endPos
+ ^ self notifyWarning:('Warning: ' , aMessage) position:position to:endPos
!
warning:aMessage position:position
@@ -290,9 +296,9 @@
^ positions
"
- Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello'
- Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14'
- Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000'
+ Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello'
+ Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14'
+ Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000'
"
! !
@@ -332,13 +338,15 @@
thisChar := source nextPeek.
].
tokenLineNr := tokenLineNr + 1.
- warnSTXSpecialComment ifTrue:[
- self warning:'end-of-line comments are a nonstandard feature of ST/X'
- position:startPos to:(source position).
- "
- only warn once
- "
- warnSTXSpecialComment := false
+ ignoreWarnings ifFalse:[
+ warnSTXSpecialComment ifTrue:[
+ self warning:'end-of-line comments are a nonstandard feature of ST/X'
+ position:startPos to:(source position).
+ "
+ only warn once
+ "
+ warnSTXSpecialComment := false
+ ]
].
outStream notNil ifTrue:[
outStream cr.
@@ -527,27 +535,27 @@
!
nextNumber
- |nextChar value radix s|
+ |nextChar value s|
- radix := 10.
- value := Integer readFrom:source radix:radix.
+ tokenRadix := 10.
+ value := Integer readFrom:source radix:tokenRadix.
nextChar := source peek.
(nextChar == $r) ifTrue:[
- radix := value.
+ tokenRadix := value.
source next.
s := 1.
source peek == $- ifTrue:[
source next.
s := -1
].
- value := Integer readFrom:source radix:radix.
+ value := Integer readFrom:source radix:tokenRadix.
value := value * s.
nextChar := source peek
].
(nextChar == $.) ifTrue:[
nextChar := source nextPeek.
- (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
- value := value asFloat + (self nextMantissa:radix).
+ (nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
+ value := value asFloat + (self nextMantissa:tokenRadix).
nextChar := source peek
] ifFalse:[
nextChar == (Character cr) ifTrue:[
@@ -556,9 +564,9 @@
peekChar := $.
]
].
- (nextChar == $e) ifTrue:[
+ ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
nextChar := source nextPeek.
- (nextChar notNil and:[(nextChar isDigitRadix:radix) or:['+-' includes:nextChar]]) ifTrue:[
+ (nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
s := 1.
(nextChar == $+) ifTrue:[
nextChar := source nextPeek
@@ -569,7 +577,7 @@
]
].
value := value asFloat
- * (10.0 raisedToInteger:((Integer readFrom:source radix:radix) * s))
+ * (10.0 raisedToInteger:((Integer readFrom:source radix:tokenRadix) * s))
]
].
tokenValue := value.