I would like to be able to pattern match on ATerm parameters.

eval(|"methpar-1") = is-methodreference
eval(|"methpar-2") = methodreference-get-method
eval(|"methpar-3") = methodreference-get-params;map(param-get-name)
eval(|"methpar-4") = methodreference-get-method

Should be sugar for

eval(|f) = where("methpar-1":=f); is-methodreference
eval(|f) = where("methpar-2":=f); methodreference-get-method
eval(|f) = where("methpar-3":=f); methodreference-get-params;map(param-get-name)
eval(|f) = where("methpar-4":=f); methodreference-get-method
Submitted by Daco Harkes on 16 January 2015 at 13:50

On 16 January 2015 at 14:05 Eelco Visser commented:

You mean you want to be able to pattern match on term parameters! Strategy parameters are the parameters before the |

Yes, I’ve wanted to do that myself.

This requires an extension of the syntax + a desugaring. Shouldn’t be too hard. And it should work for rules as well, of course.

On 16 January 2015 at 14:16 Daco Harkes commented:

Yes, sorry for the confusion of calling it both term and strategy parameters. (Note I called it ATerm parameters because the stratego xt api calls it ATerm parameters.)

By the looks of it it is indeed just a syntax extension (it doesnt parse now) + syntactic desugaring.

On 21 January 2015 at 16:04 D. Pelsmaeker commented:

This feature has now been added to Stratego. See metaborg/strategoxt/pull#14. The syntax is as follows:

You can specify any term as a term parameter to a strategy or rule, not just variables. You can mix-and-match term variables with term patterns:

 mystrategy(|"exact", v) = !v

Use a wildcard if you don’t care about the value:

 mystrategy(|_) = !()

The syntax works for both rules and strategies:

 myrule(|"exact"): x -> x

Strategy application is supported:

 mystrategy(|<newname> "a") = !()

…also without a term:

 myrule(|<id>): _ -> ()

…which allows negative matching:

mystrategy(|<not(?"x")>) = id

As an example, a switch-case using strategies:

to-english(|1) = !"one"
to-english(|2) = !"two"
to-english(|_) = !"many"

On 21 January 2015 at 22:32 Eelco Visser commented:

Thanks Daniël! Can you put this documentation on the website?


On 22 January 2015 at 10:47 D. Pelsmaeker commented:

Sure, but where would you want me to put it? There is only very limited Stratego documentation on metaborg.org, the main documentation is on strategoxt.org.

On 22 January 2015 at 16:00 Eelco Visser commented:

Somewhere in the stratego directory; we should get started somehow.

Log in to post comments