On 21 ao�t 2013, at 15:43, Gisela Decuzzi wrote:
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.
Putting a dot after the @ means that you want to match statements.
So '``@.some size' cannot match: 'arg1 size'.
Does not match with:
insideABlock: arg1 part2: arg2
|temp1 temp3|
[arg1 size].
temp1 := arg2 + 3.
^arg2
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.
`@.stms2.
After looking while I realize that is not matching with
part1: arg1 part2: arg2
|temp1 temp2 temp3|
arg1 size.
temp1 := arg2 + 3.
^arg2
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.