Clojure 允许任意规则顺序的语法

Clojure 允许任意规则顺序的语法,clojure,dsl,context-free-grammar,instaparse,Clojure,Dsl,Context Free Grammar,Instaparse,我正在(尝试)设计一种特定于领域的语言(我称之为“华氏”)来设计引用样式 用华氏温度编写的程序: 必须正好有一个引用块 可能有零个或多个宏块 下面是一个简化但有效的示例: macro m1 "Hello World!" end macro m2 "Hello World!" end citation "Hello World!" end 该语法将识别上述代码的语法正确性: style = macro* citation (* example of macro defin

我正在(尝试)设计一种特定于领域的语言(我称之为“华氏”)来设计引用样式

用华氏温度编写的程序:

  • 必须正好有一个
    引用
  • 可能有零个或多个
下面是一个简化但有效的示例:

macro m1
  "Hello World!"
end

macro m2
  "Hello World!"
end

citation
  "Hello World!"
end
该语法将识别上述代码的语法正确性:

style = macro* citation

(*  example of macro definition

    macro hw
        "Hello World!"
    end

    *)

macro = <'macro'> #'[a-z0-9]+' statement+ end

citation = <'citation'> statement+ end

statement = #'".*?"'

<end> = <'end'>

PS:我打算添加顺序也不相关的其他可选块。

对于0..n规则,您可以将它们放在
引用之前或之后。例如

style = tools* citation tools*
tools = macro | foo | bar
...

对于0..n规则,您可以将它们放在
引用之前或之后。例如

style = tools* citation tools*
tools = macro | foo | bar
...

黑暗中拍摄:
style=macro*引文macro*
?@cfrick感谢您的帮助。我没有提到其他类型的块,它们的顺序也不相关。我更喜欢一个不必“硬编码”所有不同排列的解决方案。其他“非引用”规则可以组合成其他的
others=macros | something
,然后使用
others*
@cfrick哦,我明白了,那么我就可以做
style=others*引文others*
?我会试试的。@cfrick,这很有效!谢谢。你想把它作为一个答案吗?在黑暗中拍摄:
style=macro*引文macro*
?@cfrick谢谢你。我没有提到其他类型的块,它们的顺序也不相关。我更喜欢一个不必“硬编码”所有不同排列的解决方案。其他“非引用”规则可以组合成其他的
others=macros | something
,然后使用
others*
@cfrick哦,我明白了,那么我就可以做
style=others*引文others*
?我会试试的。@cfrick,这很有效!谢谢。你想把它作为一个答案吗?