[英]DSL for generating sequences
trying to create DSL to generate sequences... here is what i did so far:试图创建 DSL 来生成序列……这是我到目前为止所做的:
?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:这是 DSL 的样子:
(a b:2 (c d:3):2 ):3
[[a bb [[c ddd] [c ddd]] ] ... ]
I have problem with expr within expr... ?我在 expr... 中遇到 expr 问题?
this fails:这失败了:
(a:2 (b))
How do you see fitting (a:2 (b))
into your grammar?您如何看待(a:2 (b))
适合您的语法? It doesn't seem like you can.看来你做不到。 Here's my logic:这是我的逻辑:
The outer level has to be an expr
because of the parens.由于括号的原因,外层必须是一个expr
。 In that expr
you have both a repeat_token
and another expr
.在那个expr
你有一个repeat_token
和另一个expr
。 I don't see anywhere that lets you have a sequence of elements that includes both repeat_token
s and expr
s.我看不到任何地方可以让您拥有包含repeat_token
和expr
的元素序列。 Because of that, your input can't be parsed with your grammar.因此,您的输入无法用您的语法进行解析。
As it is, a expr
can only be in another expr
all by itself, which doesn't seem very useful in general.事实上,一个expr
只能单独存在于另一个expr
中,这通常看起来不是很有用。 That could only lead to extra sets of parentheses I think.我认为这只会导致多套括号。 What I think you need to do is allow an expr
to be included in a tokens
.我认为您需要做的是允许将expr
包含在tokens
中。
So then maybe:那么也许:
?start : expr
token : WORD
repeat_token : token ":" INT
tokens : (token | repeat_token | expr)+
repeat : ":" INT
expr : "(" tokens ")" repeat?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.