Skip to content

Latest commit

 

History

History
64 lines (53 loc) · 1.92 KB

README.md

File metadata and controls

64 lines (53 loc) · 1.92 KB

Abnf

Build Status

Example

iex(1)> parser = Abnf.load("priv/rfc5234.abnf")
Rfc5234
iex(2)> parser.parse(:rule, "DQUOTE = %x22\r\n")
[{:rule, "DQUOTE = %x22\r\n",
  [{:rulename, "DQUOTE",
    [{:ALPHA, "D", [{:literal, "D", []}]}, {:ALPHA, "Q", [{:literal, "Q", []}]},
     {:ALPHA, "U", [{:literal, "U", []}]}, {:ALPHA, "O", [{:literal, "O", []}]},
     {:ALPHA, "T", [{:literal, "T", []}]},
     {:ALPHA, "E", [{:literal, "E", []}]}]},
   {:"defined-as", " = ",
    [{:"c-wsp", " ", [{:WSP, " ", [{:SP, " ", [{:literal, " ", []}]}]}]},
     {:literal, "=", []},
     {:"c-wsp", " ", [{:WSP, " ", [{:SP, " ", [{:literal, " ", []}]}]}]}]},
   {:elements, "%x22",
    [{:alternation, "%x22",
      [{:concatenation, "%x22",
        [{:repetition, "%x22",
          [{:element, "%x22",
            [{:"num-val", "%x22",
              [{:literal, "%", []},
               {:"hex-val", "x22",
                [{:literal, "x", []},
                 {:HEXDIG, "2", [{:DIGIT, "2", [{:literal, "2", []}]}]},
                 {:HEXDIG, "2",
                  [{:DIGIT, "2", [{:literal, "2", []}]}]}]}]}]}]}]}]}]},
   {:"c-nl", "\r\n",
    [{:CRLF, "\r\n",
      [{:CR, "\r", [{:literal, "\r", []}]},
       {:LF, "\n", [{:literal, "\n", []}]}]}]}]}]

TODO

  • Build minimal parser
  • Build minimal generator
  • Use self-hosted parser
  • Parse rfc2822
  • Clean up generator
  • Improve test coverage
  • Log error messages during parsing
  • Improve UX of parsing for specific rules

Installation

If available in Hex, the package can be installed as:

  1. Add abnf to your list of dependencies in mix.exs:

    def deps do [{:abnf, "~> 0.0.1"}] end

  2. Ensure abnf is started before your application:

    def application do [applications: [:abnf]] end