language-qux-0.2.0.0: Utilities for working with the Qux language

Copyright(c) Henry J. Wylde, 2015
LicenseBSD3
Maintainerpublic@hjwylde.com
Safe HaskellSafe
LanguageHaskell2010

Language.Qux.Annotated.Syntax

Contents

Description

Abstract syntax tree nodes with annotations. The annotation style was inspired by haskell-src-exts.

Instances of Simplifiable are provided for simplifying a node down to it's unannotated form and of Pretty for pretty printing.

Synopsis

Type classes

class Annotated n where Source

An annotated class. Annotations are used for attaching data to a node, such as a SourcePos.

Methods

ann :: n a -> a Source

class Simplifiable n r | n -> r where Source

A simplifiable class. Simplifiable is used to simplify a node to a a simpler form. See Language.Qux.Syntax for simpler forms of the nodes defined here.

Methods

simp :: n -> r Source

Annotated nodes

data Id a Source

An identifier. Identifiers should match '[a-z_][a-zA-Z0-9_']*'.

Constructors

Id a String 

data Program a Source

A program is a module identifier (list of Id's) and a list of declarations.

Constructors

Program a [Id a] [Decl a] 

data Decl a Source

A declaration.

Constructors

FunctionDecl a (Id a) [(Type a, Id a)] [Stmt a]

A name, list of (Type, Id) parameters and statements. The return type is treated as a parameter with id '@'.

data Stmt a Source

A statement.

Constructors

IfStmt a (Expr a) [Stmt a] [Stmt a]

A condition, true block and false block of statements.

ReturnStmt a (Expr a)

An expression.

WhileStmt a (Expr a) [Stmt a]

A condition and block of statements.

data Expr a Source

A complex expression.

Constructors

ApplicationExpr a (Id a) [Expr a]

A function name to call and the arguments to pass as parameters.

BinaryExpr a BinaryOp (Expr a) (Expr a)

A binary operation.

ListExpr a [Expr a]

A list expression.

TypedExpr a Type (Expr a)

A typed expression. See Language.Qux.Annotated.TypeResolver.

UnaryExpr a UnaryOp (Expr a)

A unary operation.

ValueExpr a Value

A raw value.

data Type a Source

A type.

Constructors

BoolType a 
IntType a 
ListType a (Type a)

A list type with an inner type.

NilType a 

Regular nodes

data BinaryOp Source

A binary operator.

Constructors

Acc

List access.

Mul

Multiplicaiton.

Div

Division.

Mod

Modulus.

Add

Addition.

Sub

Subtraction.

Lt

Less than.

Lte

Less than or equal to.

Gt

Greater than.

Gte

Greater than or equal to.

Eq

Equal to.

Neq

Not equal to.

data UnaryOp Source

A unary operator.

Constructors

Len

List length.

Neg

Negation.

data Value Source

A value is considered to be in it's normal form.

Constructors

BoolValue Bool

A boolean.

IntValue Integer

An unbounded integer.

ListValue [Value]

A normalised list value.

NilValue

A unit value.