question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Construct a Lark grammar from ABNF format (RFC 5234)

See original GitHub issue

RFC 5234 describes the standard grammar format for internet standards, such as the notoriously-hard-to-validate email addresses.

Because this standard is a dialect of EBNF and does not allow for embedded code, it should be relatively easy to construct a Lark object for a given ABNF grammar - at least easier than converting from Nearley! Hopefully it’s easy enough that runtime conversion in a new Lark.from_abnf method (or group of methods) would be practical.

This feature request is based on HypothesisWorks/hypothesis#170, where I eventually realized that parsing ABNF was going to be easier as well as more widely useful upstream. I’d be happy to work on this with some guidance about where to start, and have already translated the grammar of ABNF from ABNF to Lark’s format.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
erezshcommented, Feb 4, 2019

I think it’s a nice idea. I think your best bet is to create a Lark parser that reproduces the output of the GrammarLoader parser : https://github.com/lark-parser/lark/blob/master/lark/load_grammar.py#L663

You might have to do some post-processing (for example, in a Transformer) to make them a perfect fit.

Once you have that working, I’ll add an interface to plug it in there when called with ABNF grammar.

While using Lark.from_abnf isn’t bad (and can be complemented with Lark.open_abnf), how about doing this instead?

parser = Lark("... grammar ... ", syntax='abnf')

That opens the door to adding other formats in the future.

1reaction
erezshcommented, May 23, 2019

simply cannot be expressed at all in ABNF

In that situation, it’s common to add new language features that don’t break the old one. For example a new operator, that works in lark and not ABNF, but you don’t have to use it.

saving the grammar to a Lark file, allows the developer edit that file to add features to the grammar

That seems a bit cumbersome. Why not just a have an translator from Extended-ABNF into ABNF? It should be fairly easy, just removing and canonizing some nodes, and then writing it back. It’s simple enough that Lark’s reconstructor might even be able to handle it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ABNF grammar support V2 by t-higuchi · Pull Request #1022 · lark ...
t-higuchi wants to merge 5 commits into lark-parser:master. base: master ... Added support for grammar in ABNF format (RFC5234 and RFC7405)
Read more >
Grammar Reference - Lark documentation - Read the Docs
A grammar is a list of rules and terminals, that together define a language. Terminals define the alphabet of the language, while rules...
Read more >
ABNF Grammars in Elixir
This article is about how to parse and use ABNF grammars in elixir. ... which is obsoleted by RFC4234 which in turn is...
Read more >
A Type-Theoretic Model on NDN-TLV Encoding
In this paper, we make a first step toward an NDN-TLV encoding model via the following contributions: ... ABNF. RFC 5234. https://doi.org/10.17487/RFC5234.
Read more >
Hypothesis Documentation - Read the Docs
Hypothesis is a Python library for creating unit tests which are simpler to write and more powerful ... such as ANTLR and RFC...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found