Hello, I'm trying to understand how to define a correct pattern and I'm lost with the cases where I use a method pattern and the desired code is inside a block. In the case where we search (methods) with metavariables and the code is inside a block.
An Example: This pattern `a: `aa `b: `bb | `@temps | ``@.Stats. ``@.some size ``@.more. ``@.Stats2. Does not match with: insideABlock: arg1 part2: arg2 |temp1 temp3| [arg1 size].
temp1 := arg2 + 3. ^arg2 After looking while I realize that is not matching with
part1: arg1 part2: arg2 |temp1 temp2 temp3| arg1 size. temp1 := arg2 + 3.
^arg2 Until I understand: ``@.some size ``@.more. This should mean: anything that sends the message size, doesn't matter if we have something before or after, I think that this expression should match both cases.
But maybe I'm missunderstanding the patterns (again). Any help with this will be really welcome! |
Hello Gisela,
On 21 août 2013, at 15:43, Gisela Decuzzi wrote:
Putting a dot after the @ means that you want to match statements. So '``@.some size' cannot match: 'arg1 size'.
Then even if you remove the extra dots, the rule won't match the method you give. This is because this method has no statements matching '``@some size' (even if it has a block that has a statement that can). So here is a rule that can match your method: `a: `aa `b: `bb | `@temps | `@.stms1. [ `@rcv size ].
This one however can be matched by your rule (without the extra dots). I think that you should try to parse expressions instead of full methods (RBParseTreeSearcher>>#matches:do: instead of RBParseTreeSearcher>>#matchesMethod:do:). You could just try to match '`@rcv size': it would succeed in both methods.
It should work like that (modulo bugs)
|
Hi Camille! Thanks for the details about using the dot. I know that for this case is better matching an expression but it sounded strange at the begining the behavior inside the block despite of the ``@
I will take a look in the matching. Because like that we cannot say that we don't care if we have that piece of code and we should repeat the pattern with an or containing the block and without it. But I don't understand if the actual behavior is really a bug or it's a feature...
2013/8/21 Camille Teruel <[hidden email]>
|
On 23 août 2013, at 05:16, Gisela Decuzzi wrote:
As far as I understand, there is no difference between ` and `` when you try to match a method because there is no such thing as a submethod. No matter where you recurse in a method, you'll never find another method that can potentially match.
Good luck. Stef suggested to see in visualworks if there is a new version.
What you can do is still to try matching an expression but with an additional condition. By the way I forgot to mention the `{ :node | "some smalltalk code here" } syntax in my last mail: it permits to match only the nodes that satisfy the "wrapped block".
Its more a limitation.
|
Free forum by Nabble | Edit this page |