Markdown 的 XText 语法

XText grammar for markdown

我正在为 Markdown 语法编写 XText 语法。在markdown中h1可以写成#heading

因此,Heading 可以匹配换行符以外的任何内容。

grammar org.example.domainmodel.DomainModel with org.eclipse.xtext.common.Terminals

generate domainModel "http://www.example.org/domainmodel/DomainModel"

DomainModel:
    (elements += Element)*
;

Element:
    Section1 | Section2
;

Section1:
    '#' name += HEADING '\n'
;

Section2:
    '##' name += HEADING '\n'
;

terminal HEADING: (('A'..'Z') | '_'| ('a'..'z') | ('0'..'9') | '-')* ;

但这给出了错误:

The following token definitions can never be matched because prior tokens match the same input: RULE_INT

此外,标题不能有任何特殊字符。

这个语法的正确写法是什么?

不使用新的终端规则 HEADING,而是使用已经定义的终端规则 ID:

Section1:
    '#' name = ID '\n'
;

Section2:
   '##' name = ID '\n'
;