marcelog / ex_abnf

Parser for ABNF Grammars
Apache License 2.0
61 stars 12 forks source link

Unable to load example grammar file #7

Closed OldhamMade closed 8 years ago

OldhamMade commented 8 years ago

Trying to parse the example test/resources/ipv4.abnf provided with the repository, I get this result.

iex(1)> grammar = ABNF.load_file "ipv4.abnf"
** (throw) {:incomplete_parsing, 'IPv4address =\n  dec-octet "."\n  dec-octet "."\n  dec-octet "."\n  dec-octet !!!\n    state = Map.put state, :ipv4address, rule\n    {:ok, state, "Your ip address is: \#{rule}"}\n  !!!\n\ndec-octet = DIGIT         ; 0-9\n  / %x31-39 DIGIT         ; 10-99\n  / "1" 2DIGIT            ; 100-199\n  / "2" %x30-34 DIGIT     ; 200-249\n  / "25" %x30-35          ; 250-255\n\nDIGIT = %x30-39\n'}
    lib/ex_abnf.ex:41: ABNF.load/1

Unit tests run successfully.

Version info (running on OS X Mavericks 10.11.2):

> elixir -v
Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.2.0
OldhamMade commented 8 years ago

It seems as though the examples all use DOS line endings (CLRF). If you use unix line endings, the parser fails.

marcelog commented 8 years ago

Hello!

It is correct that DOS line endings are required in the abnf files since 0.2 (as the README states). The change was made to make it compatible with how the RFC defines the rules:

A rule is defined by the following sequence: name = elements crlf

where is the name of the rule, is one or more rule names or terminal specifications, and crlf

However, this does work for me:

$ iex -S mix
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> grammar = ABNF.load_file "test/resources/ipv4.abnf"

I'm using elixir 1.1.1 currently. Will try 1.2.0 and let you know.

marcelog commented 8 years ago
Interactive Elixir (1.2.0) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> grammar = ABNF.load_file "test/resources/ipv4.abnf"

iex(2)> ABNF.apply grammar, "ipv4address", '192.168.0.10', %{}
%ABNF.CaptureResult{input: '192.168.0.10', rest: [],
 state: %{ipv4address: '192.168.0.10'}, string_text: '192.168.0.10',
 string_tokens: ['192', '.', '168', '.', '0', '.', '10'],
 values: ["Your ip address is: 192.168.0.10"]}

So I confirm it works with 1.2.0 too.

Could you try specifying the complete path to the ipv4.abnf file? Perhaps it's taking an outdated ipv4 file as input?