Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?).

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?

Thank you for your help and best regards, Fuchs

like image 602
Fuchs Avatar asked Feb 09 '18 08:02

Fuchs


People also ask

What is a PIN in computers?

1) A pin is a pronged contact as part of a signal interface in a computer or other communications device. Pins are part of a male connector and plug into a female connector. The number of pins in a connector is sometimes used in describing the connector (for example, "a 25-way D-type connector").

Are pins legs?

Informally, legs can be called pins, although this is now rather dated. As a verb, to pin means 'to fasten with or as with a pin' and 'to hold something or someone still in one place. ' Unrelatedly, a PIN is also an identification number that gives you access to an automatic machine or other device.

What is a PIN in Pinterest?

What are Pins? Pins are bookmarks that people use to save content they love on Pinterest. People can search for Pins, save the ones they like and click on a Pin to learn more. If you have a business account , you can create Pins that link back to your website to share your products and ideas with people on Pinterest.


1 Answers

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

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 specifies a part of the rule (by index or literally) after successful parsing of which the rule considered successful. In the example:

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

if expr1 is matched, the whole rule will be considered successful and parser will try yo match the rest.

if pin=2 the rule will be considered successful after matching "+" and will fail if expr1 or "+" not matched.

RecoverWhile attribute specifies where to skip after parsing the rule. Independently of its success. For example

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

will skip all input before ";" or ".". I.e. parser will start matching next rule from ";" or ".".

like image 77
Argb32 Avatar answered Oct 11 '22 18:10

Argb32