The full definition from the draft standards (don’t have the standard handy) is:<block constructor> ::= '[' <block body> ']'<block body> ::= [<block argument>* '|'] [<temporaries>] [<statements>]<block argument> ::= ':' identifierThe last line is on the next page of the draft./————————————————————/For encrypted mail use jgpfersich@protonmail.comGet a free account at ProtonMail.comWeb: www.objectnets.net and www.objectnets.org
On Aug 18, 2019, at 12:09, JOHN SARKELA via Squeak-dev <squeak-dev@lists.squeakfoundation.org> wrote:The ANSI standard has the following rules for blocks:The standard does not recognize [:x] as legal syntax for a block.<page21image64736448.png> <page21image37471328.png> <page21image64735680.png> <page21image64733952.png> <page21image64746816.png><block constructor> ::= '[' <block body> ']'
<block body> ::= [<block argument>* '|'] [<temporaries>] [<statements>]
On Aug 18, 2019, at 3:03 PM, Levente Uzonyi <leves@caesar.elte.hu> wrote:Hi Nicolas,
Thanks for investigating this.
I still think that it's just a parser bug, which is accidentally "used" sometimes, especially because it only works when the block is empty.
[block | blk argNodes argument | " '[' {:var.} (:var|statements) ']' BlockNode" argNodes ← (Vector new: 1) asStream. (self match: #leftBracket) ifTrue: [[(self match: #colon) and: [((argument ← self match: #word) ifTrue: [argNodes next← encoder autoBind: argument] ifFalse: [↑self expected: 'Argument name'])]] whileTrueDo: []. (argNodes empty or: [(self match: #verticalBar)]) false ifTrue: [↑self expected: 'Vertical bar']. ((blk ← self statements: argNodes contents doit: false) and: [(self match: #rightBracket)]) ifTrue: [↑blk]. ↑self expected: 'Period or right bracket'] ifFalse: [↑self expected: 'Left bracket']].
Or does it work in other dialects with non-empty blocks?
"374" LADParser$'Parser' [temporaries | vars | "[ '|' {variable} ] {variable, ..., variable}" (self match: #verticalBar) and: [((self match: #verticalBar) ifTrue: [↑#()]. vars ← (Vector new: 8) asStream. [hereType #word] whileTrueDo: [vars next← encoder bind: self advance]. (self match: #verticalBar) ifTrue: [↑vars contents])]. ↑self expected: 'Vertical bar'].
Is it used in other dialects?
Levente
On Sun, 18 Aug 2019, Nicolas Cellier wrote:Le jeu. 15 août 2019 à 12:21, Levente Uzonyi <leves@caesar.elte.hu> a écrit :
On Thu, 15 Aug 2019, Tobias Pape wrote:
>
>> On 15.08.2019, at 03:29, Levente Uzonyi <leves@caesar.elte.hu> wrote:
>>
>> On Wed, 14 Aug 2019, commits@source.squeak.org wrote:
>>
>>> A new version of ShoutCore was added to project The Inbox:
>>> http://source.squeak.org/inbox/ShoutCore-ct.69.mcz
>>>
>>> ==================== Summary ====================
>>>
>>> Name: ShoutCore-ct.69
>>> Author: ct
>>> Time: 14 August 2019, 10:43:04.7164 pm
>>> UUID: 7d165f4e-09bf-a445-a664-5e8edb9867b8
>>> Ancestors: ShoutCore-ul.68
>>>
>>> Fix bug in SHParserST80: Wrong styling after blocks with arguments without statements
>>
>> If you mean that Shout should accept [ :x ], then no, I'm pretty sure that's not valid smalltalk syntax, even if Parser accepts it.
>> The vertical bar, even though I consider it unnecessary in all cases, is mandatory when there are arguments.
>
> I only got to know this "shortcut syntax" because eliot used it either Cog or somewhere in trunk when preparing something (Spur? full block closures? I forgot). So this is a syntax idiosyncrasy that is in active use, not only "old code".
>
> Either we forbid it in the parser and change all of the image or allow it in Shout.
Can you give me examples?
I suspect those are just typos, which the parser accidentally accepted
(and Shout as well before my fixes).
Levente
I don't remember seeing this syntax before and found it a bit surprising.
So, for the sake of curiosity, I tried in some other dialects.
[:x ] is accepted syntax in
- Visualworks (8.3),
- Pharo (v7 with OpalCompiler)
- Smalltalk-80 (apple v0.?)
[:x ] is invalid in
- Dolphin
- Smalltalk/X (jv branch)
So it seems that it's something originating from original Smalltalk-80, but not reproducted in non derivated dialects...
The bar is mandatory in blue book specification (see the last pages)
Capture d’écran 2019-08-18 à 17.11.53.png
So it seems that implementation did not agree with specifications for ages...
Capture d’écran 2019-08-18 à 18.56.05.png
>
> Best regards
> -Tobias
>
>>
>> Levente
>>
>>>
>>> Thanks Jakob for the report!
>>>
>>> =============== Diff against ShoutCore-ul.68 ===============
>>>
>>> Item was changed:
>>> ----- Method: SHParserST80>>parseBlockArguments (in category 'parse') -----
>>> parseBlockArguments
>>>
>>> currentTokenFirst == $: ifFalse: [ ^self ].
>>> [ currentTokenFirst == $: ] whileTrue: [
>>> self
>>> scanPast: #blockArgColon;
>>> parseArgument: #blockPatternArg ].
>>> + ((self parseVerticalBarForTemporaries: #blockArgsBar) and: [
>>> + currentTokenFirst ~= $] ])
>>> + ifFalse: [
>>> + self fail ": Missing block args bar" ]!
>>> - (self parseVerticalBarForTemporaries: #blockArgsBar) ifFalse: [
>>> - self fail ": Missing block args bar" ]!
>>