Alhadis / language-grammars

Syntax highlighting for ABNF/BNF/EBNF, Yacc, and other language-related languages.
https://atom.io/packages/language-grammars
ISC License
19 stars 5 forks source link

Support for Lark-style EBNF #4

Closed ThatXliner closed 4 years ago

ThatXliner commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

Figure 1
Alhadis commented 4 years ago

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