Maintainer | diagrams-discuss@googlegroups.com |
---|---|
Safe Haskell | None |
Tools for dynamically building diagrams, for e.g. creating preprocessors to interpret diagrams code embedded in documents.
- buildDiagram :: (Typeable b, Typeable v, InnerSpace v, OrderedField (Scalar v), Backend b v, Show (Options b v)) => b -> v -> Options b v -> [String] -> String -> [String] -> [String] -> (String -> IO (x, Maybe (Options b v -> Options b v))) -> IO (BuildResult b v x)
- data BuildResult b v x
- ppInterpError :: InterpreterError -> String
- alwaysRegenerate :: String -> IO ((), Maybe (a -> a))
- hashedRegenerate :: (String -> a -> a) -> FilePath -> String -> IO (String, Maybe (a -> a))
- setDiagramImports :: MonadInterpreter m => String -> [String] -> m ()
- interpretDiagram :: forall b v. (Typeable b, Typeable v, InnerSpace v, OrderedField (Scalar v), Backend b v) => b -> v -> Options b v -> FilePath -> [String] -> String -> IO (Either InterpreterError (Result b v))
- data Build = Build {}
- defaultBuildOpts :: Build
Building diagrams
:: (Typeable b, Typeable v, InnerSpace v, OrderedField (Scalar v), Backend b v, Show (Options b v)) | |
=> b | Backend token |
-> v | Dummy vector to fix the vector type |
-> Options b v | Backend-specific options to use |
-> [String] | Source code snippets. Each should be a syntactically valid Haskell module. They will be combined intelligently, i.e. not just pasted together textually but combining pragmas, imports, etc. separately. |
-> String | Diagram expression to interpret |
-> [String] | Extra |
-> [String] | Additional imports (Diagrams.Prelude is imported by default). |
-> (String -> IO (x, Maybe (Options b v -> Options b v))) | A function to decide whether a particular diagram needs to
be regenerated. It will be passed the final assembled
source for the diagram (but with the module name set to
Two standard decision functions are provided for
convenience: |
-> IO (BuildResult b v x) |
Build a diagram by writing the given source code to a temporary module and interpreting the given expression. Can return either a parse error if the source does not parse, an interpreter error, or the final result.
data BuildResult b v x Source
Potential results of a dynamic diagram building operation.
ParseErr String | Parsing of the code failed. |
InterpErr InterpreterError | Interpreting the code
failed. See |
Skipped x | This diagram did not need to be regenerated. |
OK x (Result b v) | A successful build, yielding a backend-specific result and some extra information. |
ppInterpError :: InterpreterError -> StringSource
Pretty-print an InterpreterError
.
Regeneration decision functions
alwaysRegenerate :: String -> IO ((), Maybe (a -> a))Source
Convenience function suitable to be given as the final argument
to buildDiagram
. It implements the simple policy of always
rebuilding every diagram.
:: (String -> a -> a) | A function for computing an update to rendering options, given a new base filename computed from a hash of the diagram source. |
-> FilePath | The directory in which to look for generated files |
-> String | The "source" to hash. Note that this does not actually have to be valid source code. A common trick is to concatenate the actual source code with String representations of any other information on which the diagram depends. |
-> IO (String, Maybe (a -> a)) |
Convenience function suitable to be given as the final argument
to buildDiagram
. It works by hashing the given diagram source,
and looking in the specified directory for any file whose base
name is equal to the hash. If there is such a file, it specifies
that the diagram should not be rebuilt. Otherwise, it specifies
that the diagram should be rebuilt, and uses the provided
function to update the rendering options based on the generated
hash. (Most likely, one would want to set the requested output
file to the hash followed by some extension.) It also returns
the generated hash.
Interpreting diagrams
These functions constitute the internals of diagrams-builder. End
users should not usually need to call them directly; use
buildDiagram
instead.
:: MonadInterpreter m | |
=> String | Filename of the module containing the diagrams |
-> [String] | Additional necessary imports. |
-> m () |
Set up the module to be interpreted, in the context of the necessary imports.
:: forall b v . (Typeable b, Typeable v, InnerSpace v, OrderedField (Scalar v), Backend b v) | |
=> b | Backend token |
-> v | Dummy vector to identify the vector space |
-> Options b v | Rendering options |
-> FilePath | Filename of the module containing the example |
-> [String] | Additional imports needed |
-> String | Expression of type |
-> IO (Either InterpreterError (Result b v)) |
Interpret a diagram expression based on the contents of a given source file, using some backend to produce a result.
Tools for creating standalone builder executables
Record of command-line options.
defaultBuildOpts :: BuildSource
Default command-line options record.