mulang icon indicating copy to clipboard operation
mulang copied to clipboard

Faulty operator precedence parsing in haskell

Open julian-berbel opened this issue 3 years ago • 1 comments

The following piece of code:

foo = (even $ 5) || False

(valid)

Gets parsed to the same ast as:

foo = even $ 5 || False

(type error)

julian-berbel avatar Dec 15 '21 18:12 julian-berbel

This doesn't seem like an easy fix; the haskell parser is parsing the previous two pieces of code to this:

HsInfixApp 
  (HsParen (HsInfixApp (HsVar (UnQual (HsIdent "even"))) (HsQVarOp (UnQual (HsSymbol "$"))) (HsLit (HsInt 5))))
  (HsQVarOp (UnQual (HsSymbol "||")))
  (HsCon (UnQual (HsIdent "False")))

HsInfixApp 
  (HsInfixApp (HsVar (UnQual (HsIdent "even"))) (HsQVarOp (UnQual (HsSymbol "$"))) (HsLit (HsInt 5)))
  (HsQVarOp (UnQual (HsSymbol "||")))
  (HsCon (UnQual (HsIdent "False")))

The resulting tree hierarchy does not to reflect the operator precedence, it seems that is accounted for at a later stage.

julian-berbel avatar Dec 15 '21 19:12 julian-berbel