0
我試圖用Antlr4解析MarkDown文本。爲了方便起見,我首先解析list
視圖。 我找到了一個關於它的網頁。 http://www.cforcoding.com/2010/01/markdown-and-introduction-to-parsing.html解析MarkDown文件中的列表格式使用Antlr4
在該網頁上的語法似乎確定對我來說,我將其更改爲適合Antlr4格式是這樣的:
grammar MarkDown;
listItem : ORDERED inline NEWLINE
| UNORDERED inline NEWLINE
;
inline : (~ NEWLINE)+ ;
ORDERED : DIGIT+ '.' (' ' | '\t')+ ;
UNORDERED : ('*' | '-' | '+') (' ' | '\t')+ ;
DIGIT : [0-9]+ ;
NEWLINE : '\r'? '\n' ;
例如文件
1. abc
2. kljjkj
3. tree4545
但它不工作,錯誤以下信息
line 1:3 token recognition error at: 'a'
line 1:4 token recognition error at: 'b'
line 1:5 token recognition error at: 'c'
line 1:6 extraneous input '\r\n' expecting {ORDERED, UNORDERED, DIGIT}
line 2:3 token recognition error at: 'k'
line 2:4 token recognition error at: 'l'
line 2:5 token recognition error at: 'j'
line 2:6 token recognition error at: 'j'
line 2:7 token recognition error at: 'k'
line 2:8 token recognition error at: 'j'
(listItem 1. (inline \r\n 2.) \r\n)
你能幫我解決這個問題嗎?
感謝您的答覆。你能否直接提出解決問題的建議?看看我能否輕鬆理解。 – jmuok