Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Display
Description
This module contains functions for visualizing derivations using LaTeX and TikZ.
These functions are generic over slice and transition contents and are thus somewhat limited.
For protovoice derivations,
an alternative to plotting a derivation would be to export an Analysis
to JSON
and view it interactively in the
protovoice annotation tool
(not implemented yet).
Plotting happens in two steps.
First, a the derivation is "replayed" using a (generic or grammar-specific) "player"
to construct a DerivationGraph
,
which contains all graphical objects and their positions explicitly.
The DerivationGraph
can then be plotted using different backends
(currently only TikZ, but a diagrams/SVG backed would be useful too).
Synopsis
- data DerivationGraph slc tr = DGraph {
- dgNextId :: !Int
- dgSlices :: !(Set (DerivSlice slc))
- dgTransitions :: !(Set (DerivTrans slc tr))
- dgHoriEdges :: !(Set (DerivSlice slc, DerivSlice slc))
- dgOpen :: ![DerivTrans slc tr]
- dgFrozen :: ![DerivTrans slc tr]
- dgRoot :: ![DerivTrans slc tr]
- data DerivSlice slc = DerivSlice {}
- type DerivTrans slc tr = (DerivSlice slc, tr, DerivSlice slc)
- replayDerivation :: (Foldable t, Ord slc, Ord tr) => DerivationPlayer s f h slc tr -> t (Leftmost s f h) -> Either String (DerivationGraph slc tr)
- replayDerivation' :: (Foldable t, Ord slc, Ord tr) => Path tr slc -> DerivationPlayer s f h slc tr -> t (Leftmost s f h) -> Either String (DerivationGraph slc tr)
- replayDerivationFull :: (Foldable t, Ord slc, Ord tr) => DerivationPlayer s f h slc tr -> t (Leftmost s f h) -> Either String (DerivationGraph slc tr)
- unfoldDerivation :: (Ord slc, Ord tr) => DerivationPlayer s f h slc tr -> [Leftmost s f h] -> [Either String (DerivationGraph slc tr)]
- unfoldDerivation' :: (Ord slc, Ord tr) => Path tr slc -> DerivationPlayer s f h slc tr -> [Leftmost s f h] -> [Either String (DerivationGraph slc tr)]
- data DerivationPlayer s f h slc tr = DerivationPlayer {}
- derivationPlayerUnit :: DerivationPlayer s f h () ()
- derivationPlayerEmpty :: DerivationPlayer s f h Empty Empty
- data Empty
- tikzDerivationGraph :: (Eq slc, Eq tr) => (slc -> Text) -> (tr -> Text) -> DerivationGraph slc tr -> Text
- tikzPic :: (Semigroup a, IsString a) => a -> a
- tikzStandalone :: (Semigroup a, IsString a) => Bool -> a -> a
- writeGraph :: (Show slc, Eq slc, Eq tr, Show tr) => FilePath -> DerivationGraph slc tr -> IO ()
- writeGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO ()
- viewGraph :: (Eq slc, Eq tr, Show slc, Show tr) => FilePath -> DerivationGraph slc tr -> IO ()
- viewGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO ()
Documentation
data DerivationGraph slc tr Source #
A derivation graph. Contains the graphical objects of a derivation plot as well as intermediate information that is used during a replay.
Constructors
DGraph | |
Fields
|
Instances
data DerivSlice slc Source #
A slice together with a depth and an ID
Constructors
DerivSlice | |
Instances
Show slc => Show (DerivSlice slc) Source # | |
Defined in Display Methods showsPrec :: Int -> DerivSlice slc -> ShowS # show :: DerivSlice slc -> String # showList :: [DerivSlice slc] -> ShowS # | |
Eq slc => Eq (DerivSlice slc) Source # | |
Defined in Display Methods (==) :: DerivSlice slc -> DerivSlice slc -> Bool # (/=) :: DerivSlice slc -> DerivSlice slc -> Bool # | |
Ord slc => Ord (DerivSlice slc) Source # | |
Defined in Display Methods compare :: DerivSlice slc -> DerivSlice slc -> Ordering # (<) :: DerivSlice slc -> DerivSlice slc -> Bool # (<=) :: DerivSlice slc -> DerivSlice slc -> Bool # (>) :: DerivSlice slc -> DerivSlice slc -> Bool # (>=) :: DerivSlice slc -> DerivSlice slc -> Bool # max :: DerivSlice slc -> DerivSlice slc -> DerivSlice slc # min :: DerivSlice slc -> DerivSlice slc -> DerivSlice slc # |
type DerivTrans slc tr = (DerivSlice slc, tr, DerivSlice slc) Source #
A transition between two DerivSlice
s.
Replaying Derivations
Arguments
:: (Foldable t, Ord slc, Ord tr) | |
=> DerivationPlayer s f h slc tr | the derivation player |
-> t (Leftmost s f h) | the derivation |
-> Either String (DerivationGraph slc tr) |
Replay a derivation from ⋊——⋉
.
Arguments
:: (Foldable t, Ord slc, Ord tr) | |
=> Path tr slc | the starting point of the derivation |
-> DerivationPlayer s f h slc tr | the derivation player |
-> t (Leftmost s f h) | the derivation |
-> Either String (DerivationGraph slc tr) |
Replay a derivation from n
top-level transitions.
Arguments
:: (Foldable t, Ord slc, Ord tr) | |
=> DerivationPlayer s f h slc tr | the derivation player |
-> t (Leftmost s f h) | the derivation |
-> Either String (DerivationGraph slc tr) |
Replay a derivation from ⋊——⋉
and ensure that the dervation is complete (freezing all transitions).
Return an error message if not.
Arguments
:: (Ord slc, Ord tr) | |
=> DerivationPlayer s f h slc tr | the derivation player |
-> [Leftmost s f h] | the derivation |
-> [Either String (DerivationGraph slc tr)] |
Replays a derivation from ⋊——⋉
and returns every intermediate derivation graph.
Arguments
:: (Ord slc, Ord tr) | |
=> Path tr slc | the starting point of the derivation |
-> DerivationPlayer s f h slc tr | the derivation player |
-> [Leftmost s f h] | the derivation |
-> [Either String (DerivationGraph slc tr)] |
Replays a derivation from n
top-level transitions
and returns every intermediate derivation graph.
Derivation Players
data DerivationPlayer s f h slc tr Source #
A derivation player. Contains functions for replaying derivations of a particular grammar, i.e. for deriving child elements from parent elements.
Constructors
DerivationPlayer | |
Fields
|
derivationPlayerUnit :: DerivationPlayer s f h () () Source #
A derivation player that uses ()
for slice and transition contents.
The actual derivation operations are ignored, so only the outer structure is produced.
derivationPlayerEmpty :: DerivationPlayer s f h Empty Empty Source #
A derivation player that uses Empty
for slice and transition content.
The actual derivation operations are ignored, so only the outer structure is produced.
A helper type that is like ()
but has a Show
instance that returns the empty string.
Plotting Derivation Graphs with TikZ
Arguments
:: (Eq slc, Eq tr) | |
=> (slc -> Text) | a function for displaying slice contents |
-> (tr -> Text) | a function for displaying transitions contents |
-> DerivationGraph slc tr | the derivation graph |
-> Text |
Convert a derivation graph into a series of TikZ commands.
tikzPic :: (Semigroup a, IsString a) => a -> a Source #
Wraps TikZ commands in a tikzpicture
environment.
Arguments
:: (Semigroup a, IsString a) | |
=> Bool | a flag for using the the |
-> a | the document content |
-> a |
Wraps latex code (e.g. a tikzpicture
) in a complete standalone document.
This environment includes default styles for slices, transitions, and hori edges.
writeGraph :: (Show slc, Eq slc, Eq tr, Show tr) => FilePath -> DerivationGraph slc tr -> IO () Source #
Write a single derivation graph to a tex
file.
writeGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO () Source #
Write a several derivation graphs to a tex
file.
viewGraph :: (Eq slc, Eq tr, Show slc, Show tr) => FilePath -> DerivationGraph slc tr -> IO () Source #
Write a single derivation graph to a tex
file and compile the file using pdflatex
.
viewGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO () Source #
Write a several derivation graphs to a tex
file and compile the file using pdflatex
.