I'm wondering if it's possible to use an anonymous variable here to match the type of a node. For example from http://tutor.rascal-mpl.org/Rascal/Expressions/Values/Location/Location.html#/Rascal/Patterns/Abstract/TypedLabelled/TypedLabelled.html):
case Exp e:_(_,_): println("And I found an Exp <e>");
which would match both the add and subtract Exp nodes. I've been experimenting a bit with something like this but haven't had any success.
(Apologies, I posted this in the comments section on the website before I saw the link to ask.rascal)
Building on Davy's answer, you could do something like this if you only want to match constructors that take two parameters:
rascal>data D = d1(int n) | d2(int n, int m) | d3(int n,int m);
ok
rascal>D d: str s(_,_) := d2(3,4);
bool: true
rascal>D d: str s(_,_) := d1(3);
bool: false
Normally in a match of this form you would use the constructor name. Using str s
instead forces this to be a generic node match, where nodes are given as the node name (a string, here the constructor name) and the node parameters (here, we assume two parameters). This may be useful if there are a large number of these types of matches, but otherwise I would recommend just writing them individually.