syntactic-2.0: Generic representation and manipulation of abstract syntax

Safe HaskellNone

Data.Syntactic.Interpretation

Contents

Description

Equality and rendering of ASTs

Synopsis

Equality

class Equality e whereSource

Higher-kinded equality

Methods

equal :: e a -> e b -> BoolSource

Higher-kinded equality

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

hash :: e a -> HashSource

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 whereSource

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

Methods

renderSym :: sym sig -> StringSource

Show a symbol as a String

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

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 -> StringSource

Implementation of renderArgs that handles infix operators

render :: forall sym a. Render sym => ASTF sym a -> StringSource

Render an AST as concrete syntax

class Render sym => StringTree sym whereSource

Convert a symbol to a Tree of strings

Methods

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

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

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

Convert an AST to a Tree of strings

showAST :: StringTree sym => ASTF sym a -> StringSource

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 -> BoolSource

Default implementation of equal

hashDefault :: Render sym => sym a -> HashSource

Default implementation of hash