allow dollars in identifiers
authorClaus Gittinger <cg@exept.de>
Sun, 07 Sep 1997 01:28:18 +0200
changeset 608 faa97ce2db56
parent 607 118452a23976
child 609 dfae7c6eea05
allow dollars in identifiers
Scanner.st
--- a/Scanner.st	Sun Sep 07 01:25:50 1997 +0200
+++ b/Scanner.st	Sun Sep 07 01:28:18 1997 +0200
@@ -10,7 +10,7 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.1.9 on 30-aug-1997 at 12:57:03 am'                 !
+'From Smalltalk/X, Version:3.1.9 on 7-sep-1997 at 1:59:17 pm'                   !
 
 Object subclass:#Scanner
 	instanceVariableNames:'source lineNr collectedSource token tokenType tokenPosition
@@ -19,10 +19,11 @@
 		saveComments currentComments warnSTXSpecialComment
 		warnUnderscoreInIdentifier warnOldStyleAssignment
 		warnCommonMistakes outStream outCol warnSTXNameSpaceUse
-		warnPossibleIncompatibilities'
+		warnPossibleIncompatibilities warnDollarInIdentifier'
 	classVariableNames:'TypeArray ActionArray AllowUnderscoreInIdentifier Warnings
 		WarnSTXSpecials WarnOldStyleAssignment WarnUnderscoreInIdentifier
-		WarnCommonMistakes WarnPossibleIncompatibilities'
+		WarnCommonMistakes WarnPossibleIncompatibilities
+		WarnDollarInIdentifier AllowDollarInIdentifier'
 	poolDictionaries:''
 	category:'System-Compiler'
 !
@@ -89,14 +90,18 @@
     Warnings := true.
     WarnSTXSpecials := true.
     WarnUnderscoreInIdentifier := true.
+    WarnDollarInIdentifier := true.
     WarnOldStyleAssignment := true.
     WarnCommonMistakes := true.
     WarnPossibleIncompatibilities := false.
     AllowUnderscoreInIdentifier := false.
+    AllowDollarInIdentifier := false.
 
-    "self initialize"
+    "
+     self initialize
+    "
 
-    "Modified: 23.5.1997 / 12:24:44 / cg"
+    "Modified: 7.9.1997 / 01:37:57 / cg"
 !
 
 setupActions
@@ -169,6 +174,34 @@
 
 !Scanner class methodsFor:'defaults'!
 
+allowDollarInIdentifier
+    "return true, if $-characters are allowed in identifiers.
+     Notice, that dollars are NEVER allowed as the first character in an identifier."
+
+    ^ AllowDollarInIdentifier
+
+    "Created: 7.9.1997 / 01:32:18 / cg"
+    "Modified: 7.9.1997 / 01:39:44 / cg"
+!
+
+allowDollarInIdentifier:aBoolean
+    "this allows turning on/off $-characters in identifiers.
+     Notice, that dollars are NEVER allowed as the first character in an identifier.
+     If turned off (the default), dollars are not allowed in identifiers,
+     but instead are scanned as character-constant prefix.
+     If turned on, dollars are in identifiers are allowed, while extra
+     dollars are still scanned as constant character prefix.
+     If you have to fileIn old VW-Vsn2.x classes, turn this off
+     before filing them in; i.e.:
+        Compiler allowDollarInIdentifiers:false"
+
+    AllowDollarInIdentifier := aBoolean.
+    self setupActions
+
+    "Created: 7.9.1997 / 01:34:49 / cg"
+    "Modified: 7.9.1997 / 01:39:30 / cg"
+!
+
 allowUnderscoreInIdentifier
     "return true, if underscores are allowed in identifiers"
 
@@ -181,13 +214,14 @@
      but instead scanned as assignment character (old ST/80 syntax).
      If turned on, underscores are in identifiers are allowed, while extra
      underscores are still scanned as assignment.
-     If you have to fileIn VV-Vsn2 classes, 
-     add a line such as:
-	Compiler allowUnderscoreInIdentifiers:false
-     in your 'private.rc'/'smalltalk.rc' file"
+     If you have to fileIn old VW-Vsn2.x classes, 
+     turn them off with:
+        Compiler allowUnderscoreInIdentifiers:false"
 
     AllowUnderscoreInIdentifier := aBoolean.
     self setupActions
+
+    "Modified: 7.9.1997 / 01:35:19 / cg"
 !
 
 warnCommonMistakes
@@ -209,6 +243,31 @@
     WarnCommonMistakes := aBoolean
 !
 
+warnDollarInIdentifier
+    "return true, if $-characters in identifiers are to be warned about"
+
+    ^ WarnDollarInIdentifier
+
+    "Created: 7.9.1997 / 01:36:17 / cg"
+!
+
+warnDollarInIdentifier:aBoolean
+    "this allows turning on/off warnings about $-characters in identifiers.
+     You may find those warnings useful, to make certain that your code
+     is portable to other smalltalk versions, which do not allow this
+     (i.e. VW releases 2.x and maybe others).
+     Notice, that dollars are NEVER allowed as the first character in an identifier.
+     If you get bored by those warnings, turn them off by adding
+     a line as:
+        Compiler warnDollarInIdentifier:false
+     in your 'private.rc' file"
+
+    WarnDollarInIdentifier := aBoolean
+
+    "Created: 7.9.1997 / 01:37:42 / cg"
+    "Modified: 7.9.1997 / 01:40:02 / cg"
+!
+
 warnOldStyleAssignment
     "return true, if underscore-assignment (pre ST-80v4 syntax) are to be warned about"
 
@@ -271,12 +330,17 @@
 
 warnUnderscoreInIdentifier:aBoolean
     "this allows turning on/off warnings about underscores in identifiers.
+     You may find those warnings useful, to make certain that your code
+     is portable to other smalltalk versions, which do not allow this
+     (i.e. VW releases 2.x).
      If you get bored by those warnings, turn them off by adding
      a line as:
-	Compiler warnUnderscoreInIdentifier:false
+        Compiler warnUnderscoreInIdentifier:false
      in your 'private.rc' file"
 
     WarnUnderscoreInIdentifier := aBoolean
+
+    "Modified: 7.9.1997 / 01:37:13 / cg"
 !
 
 warnings
@@ -593,6 +657,25 @@
     "Modified: 23.5.1997 / 12:16:39 / cg"
 !
 
+warnDollarAt:position
+    "warn about $-character in an identifier"
+
+    ignoreWarnings ifFalse:[
+        warnDollarInIdentifier ifTrue:[
+            self 
+                warning:'$-characters in identifiers/symbols are nonportable' 
+                position:position to:position.
+            "
+             only warn once (per method)
+            "
+            warnDollarInIdentifier := false
+        ]
+    ]
+
+    "Created: 7.9.1997 / 01:50:24 / cg"
+    "Modified: 7.9.1997 / 01:51:13 / cg"
+!
+
 warnOldStyleAssignmentAt:position
     "warn about an oldStyle assignment"
 
@@ -720,6 +803,7 @@
     warnSTXSpecialComment := WarnSTXSpecials.
     warnSTXNameSpaceUse := WarnSTXSpecials.
     warnUnderscoreInIdentifier := WarnUnderscoreInIdentifier.
+    warnDollarInIdentifier := WarnDollarInIdentifier.
     warnOldStyleAssignment := WarnOldStyleAssignment.
     warnCommonMistakes := WarnCommonMistakes.
     warnPossibleIncompatibilities := WarnPossibleIncompatibilities.
@@ -727,7 +811,7 @@
         self class setupActions
     ]
 
-    "Modified: 23.5.1997 / 12:00:07 / cg"
+    "Modified: 7.9.1997 / 01:51:01 / cg"
 !
 
 initializeFor:aStringOrStream
@@ -971,7 +1055,7 @@
 !
 
 nextIdentifier
-    |nextChar string firstChar|
+    |nextChar string firstChar ok|
 
     hereChar == $_ ifTrue:[
         "/
@@ -1002,17 +1086,32 @@
     ].
     nextChar := source peek.
 
-    AllowUnderscoreInIdentifier ifTrue:[
-        nextChar == $_ ifTrue:[
-            self warnUnderscoreAt:(source position).
-        ].
-        [nextChar == $_] whileTrue:[
-            string := string copyWith:nextChar.
-            nextChar := source nextPeek.
-            (nextChar isAlphaNumeric) ifTrue:[
-                string := string , source nextAlphaNumericWord.
-                nextChar := source peek.
-            ]
+    (nextChar == $_ 
+    or:[nextChar == $$]) ifTrue:[
+        ok := (nextChar == $_) ifTrue:[AllowUnderscoreInIdentifier] ifFalse:[AllowDollarInIdentifier].
+        ok ifTrue:[
+            nextChar == $_ ifTrue:[
+                self warnUnderscoreAt:(source position).
+            ] ifFalse:[
+                self warnDollarAt:(source position).
+            ].
+            [ok] whileTrue:[
+                string := string copyWith:nextChar.
+                nextChar := source nextPeek.
+                (nextChar isAlphaNumeric) ifTrue:[
+                    string := string , source nextAlphaNumericWord.
+                    nextChar := source peek.
+                ].
+                (nextChar == $_) ifTrue:[
+                    ok := AllowUnderscoreInIdentifier
+                ] ifFalse:[
+                    (nextChar == $$) ifTrue:[
+                        ok := AllowDollarInIdentifier
+                    ] ifFalse:[
+                        ok := false
+                    ]
+                ]
+            ].
         ].
     ].
 
@@ -1058,7 +1157,7 @@
     ^ tokenType
 
     "Created: 13.9.1995 / 12:56:42 / claus"
-    "Modified: 20.6.1997 / 17:53:42 / cg"
+    "Modified: 7.9.1997 / 01:49:44 / cg"
 !
 
 nextMantissa:radix
@@ -1488,6 +1587,6 @@
 !Scanner class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.68 1997-09-02 18:28:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.69 1997-09-06 23:28:18 cg Exp $'
 ! !
 Scanner initialize!