syntactic-2.1: Generic representation and manipulation of abstract syntax

Safe HaskellNone
LanguageHaskell2010

Data.Syntactic.Interpretation

Contents

Description

Equality and rendering of ASTs

Synopsis

Equality

class Equality e where Source

Higher-kinded equality

Methods

equal :: e a -> e b -> Bool Source

Higher-kinded equality

Comparing elements of different types is often needed when dealing with expressions with existentially quantified sub-terms.

hash :: e a -> Hash Source

Higher-kinded hashing. Elements that are equal according to equal must result in the same hash:

equal a b  ==>  hash a == hash b

Instances

Equality Empty 
Equality BindingT

equal does strict identifier comparison; i.e. no alpha equivalence.

hash assigns the same hash to all variables and binders. This is a valid over-approximation that enables the following property:

alphaEq a b ==> hash a == hash b
Equality Binding

equal does strict identifier comparison; i.e. no alpha equivalence.

hash assigns the same hash to all variables and binders. This is a valid over-approximation that enables the following property:

alphaEq a b ==> hash a == hash b
Equality Construct 
Equality sym => Equality (AST sym) 
Equality (MONAD m) 
(Equality sym1, Equality sym2) => Equality ((:+:) sym1 sym2) 
Equality expr => Equality ((:&:) expr info) 

Rendering

class Render sym where Source

Render a symbol as concrete syntax. A complete instance must define at least the renderSym method.

Minimal complete definition

renderSym

Methods

renderSym :: sym sig -> String Source

Show a symbol as a String

renderArgs :: [String] -> sym sig -> String Source

Render a symbol given a list of rendered arguments

Instances

Render Empty 
Render BindingT 
Render Binding 
Render Construct 
Render (MONAD m) 
(Render sym1, Render sym2) => Render ((:+:) sym1 sym2) 
Render expr => Render ((:&:) expr info) 

renderArgsSmart :: Render sym => [String] -> sym a -> String Source

Implementation of renderArgs that handles infix operators

render :: forall sym a. Render sym => ASTF sym a -> String Source

Render an AST as concrete syntax

class Render sym => StringTree sym where Source

Convert a symbol to a Tree of strings

Minimal complete definition

Nothing

Methods

stringTreeSym :: [Tree String] -> sym a -> Tree String Source

Convert a symbol to a Tree given a list of argument trees

stringTree :: forall sym a. StringTree sym => ASTF sym a -> Tree String Source

Convert an AST to a Tree of strings

showAST :: StringTree sym => ASTF sym a -> String Source

Show a syntax tree using ASCII art

drawAST :: StringTree sym => ASTF sym a -> IO () Source

Print a syntax tree using ASCII art

writeHtmlAST :: StringTree sym => FilePath -> ASTF sym a -> IO () Source

Write a syntax tree to an HTML file with foldable nodes

Default interpretation

equalDefault :: Render sym => sym a -> sym b -> Bool Source

Default implementation of equal

hashDefault :: Render sym => sym a -> Hash Source

Default implementation of hash