ddc-source-tetra-0.4.2.1: Disciplined Disciple Compiler source language.

Safe HaskellNone
LanguageHaskell98

DDC.Source.Tetra.Transform.Defix

Description

Convert infix expressions to prefix form.

The parser packs up sequences of expressions and operators into an XDefix node, but does not convert them to standard prefix applications. That is the job of this module.

The parsed code will contain XDefix, XInfixOp and XInfixVar nodes, which are pretty-printed like this:

 [DEFIX| Cons start [DEFIX| enumFromTo [DEFIX| start (INFIXOP "+") 1 ] end ]

After applying the transform in this module, all function applications will be in prefix form:

 Cons start (enumFromTo ((+) start 1) end)

Synopsis

Documentation

data FixTable l Source

Table of infix operator definitions.

Constructors

FixTable [FixDef l] 

data FixDef l Source

Infix operator definition.

data InfixAssoc Source

Infix associativity.

Constructors

InfixLeft

Left associative.

InfixRight

Right associative.

InfixNone

Non associative.

defaultFixTable :: (GBound l ~ Bound Name) => FixTable l Source

Default fixity table for infix operators.

data Error l Source

Things that can go wrong when defixing code.

Constructors

ErrorNoInfixDef

Infix operator symbol has no infix definition.

ErrorDefixNonAssoc

Two non-associative operators with the same precedence.

ErrorDefixMixedAssoc

Two operators of different associativies with same precedence.

Fields

errorAnnot :: GAnnot l
 
errorOps :: [String]
 
ErrorMalformed

Infix expression is malformed. Eg "+ 3" or "2 + + 2"

Fields

errorAnnot :: GAnnot l
 
errorExp :: GExp l
 

class Defix c l where Source

Methods

defix :: FixTable l -> c l -> Either (Error l) (c l) Source

Resolve infix expressions in a thing.