简体   繁体   English

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

[英]idea grammar-kit recoverWhile beaks the parser on the first element in list

I have a bnf grammar: 我有一个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)*

Text to test: 要测试的文字:

Fiction Book: Some Fiction
    Section: Chapter One
    Section: Chapter Two Section
    Content: Chapter Three

If I make an error in second or later element all be ok, but if in the first Sectio: Chapter One all psi tree will be broken. 如果我在第二个或更高版本的元素中出错,则一切正常,但在第一个Sectio: Chapter One所有psi树将被破坏。

在此处输入图片说明

I see several problems: 1) you should have whitespace token. 我看到几个问题:1)您应该有空白令牌。 Something like this: 像这样:

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

as a consequence, you don't need space and npsp anymore 结果,您不再需要空间和npsp

2) recoverWhile rule should be specified without quotes 2)restoreWhile规则应指定不带引号

3) sectionRecover matching whitespaces which most likely is incorrect 3)部分恢复最有可能不正确的匹配空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM