AbnfParsec - ABNF in, parser out

Hi all,

This probably has a very small audience, but :man_shrugging:

Both the hand written ABNF parser and the generated parsers are using nimble_parsec.

Example usage: https://github.com/princemaple/elixir-imap/blob/master/lib/imap/parser.ex

14 Likes

Not so small, will definitely use it :slight_smile:

Thanks for the great work!

1 Like

[Removed, looks like I suck at copy pasing]

Gosh those RFCs are hard to use. I cant’ find a version without the body being cut with footer and headers.

By the way, thank you very much for this project.

1 Like

Indeed I have been having some problems when generating parsers. One example,

I took the IRI grammar from RFC 3987 - Internationalized Resource Identifiers (IRIs) and saved it as a file: jsv/priv/grammars/iri.abnf at main · lud/jsv · GitHub

But it does not seem to fully parse this IRI: https://en.wiktionary.org/wiki/Ῥόδος, it returns {:ok, ...} but does not consume the whole string.

Hi @lud , I did a quick test and indeed the given url is not parsed fully. I also tested swapping the last part with Chinese “你好” and it parsed correctly. I’m not an expert in encoding and am currently unsure if it’s the functionality or the data that’s causing this. Shall we move the discussion to an issue on the repo?

Yes I’ll create the issue.

Edit: here you go

v1.3.0 was released with a special byte mode, in case your ABNF describes byte representation in stead of codepoints.

4 Likes

v2.0.0

Highlights :tada:

  • Core rules are no longer special-cased, they are brought in via parsing and compiling core.abnf
    • hence they can now be transformed, ignored, just like other rules
  • Core rules are now all transformed to string format by default
    • so when matching *HEXDIG on "1A", instead of getting [49, 65], you get ["1", "A"]
    • however, performing List.to_string on either one gives you the same result - "1A"
  • Core rules are defined only when they are not already defined in your abnf
    • if they are already defined in your abnf, they will be skipped
    • note the way we generate the functions unifies cases, so if you have char defined,
      the core rule CHAR will be ignored as well
    • this also makes it possible to override core rules
3 Likes