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 ] ]
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
John Brant