GroteTrap-0.5.2: Parser and selection library for expression languages.

Safe HaskellSafe
LanguageHaskell98

Language.GroteTrap.Language

Contents

Description

The Language type that is the core of GroteTrap.

Synopsis

Language

data Language a Source #

Language connects the syntax of identifiers, numbers, operators and functions with their semantics. GroteTrap is able to derive a parser and evaluator from a Language, as well as convert between source text selections and tree selections.

Constructors

Language 

Fields

language :: Language a Source #

An empty language. Use this as the starting base of your languages, setting only those fields that are of importance.

Operators

data Operator a Source #

Representation of an operator.

Constructors

Unary

An operator expecting one operand.

Fields

Binary

A non-associative operator expecting two operands.

Fields

Assoc

An infix associative operator that chains together many operands.

Fields

data Fixity1 Source #

Fixity for unary operators.

Constructors

Prefix

The operator is written before its operand.

Postfix

The operator is written after its operand.

data Fixity2 Source #

Fixity for infix binary operators.

Constructors

InfixL

The operator associates to the left.

InfixR

The operator associates to the right.

findOperator :: Monad m => String -> (Operator a -> Bool) -> [Operator a] -> m (Operator a) Source #

findOperator name p os yields the operator from os that matches the predicate p and has token name. Fails if there are no or several matching operators.

Functions

data Function a Source #

Representation of a function.

Constructors

Function 

Fields

findFunction :: Monad m => String -> [Function a] -> m (Function a) Source #

Yelds the function with the specified name. Fails if there are no or several matching functions.

function1 :: (a -> a) -> String -> Function a Source #

Lifts a unary function to a Function.

function2 :: (a -> a -> a) -> String -> Function a Source #

Lifts a binary function to a Function.