1

我有一个 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 树都会被破坏。

在此处输入图像描述

4

1 回答 1

1

我看到几个问题:1)你应该有空白令牌。像这样的东西:

WHITESPACE="regexp:[ \n\r\t\f]"

因此,您不再需要空间和 npsp

2)recoverWhile 规则应指定不带引号

3) sectionRecover 匹配的最有可能不正确的空格

于 2018-11-20T11:48:28.470 回答