Parsing Haskell, solutions
- Layout: the lexer state is part of the parser monad.
- Infix operators: parsing is done in stages:
- A parse tree is constructed as if all operators had the default
fixity. Parentheses in expressions are preserved.
- The module structure is analyzed. This tells us (amongst other
things) what is in scope on the top level of each module.
Infix applications are rewritten (reassociated) according to
the fixity of operators. The traversal of the syntax tree uses
an environment to keep track of what is in scope locally.
The class ReAssoc
as been introduced, make the reassociation
functions reusable. See modules
ReAssoc,
ReAssocBaseStruct,
ReAssocBase.