简体   繁体   English

固定并恢复在.bnf(解析)中

[英]Pin & recoverWhile in a .bnf (Parsing)

I've searched the internet far and wide (for at least half a day now) and I can't seem to find the answers needed. 我已经远程搜索了互联网(现在至少半天),我似乎无法找到所需的答案。

Currently I'm trying to create a .bnf-file for an IntelliJ-Plugin with custom language support. 目前我正在尝试为自定义语言支持的IntelliJ-Plugin创建一个.bnf-file

A few tutorials mention the existance of {pin=1} , {pin=2} and {recoverWhile=xyz} , but I didn't find any real explanation on their uses, and if there are any other things I should know (maybe a {pin=3} also exists?). 一些教程提到了{pin=1}{pin=2}{recoverWhile=xyz} ,但我没有找到任何关于它们用途的真实解释,如果还有其他事情我应该知道(也许a {pin=3}也存在?)。

So could somebody tell me what exactly those flags, methods or however they're called are, and how to use them in my .bnf, please? 那么有人可以告诉我究竟是什么标志,方法或者它们被称为是什么,以及如何在我的.bnf中使用它们,好吗?

Thank you for your help and best regards, Fuchs 感谢您的帮助和最好的问候,Fuchs

These attributes are explained here: 这些属性在这里解释:

https://github.com/JetBrains/Grammar-Kit/blob/master/HOWTO.md#22-using-recoverwhile-attribute https://github.com/JetBrains/Grammar-Kit/blob/master/TUTORIAL.md https://github.com/JetBrains/Grammar-Kit/blob/master/HOWTO.md#22-using-recoverwhile-attribute https://github.com/JetBrains/Grammar-Kit/blob/master/TUTORIAL.md

But the usage is not trivial. 但用法并非微不足道。 A good idea is to use Live Preview to play around with it. 一个好主意是使用实时预览来玩它。

My understanding: 我的理解:

Pin and recoverWhile attributes are used to recover parser from errors. Pin和recoverWhile属性用于从错误中恢复解析器。

Pin specifies a part of the rule (by index or literally) after successfull parsing of which the rule considered successull. Pin在成功解析之后指定规则的一部分(通过索引或字面),其中规则认为是成功的。 In the example: 在示例中:

expr ::= expr1 "+" expr2 {pin=1}

if expr1 is matched, the whole rule will be considered successfull and parser will try yo match the rest. 如果匹配expr1,则整个规则将被视为成功,并且解析器将尝试与其余规则匹配。

if pin=2 the rule will be considered succesfull after matching "+" and will fail if expr1 or "+" not matched. 如果pin = 2,则匹配“+”后规则将被视为成功,如果expr1或“+”不匹配则将失败。

RecoverWhile attribute specifies where to skip after parsing the rule. RecoverWhile属性指定解析规则后要跳过的位置。 Independently of its success. 独立于其成功。 For example 例如

{recoverWhile=expr_recover}
expr_recover ::= !(";" | ".)

will skip all input before ";" 将在“;”之前跳过所有输入 or ".". 要么 ”。”。 Ie parser will start matching next rule from ";" 即解析器将开始匹配来自“;”的下一个规则 or ".". 要么 ”。”。

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

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