我想将Markdown构建为Xtext。但是解析像# Introduction这样的标题似乎很棘手,因为它没有明确的结束符号。有什么办法表达这一点吗?还是一般情况下(也不仅仅是Xtext限制)不可能?
这是我的Xtext:
grammar markdown.Markdown with org.eclipse.xtext.common.Terminals
generate markdown "http://www.Markdown.markdown"
Model:
entities+=Entity*;
Entity:
Section | Subsection | Paragraph
;
Section:
'#'
content+=TextPart
'::'
;
Subsection:
'##'
content+=TextPart
'::'
;
Paragraph:
content+=TextPart
;
TextPart:
text=Text
;
Text:
(ID | WS | SINGLE_NL | MULTI_NL | ANY_OTHER | '\\[' | '\\]' | ',' | "-" | '\\:' | '\\%' | '\\#' | '\\##' )+;
terminal ID:
('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;
terminal SL_COMMENT:
'%%' !('\n' | '\r')* ('\r'? '\n');
terminal MULTI_NL:
'\r'? '\n' (/*(' ' | '\t')**/ '\r'? '\n')+;
terminal SINGLE_NL:
'\r'? '\n';
terminal WS:
' ' | '\t';
terminal ANY_OTHER:
.;终端来自Xdoc。有了这种语法规则,这是可能的:
# Introduction ::
Lorem ipsum.
## Other chapter ::
Lorem ipsum.但我喜欢这样的降价:
# Introduction
Lorem ipsum.
## Other chapter
Lorem ipsum.因此,我们需要\n而不是::作为结束。但这有可能吗?此外,antlr生成由终端规则引起的警告。但是在构建Xdoc.xtext时不会出现这种警告。我的错是什么?
warning(200): ../markdown/src-gen/markdown/parser/antlr/internal/InternalMarkdown.g:436:1: Decision can match input such as "'-'" using multiple alternatives: 9, 14
As a result, alternative(s) 14 were disabled for that input
warning(200): ../markdown/src-gen/markdown/parser/antlr/internal/InternalMarkdown.g:436:1: Decision can match input such as "'\\['" using multiple alternatives: 6, 14
As a result, alternative(s) 14 were disabled for that input
...发布于 2014-01-07 21:12:06
用Xtext基语言定义的单行注释终端非常类似:
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;其基本思想是:符号可以包含任何不是行字符末尾的字符。
https://stackoverflow.com/questions/20924402
复制相似问题