Stability | experimental |
---|---|
Maintainer | gershomb@gmail.com |
Safe Haskell | None |
Language.Javascript.JMacro.Base
Contents
Description
Simple DSL for lightweight (untyped) programmatic generation of Javascript.
- data JStat
- = DeclStat Ident (Maybe JLocalType)
- | ReturnStat JExpr
- | IfStat JExpr JStat JStat
- | WhileStat JExpr JStat
- | ForInStat Bool Ident JExpr JStat
- | SwitchStat JExpr [(JExpr, JStat)] JStat
- | TryStat JStat Ident JStat JStat
- | BlockStat [JStat]
- | ApplStat JExpr [JExpr]
- | PPostStat Bool String JExpr
- | AssignStat JExpr JExpr
- | UnsatBlock (IdentSupply JStat)
- | AntiStat String
- | ForeignStat Ident JLocalType
- | BreakStat
- data JExpr
- data JVal
- newtype Ident = StrI String
- newtype IdentSupply a = IS {
- runIdentSupply :: State [Ident] a
- class JMacro a where
- data MultiComp
- class Compos t where
- compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (t -> m t) -> t -> m t
- composOp :: Compos t => (t -> t) -> t -> t
- composOpM :: (Compos t, Monad m) => (t -> m t) -> t -> m t
- composOpM_ :: (Compos t, Monad m) => (t -> m ()) -> t -> m ()
- composOpFold :: Compos t => b -> (b -> b -> b) -> (t -> b) -> t -> b
- withHygiene :: JMacro a => (a -> a) -> a -> a
- scopify :: JStat -> JStat
- renderJs :: (JsToDoc a, JMacro a) => a -> Doc
- renderPrefixJs :: (JsToDoc a, JMacro a) => String -> a -> Doc
- class JsToDoc a where
- class ToJExpr a where
- toJExpr :: a -> JExpr
- toJExprFromList :: [a] -> JExpr
- jsv :: String -> JExpr
- jLam :: ToSat a => a -> JExpr
- jVar :: ToSat a => a -> JStat
- jVarTy :: ToSat a => a -> Maybe JLocalType -> JStat
- jFor :: (ToJExpr a, ToStat b) => JStat -> a -> JStat -> b -> JStat
- jForIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat
- jForEachIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat
- jTryCatchFinally :: ToSat a => JStat -> a -> JStat -> JStat
- expr2stat :: JExpr -> JStat
- class ToStat a where
- nullStat :: JStat
- jhEmpty :: Map String JExpr
- jhSingle :: ToJExpr a => String -> a -> Map String JExpr
- jhAdd :: ToJExpr a => String -> a -> Map String JExpr -> Map String JExpr
- jhFromList :: [(String, JExpr)] -> JVal
- jsSaturate :: JMacro a => Maybe String -> a -> a
- jtFromList :: JType -> [(String, JType)] -> JType
ADT
Statements
Constructors
Expressions
Values
Identifiers
newtype IdentSupply a Source
Constructors
IS | |
Fields
|
Instances
Functor IdentSupply | |
Typeable1 IdentSupply | |
Eq a => Eq (IdentSupply a) | |
Data a => Data (IdentSupply a) | |
Ord a => Ord (IdentSupply a) | |
Show a => Show (IdentSupply a) |
Generic traversal (via compos)
Utility class to coerce the ADT into a regular structure.
Union type to allow regular traversal by compos.
Compos and ops for generic traversal as defined over the JMacro ADT.
composOpFold :: Compos t => b -> (b -> b -> b) -> (t -> b) -> t -> bSource
Hygienic transformation
withHygiene :: JMacro a => (a -> a) -> a -> aSource
Apply a transformation to a fully saturated syntax tree, taking care to return any free variables back to their free state following the transformation. As the transformation preserves free variables, it is hygienic. Cannot be used nested.
scopify :: JStat -> JStatSource
Takes a fully saturated expression and transforms it to use unique variables that respect scope.
Display/Output
renderJs :: (JsToDoc a, JMacro a) => a -> DocSource
Render a syntax tree as a pretty-printable document (simply showing the resultant doc produces a nice, well formatted String).
renderPrefixJs :: (JsToDoc a, JMacro a) => String -> a -> DocSource
Render a syntax tree as a pretty-printable document, using a given prefix to all generated names. Use this with distinct prefixes to ensure distinct generated names between independent calls to render(Prefix)Js.
Ad-hoc data marshalling
Things that can be marshalled into javascript values. Instantiate for any necessary data structures.
Instances
ToJExpr Bool | |
ToJExpr Char | |
ToJExpr Double | |
ToJExpr Int | |
ToJExpr Integer | |
ToJExpr () | |
ToJExpr JSValue | |
ToJExpr JVal | |
ToJExpr JExpr | |
ToJExpr a => ToJExpr [a] | |
(ToJExpr a, ToJExpr b) => ToJExpr (a, b) | |
ToJExpr a => ToJExpr (Map String a) | |
(ToJExpr a, ToJExpr b, ToJExpr c) => ToJExpr (a, b, c) | |
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d) => ToJExpr (a, b, c, d) | |
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e) => ToJExpr (a, b, c, d, e) | |
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e, ToJExpr f) => ToJExpr (a, b, c, d, e, f) |
Literals
Occasionally helpful combinators
jLam :: ToSat a => a -> JExprSource
Create a new anonymous function. The result is an expression.
Usage:
jLam $ x y -> {JExpr involving x and y}
jVar :: ToSat a => a -> JStatSource
Introduce a new variable into scope for the duration
of the enclosed expression. The result is a block statement.
Usage:
jVar $ x y -> {JExpr involving x and y}
jVarTy :: ToSat a => a -> Maybe JLocalType -> JStatSource
Introduce a new variable with optional type into scope for the duration
of the enclosed expression. The result is a block statement.
Usage:
jVar $ x y -> {JExpr involving x and y}
jForIn :: ToSat a => JExpr -> (JExpr -> a) -> JStatSource
Create a for in statement.
Usage:
jForIn {expression} $ x -> {block involving x}
jForEachIn :: ToSat a => JExpr -> (JExpr -> a) -> JStatSource
As with jForIn but creating a "for each in" statement.
jTryCatchFinally :: ToSat a => JStat -> a -> JStat -> JStatSource
Hash combinators
jhFromList :: [(String, JExpr)] -> JValSource
Utility
jsSaturate :: JMacro a => Maybe String -> a -> aSource
Given an optional prefix, fills in all free variable names with a supply of names generated by the prefix.