LicenseGNU LGPLv3
Maintainerpaul.bittner@uni-ulm.de
Safe HaskellSafe

AST

Description

Data types and operations for Abstract Syntax Trees (ASTs). ASTs are that Trees with a fixed Node type.

Synopsis

Documentation

data Node g a Source #

Node type of ASTs.

Constructors

Node 

Fields

  • value :: a

    The value that is encapsulated by a node. Most of the time this is a String referring to source code statements.

  • grammartype :: g

    The grammar rule this node was parsed from. g should be an instance of Grammar.

  • uuid :: UUID

    A unique identifier to trace nodes across several versions of ASTs.

Instances

Instances details
Functor (Node g) Source # 
Instance details

Defined in AST

Methods

fmap :: (a -> b) -> Node g a -> Node g b

(<$) :: a -> Node g b -> Node g a

Eq (Node g a) Source # 
Instance details

Defined in AST

Methods

(==) :: Node g a -> Node g a -> Bool

(/=) :: Node g a -> Node g a -> Bool

Eq a => Ord (Node g a) Source # 
Instance details

Defined in AST

Methods

compare :: Node g a -> Node g a -> Ordering

(<) :: Node g a -> Node g a -> Bool

(<=) :: Node g a -> Node g a -> Bool

(>) :: Node g a -> Node g a -> Bool

(>=) :: Node g a -> Node g a -> Bool

max :: Node g a -> Node g a -> Node g a

min :: Node g a -> Node g a -> Node g a

(Grammar g, Show a) => Show (Node g a) Source # 
Instance details

Defined in AST

Methods

showsPrec :: Int -> Node g a -> ShowS

show :: Node g a -> String

showList :: [Node g a] -> ShowS

type AST g a = Tree (Node g a) Source #

Type for abstract syntax trees (ASTs) representing source code. It is a tree in which each node represents a source code entity by a value, a grammar type and a UUID.

optionaltype :: Grammar g => Node g a -> NodeType Source #

Returns the node type of a nodes grammar type.

node :: Grammar g => a -> g -> State UUID (Node g a) Source #

Creates a new node from a value and a type by generating a new UUID for it.

uuidOf :: AST g a -> UUID Source #

Returns the UUID of an ASTs root.

findById :: UUID -> AST g a -> Maybe (AST g a) Source #

Finds a subtree in the given AST whose root has the given UUID. Returns Nothing iff no such subtree exists.

findByValue :: Eq a => a -> AST g a -> Maybe (AST g a) Source #

Finds a subtree in the given AST whose root has the given value. Returns Nothing iff no such subtree exists.

findByGrammarType :: Eq g => g -> AST g a -> Maybe (AST g a) Source #

Finds a subtree in the given AST whose root has the given grammar type. Returns Nothing iff no such subtree exists.

optionalAncestors :: (Eq a, Grammar g) => AST g a -> AST g a -> [AST g a] Source #

Returns all ancestors of a given subtree (second argument) in the given tree (first argument), that are optional (i.e., their optionaltype is Optional).