extracted keyword detection into a separate method for easier
authorClaus Gittinger <cg@exept.de>
Wed, 13 May 1998 15:12:28 +0200
changeset 707 2fe4b3a7708a
parent 706 ce85ab699350
child 708 11837544357d
extracted keyword detection into a separate method for easier subclassing.
Scanner.st
--- a/Scanner.st	Thu May 07 19:50:50 1998 +0200
+++ b/Scanner.st	Wed May 13 15:12:28 1998 +0200
@@ -889,6 +889,35 @@
     ^ self
 !
 
+checkForKeyword:string
+    "check if string is a keyword (as opposed to an identifier).
+     That is, its one of 'self', 'super', 'nil', 'true', 'false',
+     or 'thisContext'.
+     'here' is handled elsewhere (since it must be treated as an
+     identifier, if declared locally."
+
+    |firstChar|
+
+    firstChar := string at:1.
+    (firstChar == $s) ifTrue:[
+        (string = 'self')  ifTrue:[tokenType := #Self. ^true].
+        (string = 'super') ifTrue:[tokenType := #Super. ^true]
+    ].
+    (firstChar == $n) ifTrue:[
+        (string = 'nil') ifTrue:[tokenType := #Nil. ^true]
+    ].
+    (firstChar == $t) ifTrue:[
+        (string = 'true') ifTrue:[tokenType := #True. ^true].
+        (string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^true]
+    ].
+    (firstChar == $f) ifTrue:[
+        (string = 'false') ifTrue:[tokenType := #False. ^true]
+    ].
+    ^ false
+
+    "Modified: / 13.5.1998 / 14:59:55 / cg"
+!
+
 collectedSource
     ^ collectedSource
 !
@@ -958,11 +987,12 @@
         tokenType := #Character.
 "/        self markConstantFrom:tokenPosition to:(tokenPosition + 1).
     ] ifFalse:[
+        tokenValue := token := nil.
         tokenType := #EOF
     ].
     ^ tokenType
 
-    "Modified: / 1.4.1998 / 13:06:33 / cg"
+    "Modified: / 13.5.1998 / 15:09:50 / cg"
 !
 
 nextColonOrAssign
@@ -990,13 +1020,13 @@
 
     (source nextPeek == $=) ifTrue:[
         source next.
-        tokenType := token :=$_
+        tokenType := token := $_
     ] ifFalse:[
-        tokenType := token :=$:
+        tokenType := token := $:
     ].
     ^ tokenType
 
-    "Modified: 20.6.1997 / 17:52:10 / cg"
+    "Modified: / 13.5.1998 / 15:10:04 / cg"
 !
 
 nextHash
@@ -1126,7 +1156,7 @@
 !
 
 nextIdentifier
-    |nextChar string firstChar ok pos|
+    |nextChar string ok pos|
 
     hereChar == $_ ifTrue:[
         "/
@@ -1211,26 +1241,13 @@
     ].
 
     tokenName := token := string.
-    firstChar := string at:1.
-    (firstChar == $s) ifTrue:[
-        (string = 'self') ifTrue:[tokenType := #Self. ^self].
-        (string = 'super') ifTrue:[tokenType := #Super. ^self]
-    ].
-    (firstChar == $n) ifTrue:[
-        (string = 'nil') ifTrue:[tokenType := #Nil. ^self]
-    ].
-    (firstChar == $t) ifTrue:[
-        (string = 'true') ifTrue:[tokenType := #True. ^self].
-        (string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
-    ].
-    (firstChar == $f) ifTrue:[
-        (string = 'false') ifTrue:[tokenType := #False. ^self]
-    ].
+    (self checkForKeyword:string) ifTrue:[^ tokenType].
+
     tokenType := #Identifier.
     ^ tokenType
 
     "Created: / 13.9.1995 / 12:56:42 / claus"
-    "Modified: / 5.3.1998 / 02:53:43 / cg"
+    "Modified: / 13.5.1998 / 14:58:39 / cg"
 !
 
 nextMantissa:radix
@@ -1556,19 +1573,21 @@
     self syntaxError:('invalid character: ''' , ch asString , ''' ',
                       '(' , v printString , ')')
             position:tokenPosition to:tokenPosition.
-    tokenType := #Error.
+    source next.
+    tokenName := nil.
+    tokenType := token := #Error.
     ^ #Error
 
     "Modified: / 13.9.1995 / 12:56:14 / claus"
-    "Modified: / 5.3.1998 / 02:55:17 / cg"
+    "Modified: / 13.5.1998 / 15:11:39 / cg"
 !
 
 nextToken:aCharacter
-    tokenType := aCharacter.
+    tokenType := token := aCharacter.
     hereChar notNil ifTrue:[source next].
     ^ tokenType
 
-    "Modified: 30.8.1997 / 00:56:23 / cg"
+    "Modified: / 13.5.1998 / 15:10:23 / cg"
 !
 
 skipComment
@@ -1716,6 +1735,6 @@
 !Scanner class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.79 1998-04-01 11:11:59 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.80 1998-05-13 13:12:28 cg Exp $'
 ! !
 Scanner initialize!