optionally allow nil, true, false etc. as unary selector
authorClaus Gittinger <cg@exept.de>
Fri, 09 Aug 2002 14:25:16 +0200
changeset 1306 90f45715a0d7
parent 1305 0b50f8e37109
child 1307 a91664d148ad
optionally allow nil, true, false etc. as unary selector
Parser.st
--- a/Parser.st	Fri Aug 09 09:39:47 2002 +0200
+++ b/Parser.st	Fri Aug 09 14:25:16 2002 +0200
@@ -36,7 +36,7 @@
 		LineNumberInfo SuppressDoItCompilation StringsAreImmutable
 		ParseErrorSignal RestartCompilationSignal
 		AllowFunctionCallSyntaxForBlockEvaluation AllowLazyValueExtension
-		AllowVariableReferences'
+		AllowVariableReferences AllowReservedWordsAsSelectors'
 	poolDictionaries:''
 	category:'System-Compiler'
 !
@@ -3818,13 +3818,15 @@
         endOfSelectorPosition := tokenPosition.
         ^ self
     ].
-    (tokenType == #Identifier) ifTrue:[
+
+    (self isValidUnarySelector:tokenType) ifTrue:[
         self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1).
         selector := tokenName asSymbol.
         self nextToken.
         endOfSelectorPosition := tokenPosition.
         ^ self
     ].
+
     "/ special handling for |, which is also a lexical token
     tokenType == $| ifTrue:[
         tokenType := #BinaryOperator.
@@ -4749,6 +4751,35 @@
     ^ expr
 !
 
+isValidUnarySelector:tokenType
+    tokenType == #Identifier ifTrue:[^true].
+    AllowReservedWordsAsSelectors == true ifTrue:[
+        tokenType == #Self ifTrue:[^true].
+        tokenType == #Nil ifTrue:[^true].
+        tokenType == #True ifTrue:[^true].
+        tokenType == #False ifTrue:[^true].
+        tokenType == #Here ifTrue:[^true].
+        tokenType == #Super ifTrue:[^true].
+        tokenType == #ThisContext ifTrue:[^true].
+    ].
+    ^ false
+
+    "
+     AllowReservedWordsAsSelectors := true
+     AllowReservedWordsAsSelectors := false
+    "
+
+    "
+     1234 self
+     1234 nil
+     1234 true
+     1234 false
+     1234 here
+     1234 super
+     1234 thisContext
+    "
+!
+
 keywordExpression
     "parse a keyword-expression; return a node-tree, nil or #Error.
 
@@ -5648,7 +5679,7 @@
 
     receiver := self functionCallExpression.
     (receiver == #Error) ifTrue:[^ #Error].
-    [tokenType == #Identifier] whileTrue:[
+    [ self isValidUnarySelector:tokenType ] whileTrue:[
         pos := tokenPosition.
         pos2 := pos + tokenName size - 1.
         self markSelector:tokenName from:pos to:pos2 receiverNode:receiver.
@@ -6685,6 +6716,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.345 2002-08-07 13:01:15 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.346 2002-08-09 12:25:16 cg Exp $'
 ! !
 Parser initialize!