gkappler / CombinedParsers.jl

Compiled parser combinators and regular expressions in pure julia
MIT License
77 stars 10 forks source link

Recursion in EBNF #39

Open hiiroo opened 1 year ago

hiiroo commented 1 year ago

Hi, thanks for great library. However, I was trying EBNF grammar (I could not achieve recursion using the existing API).

p = ebnf"""
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
       | "H" | "I" | "J" | "K" | "L" | "M" | "N"
       | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
       | "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
       | "c" | "d" | "e" | "f" | "g" | "h" | "i"
       | "j" | "k" | "l" | "m" | "n" | "o" | "p"
       | "q" | "r" | "s" | "t" | "u" | "v" | "w"
       | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
word = letter, {letter};
term = "(", word, " ", (word | term), ")";
"""

where I was attempting to parse the following;

match(p, "(NP (NNP Test))")

However, grammar does not compile and give StackOverflowError. Is this supposedly happen or am I missing something. Because, following EBNF grammar is working at https://mdkrajnak.github.io/ebnftest/;

Term = "(", Word, " ", (Word | Term), ")";
Word ::= Letter, {Letter}
Letter  ::= #'[A-Za-z]'
Number ::= Digits ( ( '.' | ',' ) Digits? )?
Digits ::= #'[0-9]+'

Any help or redirection would be helpful. Thanks in advance.

melonedo commented 1 year ago

Seems like the parser for EBNF grammar itself is broken😥.