# HG changeset patch # User Jan Vrany # Date 1666878839 -3600 # Node ID 3b11fb3ede98180c8c0de3ff562d493cdfc1db75 # Parent 112f76a3b1f70e5481799c33c6bb12e8eaee44ef Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e. diff -r 112f76a3b1f7 -r 3b11fb3ede98 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 " "Modified: / 15-02-2019 / 14:41:24 / Claus Gittinger" + "Modified (format): / 27-10-2022 / 15:11:08 / Jan Vrany " ! 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 " + "Modified: / 28-10-2022 / 14:51:57 / Jan Vrany " ! 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 " "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 " ! 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 " "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 " ! returnStatement