jmacro-0.6.18: QuasiQuotation library for programmatic generation of Javascript code.

Copyright | (c) Gershom Bazerman 2010
License | BSD 3 Clause
Maintainer | gershomb@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Language.Javascript.JMacro

Description

Simple DSL for lightweight (untyped) programmatic generation of Javascript.

A number of examples are available in the source of Language.Javascript.JMacro.Prelude.

Functions to generate generic RPC wrappers (using json serialization) are available in Language.Javascript.JMacro.Rpc.

usage:

    renderJs [jmacro|fun id x -> x|]

The above produces the id function at the top level.

    renderJs [jmacro|var id = \x -> x;|]

So does the above here. However, as id is brought into scope by the keyword var, you do not get a variable named id in the generated javascript, but a variable with an arbitrary unique identifier.

    renderJs [jmacro|var !id = \x -> x;|]

The above, by using the bang special form in a var declaration, produces a variable that really is named id.

    renderJs [jmacro|function id(x) {return x;}|]

The above is also id.

    renderJs [jmacro|function !id(x) {return x;}|]

As is the above (with the correct name).

    renderJs [jmacro|fun id x {return x;}|]

As is the above.

    renderJs [jmacroE|foo(x,y)|]

The above is an expression representing the application of foo to x and y.

    renderJs [jmacroE|foo x y|]]

As is the above.

    renderJs [jmacroE|foo (x,y)|]

While the above is an error. (i.e. standard javascript function application cannot seperate the leading parenthesis of the argument from the function being applied)

    \x -> [jmacroE|foo `(x)`|]

The above is a haskell expression that provides a function that takes an x, and yields an expression representing the application of foo to the value of x as transformed to a Javascript expression.

    [jmacroE|\x ->`(foo x)`|]

Meanwhile, the above lambda is in Javascript, and brings the variable into scope both in javascript and in the enclosed antiquotes. The expression is a Javascript function that takes an x, and yields an expression produced by the application of the Haskell function foo as applied to the identifier x (which is of type JExpr -- i.e. a Javascript expression).

Other than that, the language is essentially Javascript (1.5). Note however that one must use semicolons in a principled fashion -- i.e. to end statements consistently. Otherwise, the parser will mistake the whitespace for a whitespace application, and odd things will occur. A further gotcha exists in regex literals, whicch cannot begin with a space. `x 5 4` parses as ((x 5) 4). However, `x 5 4` will parse as x(5 , 4). Such are the perils of operators used as delimeters in the presence of whitespace application.

Additional features in jmacro (documented on the wiki) include an infix application operator, and an enhanced destructuring bind.

Additional datatypes can be marshalled to Javascript by proper instance declarations for the ToJExpr class.

An experimental typechecker is available in the Language.Javascript.JMacro.Typed module.

Synopsis

- jmacro :: QuasiQuoter
- jmacroE :: QuasiQuoter
- parseJM :: String -> Either ParseError JStat
- parseJME :: String -> Either ParseError JExpr
- newtype IdentSupply a = IS {
  - runIdentSupply :: State [Ident] a
  }
- newtype Ident = StrI String
- class JMacro a where
  - jtoGADT :: a -> JMGadt a
  - jfromGADT :: JMGadt a -> a
- data JStat
  - = DeclStat Ident (Maybe JLocalType)
  - | ReturnStat JExpr
  - | IfStat JExpr JStat JStat
  - | WhileStat Bool 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
  - | LabelStat JsLabel JStat
  - | BreakStat (Maybe JsLabel)
  - | ContinueStat (Maybe JsLabel)
- data JExpr
  - = ValExpr JVal
  - | SelExpr JExpr Ident
  - | IdxExpr JExpr JExpr
  - | InfixExpr String JExpr JExpr
  - | PPostExpr Bool String JExpr
  - | IfExpr JExpr JExpr JExpr
  - | NewExpr JExpr
  - | ApplExpr JExpr [JExpr]
  - | UnsatExpr (IdentSupply JExpr)
  - | AntiExpr String
  - | TypeExpr Bool JExpr JLocalType
- data JVal
  - = JVar Ident
  - | JList [JExpr]
  - | JDouble SaneDouble
  - | JInt Integer
  - | JStr String
  - | JRegEx String
  - | JHash (Map String JExpr)
  - | JFunc [Ident] JStat
  - | UnsatVal (IdentSupply JVal)
- type JsLabel = String
- data JMGadt a where
  - JMGId :: Ident -> JMGadt Ident
  - JMGStat :: JStat -> JMGadt JStat
  - JMGExpr :: JExpr -> JMGadt JExpr
  - JMGVal :: JVal -> JMGadt JVal
- class Compos (t :: Type -> Type) where
  - compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (forall a. t a -> m (t a)) -> t c -> m (t c)
- composOp :: Compos t => (forall a. t a -> t a) -> t b -> t b
- composOpM :: (Compos t, Monad m) => (forall a. t a -> m (t a)) -> t b -> m (t b)
- composOpM_ :: (Compos t, Monad m) => (forall a. t a -> m ()) -> t b -> m ()
- composOpFold :: Compos t => b -> (b -> b -> b) -> (forall a. t a -> b) -> t c -> 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
  - jsToDoc :: a -> Doc
- 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
- class ToStat a where
  - toStat :: a -> JStat
- 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
- newtype SaneDouble = SaneDouble Double
- module Language.Javascript.JMacro.Prelude
- data JType
  - = JTNum
  - | JTString
  - | JTBool
  - | JTStat
  - | JTFunc [JType] JType
  - | JTList JType
  - | JTMap JType
  - | JTRecord JType (Map String JType)
  - | JTRigid VarRef (Set Constraint)
  - | JTImpossible
  - | JTFree VarRef
  - | JTForall [VarRef] JType

# Documentation

jmacro :: QuasiQuoter Source #

QuasiQuoter for a block of JMacro statements.

jmacroE :: QuasiQuoter Source #

QuasiQuoter for a JMacro expression.

parseJM :: String -> Either ParseError JStat Source #

parseJME :: String -> Either ParseError JExpr Source #

newtype IdentSupply a Source #

Constructors

IS |

Fields

- runIdentSupply :: State [Ident] a

#### Instances

Instances details

Functor IdentSupply Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods fmap :: (a -> b) -> IdentSupply a -> IdentSupply b Source # (<$) :: a -> IdentSupply b -> IdentSupply a Source #
Data a => Data (IdentSupply a) Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IdentSupply a -> c (IdentSupply a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (IdentSupply a) Source #

toConstr :: IdentSupply a -> Constr Source #

dataTypeOf :: IdentSupply a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (IdentSupply a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IdentSupply a)) Source #

gmapT :: (forall b. Data b => b -> b) -> IdentSupply a -> IdentSupply a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IdentSupply a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IdentSupply a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> IdentSupply a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IdentSupply a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IdentSupply a -> m (IdentSupply a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IdentSupply a -> m (IdentSupply a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IdentSupply a -> m (IdentSupply a) Source #

Show a => Show (IdentSupply a) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> IdentSupply a -> ShowS Source # show :: IdentSupply a -> String Source # showList :: [IdentSupply a] -> ShowS Source #
Eq a => Eq (IdentSupply a) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: IdentSupply a -> IdentSupply a -> Bool Source # (/=) :: IdentSupply a -> IdentSupply a -> Bool Source #
Ord a => Ord (IdentSupply a) Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

compare :: IdentSupply a -> IdentSupply a -> Ordering Source #

(<) :: IdentSupply a -> IdentSupply a -> Bool Source #

(<=) :: IdentSupply a -> IdentSupply a -> Bool Source #

(>) :: IdentSupply a -> IdentSupply a -> Bool Source #

(>=) :: IdentSupply a -> IdentSupply a -> Bool Source #

max :: IdentSupply a -> IdentSupply a -> IdentSupply a Source #

min :: IdentSupply a -> IdentSupply a -> IdentSupply a Source #

newtype Ident Source #

Identifiers

Constructors

StrI String |

#### Instances

Instances details

Data Ident Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ident -> c Ident Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Ident Source #

toConstr :: Ident -> Constr Source #

dataTypeOf :: Ident -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Ident) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ident) Source #

gmapT :: (forall b. Data b => b -> b) -> Ident -> Ident Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Ident -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Ident -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ident -> m Ident Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ident -> m Ident Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ident -> m Ident Source #

Show Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> Ident -> ShowS Source # show :: Ident -> String Source # showList :: [Ident] -> ShowS Source #
Eq Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: Ident -> Ident -> Bool Source # (/=) :: Ident -> Ident -> Bool Source #
Ord Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compare :: Ident -> Ident -> Ordering Source # (<) :: Ident -> Ident -> Bool Source # (<=) :: Ident -> Ident -> Bool Source # (>) :: Ident -> Ident -> Bool Source # (>=) :: Ident -> Ident -> Bool Source # max :: Ident -> Ident -> Ident Source # min :: Ident -> Ident -> Ident Source #
JMacro Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: Ident -> JMGadt Ident Source # jfromGADT :: JMGadt Ident -> Ident Source #
JsToDoc Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: Ident -> Doc Source #

class JMacro a where Source #

Compos and ops for generic traversal as defined over the JMacro ADT.

Utility class to coerce the ADT into a regular structure.

Methods

jtoGADT :: a -> JMGadt a Source #

jfromGADT :: JMGadt a -> a Source #

#### Instances

Instances details

JMacro Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: Ident -> JMGadt Ident Source # jfromGADT :: JMGadt Ident -> Ident Source #
JMacro JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JExpr -> JMGadt JExpr Source # jfromGADT :: JMGadt JExpr -> JExpr Source #
JMacro JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JStat -> JMGadt JStat Source # jfromGADT :: JMGadt JStat -> JStat Source #
JMacro JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JVal -> JMGadt JVal Source # jfromGADT :: JMGadt JVal -> JVal Source #

data JStat Source #

Statements

Constructors

DeclStat Ident (Maybe JLocalType) |
ReturnStat JExpr |
IfStat JExpr JStat JStat |
WhileStat Bool 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 |
LabelStat JsLabel JStat |
BreakStat (Maybe JsLabel) |
ContinueStat (Maybe JsLabel) |

#### Instances

Instances details

Monoid JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods mempty :: JStat Source # mappend :: JStat -> JStat -> JStat Source # mconcat :: [JStat] -> JStat Source #
Semigroup JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (<>) :: JStat -> JStat -> JStat Source # sconcat :: NonEmpty JStat -> JStat Source # stimes :: Integral b => b -> JStat -> JStat Source #
Data JStat Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> JStat -> c JStat Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c JStat Source #

toConstr :: JStat -> Constr Source #

dataTypeOf :: JStat -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c JStat) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JStat) Source #

gmapT :: (forall b. Data b => b -> b) -> JStat -> JStat Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> JStat -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> JStat -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> JStat -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> JStat -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> JStat -> m JStat Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> JStat -> m JStat Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> JStat -> m JStat Source #

Show JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> JStat -> ShowS Source # show :: JStat -> String Source # showList :: [JStat] -> ShowS Source #
Eq JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: JStat -> JStat -> Bool Source # (/=) :: JStat -> JStat -> Bool Source #
Ord JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compare :: JStat -> JStat -> Ordering Source # (<) :: JStat -> JStat -> Bool Source # (<=) :: JStat -> JStat -> Bool Source # (>) :: JStat -> JStat -> Bool Source # (>=) :: JStat -> JStat -> Bool Source # max :: JStat -> JStat -> JStat Source # min :: JStat -> JStat -> JStat Source #
JMacro JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JStat -> JMGadt JStat Source # jfromGADT :: JMGadt JStat -> JStat Source #
JsToDoc JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JStat -> Doc Source #
ToStat JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: JStat -> JStat Source #
JTypeCheck JStat Source # |
Instance details Defined in Language.Javascript.JMacro.TypeCheck Methods typecheck :: JStat -> TMonad JType Source #
JsToDoc [JStat] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: [JStat] -> Doc Source #
ToStat [JStat] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: [JStat] -> JStat Source #

data JExpr Source #

Expressions

Constructors

ValExpr JVal |
SelExpr JExpr Ident |
IdxExpr JExpr JExpr |
InfixExpr String JExpr JExpr |
PPostExpr Bool String JExpr |
IfExpr JExpr JExpr JExpr |
NewExpr JExpr |
ApplExpr JExpr [JExpr] |
UnsatExpr (IdentSupply JExpr) |
AntiExpr String |
TypeExpr Bool JExpr JLocalType |

#### Instances

Instances details

Data JExpr Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> JExpr -> c JExpr Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c JExpr Source #

toConstr :: JExpr -> Constr Source #

dataTypeOf :: JExpr -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c JExpr) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JExpr) Source #

gmapT :: (forall b. Data b => b -> b) -> JExpr -> JExpr Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> JExpr -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> JExpr -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> JExpr -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> JExpr -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> JExpr -> m JExpr Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> JExpr -> m JExpr Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> JExpr -> m JExpr Source #

Num JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (+) :: JExpr -> JExpr -> JExpr Source # (-) :: JExpr -> JExpr -> JExpr Source # (*) :: JExpr -> JExpr -> JExpr Source # negate :: JExpr -> JExpr Source # abs :: JExpr -> JExpr Source # signum :: JExpr -> JExpr Source # fromInteger :: Integer -> JExpr Source #
Show JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> JExpr -> ShowS Source # show :: JExpr -> String Source # showList :: [JExpr] -> ShowS Source #
Eq JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: JExpr -> JExpr -> Bool Source # (/=) :: JExpr -> JExpr -> Bool Source #
Ord JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compare :: JExpr -> JExpr -> Ordering Source # (<) :: JExpr -> JExpr -> Bool Source # (<=) :: JExpr -> JExpr -> Bool Source # (>) :: JExpr -> JExpr -> Bool Source # (>=) :: JExpr -> JExpr -> Bool Source # max :: JExpr -> JExpr -> JExpr Source # min :: JExpr -> JExpr -> JExpr Source #
JMacro JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JExpr -> JMGadt JExpr Source # jfromGADT :: JMGadt JExpr -> JExpr Source #
JsToDoc JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JExpr -> Doc Source #
ToJExpr JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: JExpr -> JExpr Source # toJExprFromList :: [JExpr] -> JExpr Source #
ToStat JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: JExpr -> JStat Source #
JTypeCheck JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.TypeCheck Methods typecheck :: JExpr -> TMonad JType Source #
JsToDoc [JExpr] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: [JExpr] -> Doc Source #
ToStat [JExpr] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: [JExpr] -> JStat Source #

data JVal Source #

Values

Constructors

JVar Ident |
JList [JExpr] |
JDouble SaneDouble |
JInt Integer |
JStr String |
JRegEx String |
JHash (Map String JExpr) |
JFunc [Ident] JStat |
UnsatVal (IdentSupply JVal) |

#### Instances

Instances details

Data JVal Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> JVal -> c JVal Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c JVal Source #

toConstr :: JVal -> Constr Source #

dataTypeOf :: JVal -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c JVal) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JVal) Source #

gmapT :: (forall b. Data b => b -> b) -> JVal -> JVal Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> JVal -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> JVal -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> JVal -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> JVal -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> JVal -> m JVal Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> JVal -> m JVal Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> JVal -> m JVal Source #

Show JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> JVal -> ShowS Source # show :: JVal -> String Source # showList :: [JVal] -> ShowS Source #
Eq JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: JVal -> JVal -> Bool Source # (/=) :: JVal -> JVal -> Bool Source #
Ord JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compare :: JVal -> JVal -> Ordering Source # (<) :: JVal -> JVal -> Bool Source # (<=) :: JVal -> JVal -> Bool Source # (>) :: JVal -> JVal -> Bool Source # (>=) :: JVal -> JVal -> Bool Source # max :: JVal -> JVal -> JVal Source # min :: JVal -> JVal -> JVal Source #
JMacro JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jtoGADT :: JVal -> JMGadt JVal Source # jfromGADT :: JMGadt JVal -> JVal Source #
JsToDoc JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JVal -> Doc Source #
ToJExpr JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: JVal -> JExpr Source # toJExprFromList :: [JVal] -> JExpr Source #
JTypeCheck JVal Source # |
Instance details Defined in Language.Javascript.JMacro.TypeCheck Methods typecheck :: JVal -> TMonad JType Source #

type JsLabel = String Source #

data JMGadt a where Source #

Union type to allow regular traversal by compos.

Constructors

JMGId :: Ident -> JMGadt Ident |
JMGStat :: JStat -> JMGadt JStat |
JMGExpr :: JExpr -> JMGadt JExpr |
JMGVal :: JVal -> JMGadt JVal |

#### Instances

Instances details

Compos JMGadt Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (forall a. JMGadt a -> m (JMGadt a)) -> JMGadt c -> m (JMGadt c) Source #

class Compos (t :: Type -> Type) where Source #

Methods

compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (forall a. t a -> m (t a)) -> t c -> m (t c) Source #

#### Instances

Instances details

Compos JMGadt Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (forall a. JMGadt a -> m (JMGadt a)) -> JMGadt c -> m (JMGadt c) Source #

composOp :: Compos t => (forall a. t a -> t a) -> t b -> t b Source #

composOpM :: (Compos t, Monad m) => (forall a. t a -> m (t a)) -> t b -> m (t b) Source #

composOpM_ :: (Compos t, Monad m) => (forall a. t a -> m ()) -> t b -> m () Source #

composOpFold :: Compos t => b -> (b -> b -> b) -> (forall a. t a -> b) -> t c -> b Source #

withHygiene :: JMacro a => (a -> a) -> a -> a Source #

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.

scopify :: JStat -> JStat Source #

Takes a fully saturated expression and transforms it to use unique variables that respect scope.

renderJs :: (JsToDoc a, JMacro a) => a -> Doc Source #

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 -> Doc Source #

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.

class JsToDoc a where Source #

Methods

jsToDoc :: a -> Doc Source #

#### Instances

Instances details

JsToDoc Ident Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: Ident -> Doc Source #
JsToDoc JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JExpr -> Doc Source #
JsToDoc JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JStat -> Doc Source #
JsToDoc JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JVal -> Doc Source #
JsToDoc JLocalType Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JLocalType -> Doc Source #
JsToDoc JType Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JType -> Doc Source #
JsToDoc [JExpr] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: [JExpr] -> Doc Source #
JsToDoc [JStat] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: [JStat] -> Doc Source #

class ToJExpr a where Source #

Things that can be marshalled into javascript values. Instantiate for any necessary data structures.

Minimal complete definition

toJExpr

Methods

toJExpr :: a -> JExpr Source #

toJExprFromList :: [a] -> JExpr Source #

#### Instances

Instances details

ToJExpr Value Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Value -> JExpr Source # toJExprFromList :: [Value] -> JExpr Source #
ToJExpr JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: JExpr -> JExpr Source # toJExprFromList :: [JExpr] -> JExpr Source #
ToJExpr JVal Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: JVal -> JExpr Source # toJExprFromList :: [JVal] -> JExpr Source #
ToJExpr Text Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Text -> JExpr Source # toJExprFromList :: [Text] -> JExpr Source #
ToJExpr Text Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Text -> JExpr Source # toJExprFromList :: [Text] -> JExpr Source #
ToJExpr Integer Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Integer -> JExpr Source # toJExprFromList :: [Integer] -> JExpr Source #
ToJExpr () Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: () -> JExpr Source # toJExprFromList :: [()] -> JExpr Source #
ToJExpr Bool Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Bool -> JExpr Source # toJExprFromList :: [Bool] -> JExpr Source #
ToJExpr Char Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Char -> JExpr Source # toJExprFromList :: [Char] -> JExpr Source #
ToJExpr Double Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Double -> JExpr Source # toJExprFromList :: [Double] -> JExpr Source #
ToJExpr Int Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Int -> JExpr Source # toJExprFromList :: [Int] -> JExpr Source #
ToJExpr a => ToJExpr [a] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: [a] -> JExpr Source # toJExprFromList :: [[a]] -> JExpr Source #
ToJExpr a => ToJExpr (Map String a) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: Map String a -> JExpr Source # toJExprFromList :: [Map String a] -> JExpr Source #
(ToJExpr a, ToJExpr b) => ToJExpr (a, b) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: (a, b) -> JExpr Source # toJExprFromList :: [(a, b)] -> JExpr Source #
(ToJExpr a, ToJExpr b, ToJExpr c) => ToJExpr (a, b, c) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: (a, b, c) -> JExpr Source # toJExprFromList :: [(a, b, c)] -> JExpr Source #
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d) => ToJExpr (a, b, c, d) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: (a, b, c, d) -> JExpr Source # toJExprFromList :: [(a, b, c, d)] -> JExpr Source #
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e) => ToJExpr (a, b, c, d, e) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: (a, b, c, d, e) -> JExpr Source # toJExprFromList :: [(a, b, c, d, e)] -> JExpr Source #
(ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e, ToJExpr f) => ToJExpr (a, b, c, d, e, f) Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toJExpr :: (a, b, c, d, e, f) -> JExpr Source # toJExprFromList :: [(a, b, c, d, e, f)] -> JExpr Source #

jsv :: String -> JExpr Source #

jLam :: ToSat a => a -> JExpr Source #

Create a new anonymous function. The result is an expression. Usage: `jLam $ x y -> {JExpr involving x and y}`

jVar :: ToSat a => a -> JStat Source #

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 -> JStat Source #

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}`

jFor :: (ToJExpr a, ToStat b) => JStat -> a -> JStat -> b -> JStat Source #

jForIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat Source #

Create a for in statement. Usage: `jForIn {expression} $ x -> {block involving x}`

jForEachIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat Source #

As with "jForIn" but creating a "for each in" statement.

jTryCatchFinally :: ToSat a => JStat -> a -> JStat -> JStat Source #

class ToStat a where Source #

Methods

toStat :: a -> JStat Source #

#### Instances

Instances details

ToStat JExpr Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: JExpr -> JStat Source #
ToStat JStat Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: JStat -> JStat Source #
ToStat [JExpr] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: [JExpr] -> JStat Source #
ToStat [JStat] Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods toStat :: [JStat] -> JStat Source #

nullStat :: JStat Source #

jhEmpty :: Map String JExpr Source #

jhSingle :: ToJExpr a => String -> a -> Map String JExpr Source #

jhAdd :: ToJExpr a => String -> a -> Map String JExpr -> Map String JExpr Source #

jhFromList :: [(String, JExpr)] -> JVal Source #

jsSaturate :: JMacro a => Maybe String -> a -> a Source #

Given an optional prefix, fills in all free variable names with a supply of names generated by the prefix.

jtFromList :: JType -> [(String, JType)] -> JType Source #

newtype SaneDouble Source #

Constructors

SaneDouble Double |

#### Instances

Instances details

Data SaneDouble Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SaneDouble -> c SaneDouble Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SaneDouble Source #

toConstr :: SaneDouble -> Constr Source #

dataTypeOf :: SaneDouble -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SaneDouble) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SaneDouble) Source #

gmapT :: (forall b. Data b => b -> b) -> SaneDouble -> SaneDouble Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SaneDouble -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SaneDouble -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> SaneDouble -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SaneDouble -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SaneDouble -> m SaneDouble Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SaneDouble -> m SaneDouble Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SaneDouble -> m SaneDouble Source #

Num SaneDouble Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

(+) :: SaneDouble -> SaneDouble -> SaneDouble Source #

(-) :: SaneDouble -> SaneDouble -> SaneDouble Source #

(*) :: SaneDouble -> SaneDouble -> SaneDouble Source #

negate :: SaneDouble -> SaneDouble Source #

abs :: SaneDouble -> SaneDouble Source #

signum :: SaneDouble -> SaneDouble Source #

fromInteger :: Integer -> SaneDouble Source #

Fractional SaneDouble Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (/) :: SaneDouble -> SaneDouble -> SaneDouble Source # recip :: SaneDouble -> SaneDouble Source # fromRational :: Rational -> SaneDouble Source #
Show SaneDouble Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods showsPrec :: Int -> SaneDouble -> ShowS Source # show :: SaneDouble -> String Source # showList :: [SaneDouble] -> ShowS Source #
Eq SaneDouble Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods (==) :: SaneDouble -> SaneDouble -> Bool Source # (/=) :: SaneDouble -> SaneDouble -> Bool Source #
Ord SaneDouble Source # |

Instance details

Defined in Language.Javascript.JMacro.Base

Methods

compare :: SaneDouble -> SaneDouble -> Ordering Source #

(<) :: SaneDouble -> SaneDouble -> Bool Source #

(<=) :: SaneDouble -> SaneDouble -> Bool Source #

(>) :: SaneDouble -> SaneDouble -> Bool Source #

(>=) :: SaneDouble -> SaneDouble -> Bool Source #

max :: SaneDouble -> SaneDouble -> SaneDouble Source #

min :: SaneDouble -> SaneDouble -> SaneDouble Source #

module Language.Javascript.JMacro.Prelude

data JType Source #

Constructors

JTNum |
JTString |
JTBool |
JTStat |
JTFunc [JType] JType |
JTList JType |
JTMap JType |
JTRecord JType (Map String JType) |
JTRigid VarRef (Set Constraint) |
JTImpossible |
JTFree VarRef |
JTForall [VarRef] JType |

#### Instances

Instances details

Data JType Source # |

Instance details

Defined in Language.Javascript.JMacro.Types

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> JType -> c JType Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c JType Source #

toConstr :: JType -> Constr Source #

dataTypeOf :: JType -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c JType) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JType) Source #

gmapT :: (forall b. Data b => b -> b) -> JType -> JType Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> JType -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> JType -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> JType -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> JType -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> JType -> m JType Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> JType -> m JType Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> JType -> m JType Source #

Read JType Source # |
Instance details Defined in Language.Javascript.JMacro.Types Methods readsPrec :: Int -> ReadS JType Source # readList :: ReadS [JType] Source # readPrec :: ReadPrec JType Source # readListPrec :: ReadPrec [JType] Source #
Show JType Source # |
Instance details Defined in Language.Javascript.JMacro.Types Methods showsPrec :: Int -> JType -> ShowS Source # show :: JType -> String Source # showList :: [JType] -> ShowS Source #
Eq JType Source # |
Instance details Defined in Language.Javascript.JMacro.Types Methods (==) :: JType -> JType -> Bool Source # (/=) :: JType -> JType -> Bool Source #
Ord JType Source # |
Instance details Defined in Language.Javascript.JMacro.Types Methods compare :: JType -> JType -> Ordering Source # (<) :: JType -> JType -> Bool Source # (<=) :: JType -> JType -> Bool Source # (>) :: JType -> JType -> Bool Source # (>=) :: JType -> JType -> Bool Source # max :: JType -> JType -> JType Source # min :: JType -> JType -> JType Source #
JsToDoc JLocalType Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JLocalType -> Doc Source #
JsToDoc JType Source # |
Instance details Defined in Language.Javascript.JMacro.Base Methods jsToDoc :: JType -> Doc Source #
Compos1 JType Source # |
Instance details Defined in Language.Javascript.JMacro.TypeCheck Methods compos1 :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (JType -> m JType) -> JType -> m JType Source #