Hello Gisela,

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.
 [ `@rcv size ]. 
 `@.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.

> 
> 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).

It should work like that (modulo bugs)
` denotes a metavariable
adding @ means you're looking for a list of elements 
ex: `receiver `@msg: `@arg matches every message
adding a . means you're looking for a statement (or a list of statement if you 
combine it with @)
adding # means you're looking for a literal
adding another ` means that the pattern will be searched recursively in each 
subexpressions even if the top one already matched 
it sometimes leads to infinite loops, but I don't remember exactly when 
ex: in 'foo bar bar' :
if you search for '`rcv bar' you'll find one match ('foo bar bar')
if you search for '``rcv bar' you'll find two matches ('foo bar' and 'foo bar 
bar').
and I think it's all

> 
> Any help with this will be really welcome!
> 
> 

Reply via email to