Hi Tony,
I have a language which looks a bit like this:
"test" match {
if _ == "bar" then ...
if _.size < 5 then ...
else ...
}
Given
MatchExpr(subject: Expr, ifBranches: List[Expr], /*let's ignore the then expr for now */ elseBranch: Expr)
, the AST looks like this:
MatchExpr(
Literal("test"),
List(
BinaryExpr(Placeholder, EQ, Literal("bar")),
BinaryExpr(Call(Placeholder, Method("size")), LT, Literal(5))
),
...
)
What would be the most idiomatic way in Kiama to replace the Placeholder with the subject?
Basically I want to say something like "given a match expression, I want to traverse all nodes under it, and replace some of them (placeholders) with a value from the match expression (subject)", so that I get a tree like this:
MatchExpr(
Literal("test"),
List(
BinaryExpr(Literal("test"), EQ, Literal("bar")),
BinaryExpr(Call(Literal("test"), Method("size")), LT, Literal(5))
),
...
)
I'm a bit unsure how to capture the subject or pass the context (the subject) around with the the right macro invocation. Do you have any suggestions?
Thanks,
Simon