5
我試圖寫一個簡單的語法爲將匹配像這樣PEG.js的PEG.js結束:麻煩的輸入
some text;
arbitrary other text that can also have µnicode; different expression;
let's escape the \; semicolon, and \not recognized escapes are not a problem;
possibly last expression not ending with semicolon
所以基本上這些都是用分號隔開一些文本。我的簡化語法如下:
start
= flow:Flow
Flow
= instructions:Instruction*
Instruction
= Empty/Text
TextCharacter
= "\\;"/
.
Text
= text:TextCharacter+ ';' {return text.join('')}
Empty
= Semicolon
Semicolon "semicolon"
= ';'
的問題是,如果我把比分號以外的任何輸入,我得到:
SyntaxError: Expected ";", "\\;" or any character but end of input found.
如何解決這個問題?我讀過PEG.js無法匹配輸入的結尾。
FWIW,您可以將輸入的結尾與'!.' – ebohlman