haskell-suite / haskell-src-exts

Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer
Other
193 stars 94 forks source link

Enable `KindSignatures` extension break parsing qualified multiply operators. #384

Open sighingnow opened 6 years ago

sighingnow commented 6 years ago

When extension KindSignatures enabled, qualified multiplication operator in expression (term level) get wrong result.

Version: haskell-src-exts-1.19.0

Related: #79 , #298 , #359

> let ParseOk ast = parseExpWithMode  (defaultParseMode {extensions=[EnableExtension KindSignatures]}) "a Prelude.* b"
> ast

InfixApp (App (Var (UnQual (Ident "a"))) (Con (UnQual (Ident "Prelude")))) (QVarOp (UnQual (Symbol ".*"))) (Var (UnQual (Ident  "b")))

> let ParseOk ast = parseExpWithMode  (defaultParseMode {extensions=[DisableExtension KindSignatures]}) "a Prelude.* b"
> ast

InfixApp (UnQual (Ident "a"))) (QVarOp (Qual (ModuleName "Prelude") (Symbol "*"))) (Var (UnQual (Ident "b")))
mpickering commented 6 years ago

This comment was wrong.

mpickering commented 6 years ago

At the type level you can't disambiguate between for multiple and for the kind before renaming so any solution will be an approximation.

mpickering commented 6 years ago

To be precise, how do you propose dealing with parsing Foo * Int?

sighingnow commented 6 years ago

In the example I post above, the * in Prelude.* should be parsed as a qualified operator, both in term level or in type level. But when KindSignatures is enabled, we got the unqualified result.

At type level, we cannot determine a single * is multiplication or kind, but this problem doesn't exist in term-level. The qualified Prelude.* should not be parsed two unqualified operators as (Con (UnQual (Ident "Prelude")))) (QVarOp (UnQual (Symbol ".*"))).

mpickering commented 6 years ago

That doesn’t answer the question at all.

The correct solution is to stop lexing * as a special character but in order to do so we must answer the question I posed in my previous comment.