lark icon indicating copy to clipboard operation
lark copied to clipboard

Lark grammar?

Open davaya opened this issue 5 years ago • 8 comments

Are there any plans to create a Lark grammar for Lark? The only file currently in lark/grammars is common.lark, which defines a few terminals.

The authoritative definition of Lark would logically be expressed as a grammar (as opposed to "what the grammar reference says" or "what the latest version of the code parses"). Note that RFC 5234 defines the ABNF grammar that authoritatively validates ABNF specifications.

davaya avatar May 28 '19 15:05 davaya

There is a reference-quality grammar in ./examples: https://github.com/lark-parser/lark/blob/master/examples/lark.lark

Do you think there is a benefit to making it formal?

erezsh avatar May 28 '19 21:05 erezsh

Yes, I think there should be a formal lark-grammar for lark. Mainly, so that I can apply it to the intellij-plugin I am developing and the theoretically planed linter I think about developing.

MegaIng avatar Jun 28 '19 09:06 MegaIng

Well, you can already use the grammar I linked to. It's correct and fairly comprehensive.

erezsh avatar Jun 28 '19 09:06 erezsh

There are some things in lark.lark that don't match what load_grammar.py implements. For example, I learned the hard way that load_grammar only allows rule aliases on top-level alternates, although lark.lark says they're valid on alternates at any depth. Another example is that lark.lark says "%ignore" expansions, but load_grammar requires that expansions be derived as expansions -> expansion -> value -> Terminal.

RossPatterson avatar Jan 28 '24 23:01 RossPatterson

You're welcome to submit a PR that fixes lark.lark

erezsh avatar Jan 29 '24 03:01 erezsh

Sounds good. I wasn't sure which version was definitive. So, basically the loader is correct and the grammar should reflect what it does, right?

While I'm at it, I'll take a look at the grammar reference documentation and make sure it agrees with the loader code.

RossPatterson avatar Jan 29 '24 03:01 RossPatterson

Yes, load_grammar.py is the "ground truth", for better or worse.

erezsh avatar Jan 29 '24 03:01 erezsh

PR #1388 submitted for my observations above, plus several others I found.

RossPatterson avatar Feb 01 '24 01:02 RossPatterson