I am looking for a way to know if an optional sub rule has been used or not. For example:
my_rule returns [node* n = 0]:
(v = (optional_subrule)?)
{
$n = new node($v ? $v.n : MY_DEFAULT_VALUE);
}
;
But this does not work. I tried many ways to write it and nothing seems to be possible without writing code...
my_rule returns [node* n = new node()]:
((optional_subrule { n->set_subrule(...); })?)
;
And when you have a bison background, you like having your ast node constructors at the end of your rules... And it decreases the readability (imagine a much more bigger rule).
Does anyone know something I missed ?
Thank you.