Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Lark-style EBNF #4

Closed
ThatXliner opened this issue Oct 6, 2020 · 3 comments
Closed

Support for Lark-style EBNF #4

ThatXliner opened this issue Oct 6, 2020 · 3 comments

Comments

@ThatXliner
Copy link

ThatXliner commented Oct 6, 2020

Lark is a parsing library for python. It's flavored EBNF files (.lark) needs syntax highlighting. The only difference between lark EBNF (which I'll refer to as LEBNF) and EBNF is that LEBNF's comments are js-style, without multi-line comment support, brackets denote optional groups, a ? and/or ! are operators that may appear before the definition of a rule or TERMINAL, priority, denoted by TERMINAL.number, is a thing, and it has %import, %ignore, and %declare statements.

Detailed grammar reference can be found here

Would you modify EBNF.cson, and turn it to LEBNF.cson, please? I have no idea on how to write an atom grammar (I find it poorly documented on atom.io)

@Alhadis
Copy link
Owner

Alhadis commented Oct 13, 2020

I'll see what I can do. 👍 Rather than modify EBNF's grammar, though, it'll be better to add a dedicated grammar for LEBNF instead. Lark's format is well-defined and uses a non-conflicting file extension, whereas ebnf.cson attempts to accommodate every syntax variation that might be encountered in .ebnf files (which rarely conform to ISO/IEC 14977).

I have no idea on how to write an atom grammar (I find it poorly documented on atom.io)

It's actually TextMate's grammar format, adopted by Atom/GitHub, VSCode, and Sublime Text. Each have different requirements on file format: Atom uses CSON/JSON, VSCode and TextMate use XML property lists, and Sublime uses YAML. Regardless of their representation, all TextMate-compatible grammars are structurally similar, and the ones you'll encounter are often converted from a TextMate bundle (except mine… I proudly pen them all from scratch).

Other than TextMate's grammar reference, the only other reliable source of info (that I know of) is this blog post. It covers several critical (but undocumented) details of writing a TMCG, and discusses the hacks necessary to work around TextMate's notorious lack of multiline pattern support.

@Alhadis
Copy link
Owner

Alhadis commented Oct 13, 2020

Righto, all done! This covers everything in both the docs and Lark's own grammar definition. Here's a preview:

Figure 1

@Alhadis
Copy link
Owner

Alhadis commented Oct 14, 2020

I've also submitted a PR to have Lark grammars supported/highlighted on GitHub. See github-linguist/linguist#5049.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants