GroteTrap-0.1: GroteTrap

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

variable :: String -> a
 
number :: Int -> a
 
operators :: [Operator a]
 
functions :: [Function a]
 

Operators

data Operator a Source

Representation of an operator.

Constructors

Unary

An operator expecting one operand.

Fields

opSem1 :: a -> a
 
opFixity1 :: Fixity1
 
opPrio :: Int
 
opToken :: String
 
Binary

An operator expecting two operands.

Fields

opSem2 :: a -> a -> a
 
opFixity2 :: Fixity2
 
opPrio :: Int
 
opToken :: String
 
Nary

An infix associative operator that chains together an arbitrary number of operands.

Fields

opSemN :: [a] -> a
 
opSubranges :: Bool
 
opPrio :: Int
 
opToken :: String
 

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] -> m (Operator a)Source

Yields the specified operator in a monad. Fails when there are no operators with the name, or where there are several operators with the name.

Functions

data Function a Source

Representation of a function.

Constructors

Function 

Fields

fnSem :: [a] -> a
 
fnName :: String
 
fnArity :: Int
 

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

Yields the function with the specified name. If there are no functions with the name, or if there are several functions with the name, failure is returned.

function1 :: (a -> a) -> String -> Function aSource

Lifts a unary function to a Function.

function2 :: (a -> a -> a) -> String -> Function aSource

Lifts a binary function to a Function.