我有一个 bnf 语法:
{
tokens = [
COLON = ":"
space=' '
word = 'regexp:[^\r\n\s\t@\$\{\}\(\)\|\#:<>]+'
nl = 'regexp:\r|\n|(\r\n)'
]
}
root ::= nlsp book_keyword COLON [space] book_title sections
book_keyword ::= 'Journal Book' | 'Fiction Book'
book_title ::= (! section (word | string) space?)+
sections ::= section+
section ::= nlsp section_keyword COLON [space] section_title {recoverWhile='sectionRecover'}
section_keyword ::= 'Section' | 'Content'
section_title ::= (!section (word | space | COLON))+
sectionRecover ::= !(nlsp| section_keyword)
nlsp ::= (NL| space)*
要测试的文本:
Fiction Book: Some Fiction
Section: Chapter One
Section: Chapter Two Section
Content: Chapter Three
如果我在第二个或以后的元素中出错,一切都可以,但如果在第一个元素中,Sectio: Chapter One
所有 psi 树都会被破坏。