将语法分析器放在列表中的第一个元素上时将想法语法工具包恢复

时间:2018-11-19 04:28:56

标签: parsing grammar intellij-plugin bnf grammar-kit

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

enter image description here

1 个答案:

答案 0 :(得分:0)

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

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

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

2)recoveryWhile规则应不带引号

3)部分恢复最有可能不正确的匹配空格