Allow single underscore as method / block argument and temporaries jv tip
authorJan Vrany <jan.vrany@labware.com>
Thu, 27 Oct 2022 14:53:59 +0100
branchjv
changeset 4735 3b11fb3ede98
parent 4734 112f76a3b1f7
Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e.
Parser.st
--- a/Parser.st	Tue Nov 30 18:11:10 2021 +0000
+++ b/Parser.st	Thu Oct 27 14:53:59 2022 +0100
@@ -1,7 +1,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
  COPYRIGHT (c) 2015-2017 Jan Vrany
- COPYRIGHT (c) 2020-2021 LabWare
+ COPYRIGHT (c) 2020-2022 LabWare
  COPYRIGHT (c) 2021 Patrik Svestka
               All Rights Reserved
 
@@ -176,7 +176,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
  COPYRIGHT (c) 2015-2017 Jan Vrany
- COPYRIGHT (c) 2020-2021 LabWare
+ COPYRIGHT (c) 2020-2022 LabWare
  COPYRIGHT (c) 2021 Patrik Svestka
               All Rights Reserved
 
@@ -5783,6 +5783,14 @@
             (pos == (tokenPosition - 1)) ifFalse:[
                 self warnPossibleIncompatibility:'space(s) between colon and identifier may be non-portable' position:pos to:tokenPosition.
             ].
+
+            (tokenType == $_ and: [ parserFlags allowUnderscoreInIdentifier ]) ifTrue: [
+                "/ Allow single underscore to be a valid variable name (Pharo allows 
+                "/ that and some code uses this feature)
+                tokenName := tokenValue := '_'.
+                tokenType := #Identifier.
+            ].
+
             (tokenType ~~ #Identifier) ifTrue:[
                 ^ self identifierExpectedIn:'block-arg declaration'
             ].
@@ -5837,6 +5845,7 @@
     "Modified (comment): / 05-07-2011 / 23:23:08 / cg"
     "Modified: / 01-08-2011 / 12:34:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 15-02-2019 / 14:41:24 / Claus Gittinger"
+    "Modified (format): / 27-10-2022 / 15:11:08 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 blockBody
@@ -5855,6 +5864,12 @@
         barPos1 := tokenPosition.
         self nextToken.
         [tokenType == $|] whileFalse:[
+            (tokenType == $_ and: [ parserFlags allowUnderscoreInIdentifier ]) ifTrue: [
+                "/ Allow single underscore to be a valid variable name (Pharo allows 
+                "/ that and some code uses this feature)
+                tokenName := tokenValue := '_'.
+                tokenType := #Identifier.
+            ].
             (tokenType == #Identifier) ifFalse:[
                 ^ self identifierExpectedIn:'block-var declaration'
             ].
@@ -5920,6 +5935,7 @@
 
     "Modified: / 26-09-2012 / 14:15:41 / cg"
     "Modified: / 25-02-2014 / 20:20:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-10-2022 / 14:51:57 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 blockExpression
@@ -6287,6 +6303,12 @@
 
         localVarDefPosition := Array with:tokenPosition with:nil.
         self nextToken.
+        (tokenType == $_ and: [ parserFlags allowUnderscoreInIdentifier ]) ifTrue: [
+            "/ Allow single underscore to be a valid variable name (Pharo allows 
+            "/ that and some code uses this feature)
+            tokenName := tokenValue := '_'.
+            tokenType := #Identifier.
+        ].
         pos := tokenPosition.
         firstVar := true.
         [tokenType == #Identifier] whileTrue:[
@@ -6401,7 +6423,14 @@
                     ].  
                 ]
             ].
-            pos := tokenPosition
+            pos := tokenPosition.
+
+            (tokenType == $_ and: [ parserFlags allowUnderscoreInIdentifier ]) ifTrue: [
+                "/ Allow single underscore to be a valid variable name (Pharo allows 
+                "/ that and some code uses this feature)
+                tokenName := tokenValue := '_'.
+                tokenType := #Identifier.
+            ].
         ].
 
         (tokenType ~~ $|) ifTrue:[
@@ -6447,6 +6476,7 @@
     "Modified: / 25-02-2014 / 20:20:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 10-10-2017 / 16:58:13 / cg"
     "Modified: / 23-05-2019 / 09:20:08 / Claus Gittinger"
+    "Modified: / 28-10-2022 / 14:58:26 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 parseMethodSpec
@@ -6478,6 +6508,13 @@
             rawSelector := rawSelector , tokenName.
             self nextToken.
 
+            (tokenType == $_ and: [ parserFlags allowUnderscoreInIdentifier ]) ifTrue: [
+                "/ Allow single underscore to be a valid variable name (Pharo allows 
+                "/ that and some code uses this feature)
+                tokenName := tokenValue := '_'.
+                tokenType := #Identifier.
+            ].  
+
             (tokenType ~~ #Identifier) ifTrue:[
                 "/ ^ #Error].
                 ^ self identifierExpectedIn:'method-arg declaration'
@@ -6588,6 +6625,7 @@
     "Modified: / 12-07-2010 / 09:57:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 21-08-2011 / 08:12:20 / cg"
     "Modified: / 10-02-2019 / 18:16:09 / Claus Gittinger"
+    "Modified: / 27-10-2022 / 15:11:10 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 returnStatement