trying to create DSL to generate sequences ... here is what i did so far :
?start : expr
token : WORD
repeat_token : token ":" INT
tokens : (token | repeat_token)+
repeat : ":" INT
expr : "(" tokens | expr ")" repeat?
here is how the DSL look like :
(a b:2 (c d:3):2 ):3
[[a bb [[c ddd] [c ddd]] ] ... ]
I have problem with expr within expr ... ?
this fails:
(a:2 (b))
How do you see fitting
(a:2 (b))
into your grammar? It doesn't seem like you can. Here's my logic:The outer level has to be an
expr
because of the parens. In thatexpr
you have both arepeat_token
and anotherexpr
. I don't see anywhere that lets you have a sequence of elements that includes bothrepeat_token
s andexpr
s. Because of that, your input can't be parsed with your grammar.As it is, a
expr
can only be in anotherexpr
all by itself, which doesn't seem very useful in general. That could only lead to extra sets of parentheses I think. What I think you need to do is allow anexpr
to be included in atokens
.So then maybe: