我正在尝试为 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 无法匹配输入的结尾。