Parsing Elm case expression clashes with function call

96 Views Asked by At

I am developing an Intellij plugin for the Elm language using JFlex and Grammar Kit. I have minimal experience writing parsers.

I can't parse case expressions because they clash with function calls.

The BNF spec is as follows:

expr ::=
  NUM
  | IDENTIFIER
  | FunctionCallExpr
  | CaseExpr


CaseExpr ::= CASE IDENTIFIER OF case_body
case_body ::= (case_body_part)* OTHERWISE "->" expr
case_body_part ::= NUM "->" expr

FunctionCallExpr ::= IDENTIFIER NUM

In the following example the parser does not recognise that 84 is the start of a new case_body_part

 case n of
    42 -> foo 420
    84 -> bar 840   -- this line is treated as an error rather than case_body_part
    otherwise -> zap 100

If anyone knows Grammar Kit I would be grateful for a steer. However, on the assumption that viewers are more likely to know parsers in general:
1) Can I fix this with better BNF.
2) What kind of parsing concepts are involved.
3) Can you point me to how another parser such as yacc handles this.

0

There are 0 best solutions below