andrewcooke / ParserCombinator.jl

A parser combinator library for Julia
Other
107 stars 20 forks source link

funccall always parsed instead of funcdef because its shorter #28

Open travisstaloch opened 6 years ago

travisstaloch commented 6 years ago

Hello and thank you for this great library. I'm trying to parse a language with fat arrow funcdefs as in:

a() => 1

However, they are never begin used because funccall is a shorter version of this:

a()

I've verified they both work as removing funccall allows funcdef to work again. Is there any way to set precedence or otherwise allow funcdef to be used? Thanks for any advice or feedback.

Here are the relevent parser definitions:

arglist = (name | (name + E","))[0:end]
funccall = name + E"(" + arglist + E")" |> FuncCall

paramlist = ((name | assign) | ((name | assign) + E","))[0:end]
funcbody = stmt | (whitespacereq + stmt)[1:end]
funcdef = name + E"(" + paramlist + E")" + E"=>" + E"\n"[0:end] + funcbody |> FuncDef