haskell-src-exts-1.13.5: Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer

Portability | portable
Stability | stable
Maintainer | Niklas Broberg, d00nibro@chalmers.se
Safe Haskell | Safe-Infered

Language.Haskell.Exts.Fixity

Contents

- Fixity representation
  - Collections of fixities
- Applying fixities to an AST

Description

Fixity information to give the parser so that infix operators can be parsed properly.

Synopsis

- data Fixity = Fixity Assoc Int QName
- infix_ :: Int -> [String] -> [Fixity]
- infixl_ :: Int -> [String] -> [Fixity]
- infixr_ :: Int -> [String] -> [Fixity]
- preludeFixities :: [Fixity]
- baseFixities :: [Fixity]
- prefixMinusFixity :: (Assoc, Int)
- class AppFixity ast where
  - applyFixities :: Monad m => [Fixity] -> ast -> m ast

# Fixity representation

data Fixity

Operator fixities are represented by their associativity (left, right or none) and their precedence (0-9).

Constructors

Fixity Assoc Int QName |

Instances

Eq Fixity |
Data Fixity |
Ord Fixity |
Show Fixity |
Typeable Fixity |

The following three functions all create lists of fixities from textual representations of operators. The intended usage is e.g.

     fixs = infixr_ 0  ["$","$!","`seq`"]

Note that the operators are expected as you would write them infix, i.e. with ` characters surrounding varid operators, and varsym operators written as is.

infix_ :: Int -> [String] -> [Fixity]

infixl_ :: Int -> [String] -> [Fixity]

infixr_ :: Int -> [String] -> [Fixity]

## Collections of fixities

preludeFixities :: [Fixity]

All fixities defined in the Prelude.

baseFixities :: [Fixity]

All fixities defined in the base package.

Note that the `+++` operator appears in both Control.Arrows and Text.ParserCombinators.ReadP. The listed precedence for `+++` in this list is that of Control.Arrows.

prefixMinusFixity :: (Assoc, Int)

Built-in fixity for prefix minus

# Applying fixities to an AST

class AppFixity ast where

All AST elements that may include expressions which in turn may need fixity tweaking will be instances of this class.

Methods

applyFixities

Arguments

:: Monad m |
=> [Fixity] | The fixities to account for.
-> ast | The element to tweak.
-> m ast | The same element, but with operator expressions updated, or a failure.

Tweak any expressions in the element to account for the fixities given. Assumes that all operator expressions are fully left associative chains to begin with.

Instances

AppFixity GuardedAlt |
AppFixity GuardedAlts |
AppFixity Alt |
AppFixity FieldUpdate |
AppFixity QualStmt |
AppFixity Stmt |
AppFixity PatField |
AppFixity RPat |
AppFixity PXAttr |
AppFixity Pat |
AppFixity Splice |
AppFixity Bracket |
AppFixity XAttr |
AppFixity Exp |
AppFixity GuardedRhs |
AppFixity Rhs |
AppFixity InstDecl |
AppFixity ClassDecl |
AppFixity Match |
AppFixity IPBind |
AppFixity Binds |
AppFixity Annotation |
AppFixity Decl |
AppFixity Module |