Pattern/expression ambiguity resolution
This patch removes 'EWildPat', 'EAsPat', 'EViewPat', and 'ELazyPat' from 'HsExpr' by using the ambiguity resolution system introduced earlier for the command/expression ambiguity. Problem: there are places in the grammar where we do not know whether we are parsing an expression or a pattern, for example: do { Con a b <- x } -- 'Con a b' is a pattern do { Con a b } -- 'Con a b' is an expression Until we encounter binding syntax (<-) we don't know whether to parse 'Con a b' as an expression or a pattern. The old solution was to parse as HsExpr always, and rejig later: checkPattern :: LHsExpr GhcPs -> P (LPat GhcPs) This meant polluting 'HsExpr' with pattern-related constructors. In other words, limitations of the parser were affecting the AST, and all other code (the renamer, the typechecker) had to deal with these extra constructors. We fix this abstraction leak by parsing into an overloaded representation: class DisambECP b where ... newtype ECP = ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } See Note [Ambiguous syntactic categories] for details. Now the intricacies of parsing have no effect on the hsSyn AST when it comes to the expression/pattern ambiguity.
parent
0040af59
Branches wip/T16689
No related tags found
Pipeline #5324 passed with warnings
Stage: lint
Stage: build
Stage: full-build
Stage: cleanup
Stage: packaging
Stage: hackage
Showing
- compiler/deSugar/DsExpr.hs 0 additions, 4 deletionscompiler/deSugar/DsExpr.hs
- compiler/hieFile/HieAst.hs 0 additions, 12 deletionscompiler/hieFile/HieAst.hs
- compiler/hsSyn/HsExpr.hs 19 additions, 65 deletionscompiler/hsSyn/HsExpr.hs
- compiler/hsSyn/HsExtension.hs 0 additions, 8 deletionscompiler/hsSyn/HsExtension.hs
- compiler/parser/Lexer.x 13 additions, 15 deletionscompiler/parser/Lexer.x
- compiler/parser/Parser.y 285 additions, 269 deletionscompiler/parser/Parser.y
- compiler/parser/RdrHsSyn.hs 546 additions, 194 deletionscompiler/parser/RdrHsSyn.hs
- compiler/rename/RnExpr.hs 3 additions, 27 deletionscompiler/rename/RnExpr.hs
- compiler/typecheck/TcRnTypes.hs 0 additions, 4 deletionscompiler/typecheck/TcRnTypes.hs
- testsuite/tests/parser/should_fail/InfixAppPatErr.stderr 2 additions, 2 deletionstestsuite/tests/parser/should_fail/InfixAppPatErr.stderr
- testsuite/tests/parser/should_fail/T984.stderr 2 additions, 2 deletionstestsuite/tests/parser/should_fail/T984.stderr
- testsuite/tests/parser/should_fail/all.T 18 additions, 0 deletionstestsuite/tests/parser/should_fail/all.T
- testsuite/tests/parser/should_fail/cmdFail001.hs 4 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail001.hs
- testsuite/tests/parser/should_fail/cmdFail001.stderr 2 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail001.stderr
- testsuite/tests/parser/should_fail/cmdFail002.hs 4 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail002.hs
- testsuite/tests/parser/should_fail/cmdFail002.stderr 2 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail002.stderr
- testsuite/tests/parser/should_fail/cmdFail003.hs 8 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail003.hs
- testsuite/tests/parser/should_fail/cmdFail003.stderr 3 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail003.stderr
- testsuite/tests/parser/should_fail/cmdFail004.hs 4 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail004.hs
- testsuite/tests/parser/should_fail/cmdFail004.stderr 2 additions, 0 deletionstestsuite/tests/parser/should_fail/cmdFail004.stderr
Loading
Please register or sign in to comment