the error my fix introduced :-) :
19445 Pattern code ArrayNode matching failure
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 ?
Looking at the initial question "RegisterRewriteTool matching parts of an array", I was suprised that
for the pattern and the dynamic array expression:
pattern := '{ `@first . `@second . `@third }'
expression := '{ (1@2) . Color red . 3}'
the third variable matches all three expressions and the first two are empty:
RBPatternVariableNode(`@first)->an OrderedCollection()
RBPatternVariableNode(`@second)->an OrderedCollection()
RBPatternVariableNode(`@third)->an OrderedCollection(RBMessageNode((1 @ 2)) RBMessageNode(Color red) RBLiteralValueNode(3))
I fixed this in a way, that all three variables gets assigned one (sub)expression of the array.
But the fix was wrong, now a statement-list-pattern-variable cannot be used anymore to match
the array statements:
pattern := '{ `@.stmts }'.
expression:= RBParser parseExpression:'{ (1@2) . Color red . 3}'.
results in an error during matching but I would expect the result:
RBPatternVariableNode(`@.stmts)->an OrderedCollection(RBMessageNode((1 @ 2)) RBMessageNode(Color red) RBLiteralValueNode(3))
Now I am not sure that the pattern { `@first . `@second . `@third }' is actually a valid
pattern for matching the array (sub)-expressions, the array contents
is a list of three single statemts and @first isn't a statement pattern, but a pattern for an
expression list.
On the other hand, if I try to match *three statements* without the being in a dynamic array:
(Note the missing curly braces)
pattern := '`@first . `@second . `@third '.
expression : parseExpression: ' (1@2) . Color red . 3'.
The result works as I wanted them for the array pattern:
RBPatternVariableNode(`@first)->RBMessageNode(1 @ 2) RBPatternVariableNode(`@second)->RBMessageNode(Color red) RBPatternVariableNode(`@third)->RBLiteralValueNode(3)
So, is the pattern actually right or is the matching wrong?
What should I expect by these patterns and expressions:
pattern := '`@first . `@second . `@third '.
expression : parseExpression: ' (1@2) . Color red . 3'.
pattern := '`.first. `.second. `.third. '.
expression := ' (1@2) . Color red . 3'.
pattern := '{`.first. `.second. `.third.}'.
expression := '{ (1@2) . Color red . 3}'.
pattern := '{`@.all}'.
expression := '{ (1@2) . Color red . 3}'.
pattern := '{`@.all}'.
expression := '{ (1@2) . Color red . 3}'.
pattern := '`.head. `.@tail'.
expression := '(1@2) . Color red . 3'.
pattern := '{`.head. `.@tail}'.
expression := '{(1@2) . Color red . 3}'.
I would expect all statement-pattern without the dynamic array, assign the variables to the
subexpressions, and the same way for the pattern with dynamic arrays.
Btw, I don't know why this does not match
pattern := '`.head `.@tail'.
expression := '(1@2) . Color red . 3'.
isn't the first variable a statement pattern ?
From the rewrite-tool documentation (
http://www.refactory.com/tools/refactoring-browser/rewrite-tool):
`�� �� �� ��
recurse into the thing that is matched looking for more matches
@�� �� �� ��treat the item as a list
;�� �� �� ��used for messages where the message is treated as a list of messages in a cascade
.�� �� �� ��treat the item as a statement in a sequence node
#�� �� �� ��matches literals
thanks in advance
nicolai