support for readSmalltalkSyntax
authorClaus Gittinger <cg@exept.de>
Thu, 18 Jun 1998 23:11:53 +0200
changeset 737 4062aa740959
parent 736 0d0283353930
child 738 2c85becd8697
support for readSmalltalkSyntax
Scanner.st
--- a/Scanner.st	Thu Jun 18 17:39:58 1998 +0200
+++ b/Scanner.st	Thu Jun 18 23:11:53 1998 +0200
@@ -385,6 +385,45 @@
     "Modified: 23.5.1997 / 12:03:05 / cg"
 ! !
 
+!Scanner class methodsFor:'utility scanning'!
+
+scanNumberFrom:aStream
+    "utility - helper for Number>>readSmalltalkSyntaxFrom:"
+
+    ^ self basicNew scanNumberFrom:aStream
+
+    "
+     |s|
+
+     s := '12345abcd' readStream.
+     Transcript showCR:(self scanNumberFrom:s).
+     Transcript showCR:(s upToEnd).
+    "
+    "
+     |s|
+
+     s := '16rffffxabcd' readStream.
+     Transcript showCR:(self scanNumberFrom:s).
+     Transcript showCR:(s upToEnd).
+    "
+    "
+     |s|
+
+     s := '1.2345abcd' readStream.
+     Transcript showCR:(self scanNumberFrom:s).
+     Transcript showCR:(s upToEnd).
+    "
+    "
+     |s|
+
+     s := '1.abcd' readStream.
+     Transcript showCR:(self scanNumberFrom:s).
+     Transcript showCR:(s upToEnd).
+    "
+
+    "Modified: / 18.6.1998 / 23:10:39 / cg"
+! !
+
 !Scanner methodsFor:'ST-80 compatibility'!
 
 endOfLastToken
@@ -862,6 +901,25 @@
 
 !Scanner methodsFor:'general scanning'!
 
+scanNumberFrom:aStringOrStream
+    "scan aSourceString for the next number in smalltalk syntax
+     Return the number or nil."
+
+    |oldPos|
+
+    self initializeFor:aStringOrStream.
+    oldPos := source position.
+    self nextToken.
+    (tokenType == #Integer or:[tokenType == #Float]) ifTrue:[
+        ^ tokenValue
+    ].
+    source position:oldPos.
+    ^ nil.
+
+    "Created: / 18.6.1998 / 23:05:22 / cg"
+    "Modified: / 18.6.1998 / 23:11:30 / cg"
+!
+
 scanPositionsFor:aTokenString inString:aSourceString
     "scan aSourceString for occurrances of aTokenString.
      Return a collection of start positions.
@@ -1665,7 +1723,7 @@
     ^ #Error
 
     "Modified: / 13.9.1995 / 12:56:14 / claus"
-    "Modified: / 14.5.1998 / 20:52:18 / cg"
+    "Modified: / 18.6.1998 / 23:11:24 / cg"
 !
 
 nextToken:aCharacter
@@ -1821,6 +1879,6 @@
 !Scanner class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.84 1998-05-16 13:56:39 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.85 1998-06-18 21:11:53 cg Exp $'
 ! !
 Scanner initialize!