[squeak-dev] another parser bug

Florin Mateoc florin.mateoc at gmail.com
Tue Jan 17 04:54:36 UTC 2023


Hi Eliot,

My example was a bit oversimplified - I would agree that the "outer"
comment could be attributed to the block instead of the statement, but
that's not what's happening, the outer comment gets attributed to the
block's last statement (if the block's last statement does not end in
period).

So, if the example changes to:

test
true ifTrue: [
"block inner comment"
^self "return comment"] "outer comment"

the outer comment does not get attributed to the block, but to the return
statement. I don't think this can be construed as correct

Also, by adding an inner period (after the return, inside the block), the
outer comment suddenly does not get attributed to the block or to any of
the block's statements anymore, but to the outer statement, although the
outer statement still does not have a terminating statement separator

test
true ifTrue: [
"block inner comment"
^self. "return comment"] "outer comment"



For another example that I think is more obvious:

test
^true ifTrue: [
"block comment"
self "return value comment"]

Here, the return value comment, although written after the last statement,
is moved before the statement and attributed to the block.


That said, I know that you are doing more important work, and that the
ideal attachment of comments to their intended parse nodes is not a main
concern for most people (and in some situations there may not even be an
agreement on what the ideal interpretation is).
Plus, in the cases where this truly matters for me, there is a workaround -
I can play around with the periods until I get the result I want - so it is
not the highest priority for me either. But I'll put it on my todo list

Cheers,
Florin






On Mon, Jan 16, 2023 at 1:25 PM Eliot Miranda <eliot.miranda at gmail.com>
wrote:

> Hi Florin,
>
> On Thu, Jan 12, 2023 at 9:21 PM Florin Mateoc <florin.mateoc at gmail.com>
> wrote:
>
>> Hi Eliot,
>>
>> Thank you for the quick fix, but I have one more example of misbehavior
>> when parsing comments. The issue is that the last period (or lack thereof)
>> makes a difference with regards to associating the comment with the correct
>> parse node.
>>
>> For example, when parsing:
>>
>> test
>> true ifTrue: ["inner comment"] "outer comment"
>>
>> the parser associates both comments to the inside of the block, whereas
>> if we include the period, like so:
>>
>> test
>> true ifTrue: ["inner comment"]. "outer comment"
>>
>> it correctly leaves the inner comment inside and the outer comment outside
>>
>
> Given that period is a statement separator this is arguably correct.  Not
> sure I want to try and fix this one.  But you're welcome to propose a fix
> and I'll happily review it.
>
> _,,,^..^,,,_
> best, Eliot
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20230116/f730c6a6/attachment.html>


More information about the Squeak-dev mailing list