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

Safe HaskellSafe-Inferred
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

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

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

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

A non-associative operator expecting two operands.

Fields

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

An infix associative operator that chains together many operands.

Fields

opSemN :: [a] -> a
 
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 -> 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

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

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.