2016-12-11 0:46 GMT+01:00 John Brant <[email protected]>:

> On 12/10/2016 02:37 AM, Nicolai Hess wrote:
>
> Question : how should a pattern with three variables
>> (first/second/third) look like to match the expression
>> { (1@2) . Color red . 3} and assign the (sub)-expressions
>> 1@2
>> Color red
>> 3
>> to the three variables first/second/third ?
>>
>
> The RB was written before the {} array syntax. It appears that are a few
> bugs in the pattern matching for the arrays. The first is that it needs to
> reset the isList variable of RBPatternVariableNode when it is part of a
> dynamic array. You can fix that by adding this to the end of
> RBPatternVariableNode>>parent: method:
>
>         parent isDynamicArray
>                 ifTrue: [ self isStatement
>                                 ifFalse: [ isList := false ] ]
>

Yes, that works


>
> I think this will make the matching work like what you are expecting. If
> you want to match multiple statements, you need to add a ".", but if you
> just have "`@first", it will only match any expression node.
>
> While testing I noticed an error in the RBArrayNode>>match:inContext:. The
> method doesn't test the lengths of the nodes before sending the #with:do:
> message. If you try to match two arrays of different sizes, you get an
> error. This should be changed back to be:
>
> match: aNode inContext: aDictionary
>         aNode class = self class
>                 ifFalse: [ ^ false ].
>         ^ self matchList: statements against: aNode statements inContext:
> aDictionary
>

Yes, I used the call that is used in RBMessageNodes #match:in:Context:, but
RBMessageNode indirectly checks for the different size of arguments by
comparing the selector.
For the RBArrayNode this size comparsion isn't done.
But with your fix, the change in this method isn't needed.

Thank you John.

nicolai


>
>
> John Brant
>
>

Reply via email to