Markdown 标记为Xtext DSL
我想将Markdown构建为Xtext DSL。但解析像Markdown 标记为Xtext DSL,markdown,xtext,Markdown,Xtext,我想将Markdown构建为Xtext DSL。但解析像#简介这样的标题似乎很棘手,因为它没有明确的结束符号。有什么方法可以表达这一点吗?或者它通常(也不仅仅是Xtext限制)是不可能的 这是我的Xtext: grammar markdown.Markdown with org.eclipse.xtext.common.Terminals generate markdown "http://www.Markdown.markdown" Model: entities+=Entity*;
#简介
这样的标题似乎很棘手,因为它没有明确的结束符号。有什么方法可以表达这一点吗?或者它通常(也不仅仅是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:
.;
这些终端是从。有了这些语法规则,这是可能的:
# 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
...
Xtext基本语言中定义的单行注释终端非常类似:
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;
基本思想是:符号可以包含非行尾字符的任何字符。在Xtext基本语言中定义的单行注释终端非常类似:
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;
基本思想是:符号可以包含任何不是行尾字符的字符