Hi nicolai

I always thought that I understand and I always find a situation that totally confused me. This is why I asked some guys expert in transformation to have a look and they got confused.
This is why camille teruel started to work with Mark on Phorms.
But the effort got stalled.

Stef

Background :

initial question:
http://forum.world.st/RewriteTool-matching-parts-of-an-array-tp4910482.html
my fix :
18910 MNU: OrderedCollection>>parent: when trying to rewrite a tree with RBParseTreeRewriter

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)-expressions1@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







--
Using Opera's mail client: http://www.opera.com/mail/

Reply via email to