I wrote a grammar like this:
grammar StatementFormat {
token TOP { (<plain> | '%' <placeholder>)* }
token plain { <-[%]> }
token placeholder {
| <verb>
| <noun>
| <adverb>
}
token verb {
'v'
{
# some actions
}
}
token noun {
'n'
{
# some actions
}
}
token adverb {
'a'
{
# some actions
}
}
}
So I could use it to parse strings like "someone %v %n %a".
However, I found there were so many usages like "%v %n %a", I'd like to give it an alias, say, "%b" such that parsing "someone %b" is equivalent to parsing "someone %v %n %a".
So is there a way to do that?
Of course, token alias { 'b' { ... } }
can do that. But in that way I need to repeat that action code. I am wondering if there exists a simpler way.
%b
with%v %n %a
, then it's quite easy to implement the alias. But it seems raku does not support this feature. Do you think it useful? – Haemophiliac