SyntaxError: parentheses; cascades and yourself (Opal vs. old compilers parser)
The following method compiles with Opal: createRedMorph ^ (self new color:Color red); yourself but gives a syntax error with the old compilers parser createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself removing the parenthesis of course works for both. Who is right ? (for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like: "(some expression);yourself" nicolai
Interesting. I think that for a cascade you need more than one message send.
On 16 Sep 2015, at 10:56, Nicolai Hess <nicolaihess@web.de> wrote:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
Nicolai, can you try with the RBParser directly? I believe Opal uses the RBParser. RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself' Oh, RBParser sees it as: self new color: Color red; yourself :) Thierry 2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
OK, I think Sven is right and a cascade needs at least one message send "self ; yourself" doesn't work too (both parser don't accept this). There are currently two methods in Pharo 5.0 with this syntax: DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed: @Yuri, can you change that. And I think we should fix RBParser. 2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
Arrg, sorry Yuri, this (too) isn't from QualityAssistance, but DependencyAnalyzer 2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
But
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
Argh, sent too early: self new color: Color red; yourself est bien une cascade, non? Thierry 2015-09-16 15:12 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
But
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
2015-09-16 15:14 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Argh, sent too early:
self new color: Color red; yourself
est bien une cascade, non?
Yes, but in (self new color: Color red); yourself the expression in parenthesis looks like "this evalulates first, to 'anObject' ", so we send " ; yourself", a cascaded messages with only one message to "anObject".
Thierry
2015-09-16 15:12 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
But
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
2015-09-17 9:10 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
2015-09-16 15:14 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Argh, sent too early:
self new color: Color red; yourself
est bien une cascade, non?
Yes, but in
(self new color: Color red); yourself the expression in parenthesis looks like "this evalulates first, to 'anObject' ", so we send " ; yourself", a cascaded messages with only one message to "anObject".
Yes, agreed of course. In a way, it looks like an error correction type of thing: the parser knows the parenthesis shouldn't be there or the ; shouldn't be there, so it chooses one interpretation out of the two: here it is the parenthesis are unnecessary. By the way, John found another issue with a fix you did in RBParser (RBPatternParser>>parseUnaryMessage) which fail some refactoring expressions. Can you have a look? Thierry
Thierry
2015-09-16 15:12 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
But
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
On 17 Sep 2015, at 09:32, Thierry Goubier <thierry.goubier@gmail.com> wrote:
2015-09-17 9:10 GMT+02:00 Nicolai Hess <nicolaihess@web.de>:
2015-09-16 15:14 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>: Argh, sent too early:
self new color: Color red; yourself
est bien une cascade, non?
Yes, but in
(self new color: Color red); yourself the expression in parenthesis looks like "this evalulates first, to 'anObject' ", so we send " ; yourself", a cascaded messages with only one message to "anObject".
Yes, agreed of course.
In a way, it looks like an error correction type of thing: the parser knows the parenthesis shouldn't be there or the ; shouldn't be there, so it chooses one interpretation out of the two: here it is the parenthesis are unnecessary.
Hmm, I don't agree. We as humans can infer that, from a language/compiler's standpoint it is not clear/possible. someObject message1; message2 is a pure cascade (someObject message1) message2 is not a cascade, message2 being sent to the result the last expression is totally equivalent to someObject message1 message2 However expression message expression ; message could be equivalent, like if it said expression yourself; message but the decision to drop the parenthesis cannot be made automatically, IMHO I would make the spurious ; an error, to avoid confusion
By the way, John found another issue with a fix you did in RBParser (RBPatternParser>>parseUnaryMessage) which fail some refactoring expressions. Can you have a look?
Thierry
Thierry
2015-09-16 15:12 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>:
2015-09-16 15:05 GMT+02:00 Nicolai Hess <nicolaihess@web.de>: OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
But
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>: Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>: The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
The PackageAnalyzer is now maintained by me (especially because it is so usefull for the bootstrap). I just fixed that. Indeed, the code was wrong. Christophe Le 16 sept. 2015 à 15:05, Nicolai Hess a écrit :
OK, I think Sven is right and a cascade needs at least one message send
"self ; yourself"
doesn't work too (both parser don't accept this).
There are currently two methods in Pharo 5.0 with this syntax:
DAPackageAnalyzerWindow class>>#onPackagesNamed: DAPackageCycleDetectionTreeModel class>>#onPackagesNamed:
@Yuri, can you change that.
And I think we should fix RBParser.
2015-09-16 11:30 GMT+02:00 Thierry Goubier <thierry.goubier@gmail.com>: Nicolai,
can you try with the RBParser directly? I believe Opal uses the RBParser.
RBParser parseMethod: 'createRedMorph ^ (self new color:Color red); yourself'
Oh, RBParser sees it as:
self new color: Color red; yourself
:)
Thierry
2015-09-16 10:56 GMT+02:00 Nicolai Hess <nicolaihess@web.de>: The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
(for those who understand the ParseTreeSearcher syntax, how would a search expression look, for finding code like:
"(some expression);yourself"
nicolai
On Wed, Sep 16, 2015 at 4:56 PM, Nicolai Hess <nicolaihess@web.de> wrote:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
What is the result in other dialects? This is a potential incompatibility for little gain. Anyway I would guess Opal is wrong. cheers -ben
On 9/16/2015 10:34 AM, Ben Coman wrote:
On Wed, Sep 16, 2015 at 4:56 PM, Nicolai Hess <nicolaihess@web.de> wrote:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
What is the result in other dialects?
Dolphin lets you do "self ; yourself" as well as the example above. However, both VW & VA don't allow it.
This is a potential incompatibility for little gain. Anyway I would guess Opal is wrong.
I don't remember if we allowed this on purpose to be compatible with other Smalltalks or if it was a bug we missed. Anyway, a simple fix is to add " and: [node parentheses isEmpty]" to the RBParser>>parseCascadeMessage method: parseCascadeMessage | node receiver messages semicolons | node := self parseKeywordMessage. (currentToken isSpecial and: [currentToken value = $; and: [node isMessage and: [node parentheses isEmpty]]]) ifFalse: [^node]. ... John Brant
2015-09-17 1:18 GMT+02:00 John Brant <brant@refactoryworkers.com>:
On 9/16/2015 10:34 AM, Ben Coman wrote:
On Wed, Sep 16, 2015 at 4:56 PM, Nicolai Hess <nicolaihess@web.de> wrote:
The following method compiles with Opal:
createRedMorph ^ (self new color:Color red); yourself
but gives a syntax error with the old compilers parser
createRedMorph ^ (self new color:Color red)End of block expected -> ; yourself
removing the parenthesis of course works for both. Who is right ?
What is the result in other dialects?
Dolphin lets you do "self ; yourself" as well as the example above. However, both VW & VA don't allow it.
Thanks for the info.
This is a potential incompatibility for little gain.
Anyway I would guess Opal is wrong.
I don't remember if we allowed this on purpose to be compatible with other Smalltalks or if it was a bug we missed. Anyway, a simple fix is to add " and: [node parentheses isEmpty]" to the RBParser>>parseCascadeMessage method:
parseCascadeMessage | node receiver messages semicolons | node := self parseKeywordMessage. (currentToken isSpecial and: [currentToken value = $; and: [node isMessage and: [node parentheses isEmpty]]]) ifFalse: [^node]. ...
John Brant
participants (6)
-
Ben Coman -
Christophe Demarey -
John Brant -
Nicolai Hess -
Sven Van Caekenberghe -
Thierry Goubier