Hets - the Heterogeneous Tool Set

CopyrightChristian Maeder and Uni Bremen 2003-2005
LicenseGPLv2 or higher, see LICENSE.txt
MaintainerChristian.Maeder@dfki.de
Stabilityexperimental
Portabilityportable
Safe HaskellNone

Common.Earley

Contents

Description

Generic mixfix analysis, using an Earley parser

The grammer has a single non-terminal for terms (the double underscore). A rule of the grammer carries an identifier, a precedence number, and the actual token list of the identifier to match against the input token list..

The parser can be instantiated for any term type. A function parameter determines how applications from identifiers and arguments are constructed.

Synopsis

Documentation

type Rule = (Id, Int, [Token])

data Rules

postfix and prefix rules

Constructors

Rules 

partitionRules :: [Rule] -> Rules

presort rules

special tokens for special ids

varTok :: Token

token for a fixed (or recursively resolved) argument expression

exprTok :: Token

token for a fixed (or recursively resolved) operator expression

parenId :: Id

parenthesis around one place

tupleId :: Id

id for tuples with at least two arguments

unitId :: Id

id for the emtpy tuple

protect :: Id -> Id

interpret placeholders as literal places

listRules :: Int -> GlobalAnnos -> [Rule]

construct the list rules

mixRule :: Int -> Id -> Rule

construct a rule for a mixfix

getTokenPlaceList :: Id -> [Token]

extract tokens with the non-terminal for places

getPlainPolyTokenList :: Id -> [Token]

get the plain token list for prefix applications

getPolyTokenList :: Id -> [Token]

get the token list for a mixfix rule

resolution chart

data Chart a

the whole state for mixfix resolution

mixDiags :: [Diagnosis] -> Chart a -> Chart a

add intermediate diagnostic messages

type ToExpr a = Id -> [a] -> Range -> a

shortcut for a function that constructs an expression

rules :: Chart a -> Rules

initChart :: TokRules -> Rules -> Chart a

create the initial chart

nextChart :: (a -> a -> a) -> ToExpr a -> GlobalAnnos -> Chart a -> (a, Token) -> Chart a

make one scan, complete, and predict step. The first function adds a type to the result. The second function filters based on argument and operator info. If filtering yields Nothing further filtering by precedence is applied.

getResolved :: (a -> ShowS) -> Range -> ToExpr a -> Chart a -> Result a

extract resolved result