ormolu-0.1.2.0: A formatter for Haskell source code

Safe Haskell | None
Language | Haskell2010

Ormolu.Printer.Operators

Description

This module helps handle operator chains composed of different operators that may have different precedence and fixities.

Synopsis

- data OpTree ty op
  - = OpNode ty
  - | OpBranch (OpTree ty op) op (OpTree ty op)
- opTreeLoc :: OpTree (Located a) b -> SrcSpan
- reassociateOpTree :: (op -> Maybe RdrName) -> OpTree (Located ty) (Located op) -> OpTree (Located ty) (Located op)

# Documentation

data OpTree ty op Source #

Intermediate representation of operator trees. It has two type parameters: `ty` is the type of sub-expressions, while `op` is the type of operators.

Constructors

OpNode ty |
OpBranch (OpTree ty op) op (OpTree ty op) |

opTreeLoc :: OpTree (Located a) b -> SrcSpan Source #

Return combined `SrcSpan`s of all elements in this `OpTree`.

reassociateOpTree Source #

Arguments

:: (op -> Maybe RdrName) | How to get name of an operator
-> OpTree (Located ty) (Located op) | Original `OpTree`
-> OpTree (Located ty) (Located op) | Re-associated `OpTree`

Re-associate an `OpTree` taking into account automagically inferred relative precedence of operators. Users are expected to first construct an initial `OpTree`, then re-associate it using this function before printing.