... | ... | @@ -8,7 +8,7 @@ The parser is written using |
|
|
|
|
|
- [Alex](http://www.haskell.org/alex/), for lexical analysis. Source file [compiler/GHC/Parser/Lexer.x](https://gitlab.haskell.org/ghc/ghc/tree/master/compiler/GHC/Parser/Lexer.x)
|
|
|
- [Happy](http://www.haskell.org/happy/), for the parser itself. Source file [compiler/GHC/Parser.y](https://gitlab.haskell.org/ghc/ghc/tree/master/compiler/GHC/Parser.y).
|
|
|
- `RdrHsSyn`, for Haskell support functions. Source file [compiler/GHC/Parser/PostProcess.hs](https://gitlab.haskell.org/ghc/ghc/tree/master/compiler/GHC/Parser/PostProcess.hs)
|
|
|
- `GHC.Parser.PostProcess` (formerly known as `RdrHsSyn`), for Haskell support functions. Source file [compiler/GHC/Parser/PostProcess.hs](https://gitlab.haskell.org/ghc/ghc/tree/master/compiler/GHC/Parser/PostProcess.hs)
|
|
|
- Read [Shayne Fletcher's great blog post](https://blog.shaynefletcher.org/2020/04/syntactic-ambiguity-resolution-in-ghc.html) about how GHC deals with ambiguous situations, and the `DisambECP` class.
|
|
|
|
|
|
## Principles
|
... | ... | @@ -21,9 +21,9 @@ Making a parser parse *precisely* the right language is hard. So GHC's parser f |
|
|
|
|
|
Here are some examples:
|
|
|
|
|
|
- Patterns are parsed as expressions, and transformed from `HsExpr.HsExp` into `HsPat.HsPat` in `RdrHsSyn.checkPattern`. An expression like `[x | x<-xs]` that doesn't look like a pattern is rejected by `checkPattern`.
|
|
|
- Patterns are parsed as expressions, and transformed from `GHC.Hs.Expr.HsExp` into `GHC.Hs.Pat.HsPat` in `GHC.Parser.PostProcess.checkPattern`. An expression like `[x | x<-xs]` that doesn't look like a pattern is rejected by `checkPattern`. (ToDo: Update to the latest information)
|
|
|
|
|
|
- The context of a type is parsed as a type, and then converted into a context by `RdrHsSyn.checkContext`. For example, when parsing
|
|
|
- The context of a type is parsed as a type, and then converted into a context by `GHC.Parser.PostProcess.checkContext`. For example, when parsing
|
|
|
|
|
|
```haskell
|
|
|
f :: (Read a, Num a) => a -> a
|
... | ... | |