Safe Haskell | None |
---|
Common code generation utility functions
- identToJs :: Ident -> String
- identNeedsEscaping :: String -> Bool
- identCharToString :: Char -> String
- nameIsJsReserved :: String -> Bool
- moduleNameToJs :: ModuleName -> String
- lookupConstructor :: Environment -> Qualified ProperName -> (DataDeclType, ProperName, Type)
- isOnlyConstructor :: Environment -> Qualified ProperName -> Bool
- isNewtypeConstructor :: Environment -> Qualified ProperName -> Bool
- getConstructorArity :: Environment -> Qualified ProperName -> Int
- isNullaryConstructor :: Environment -> Qualified ProperName -> Bool
Documentation
identToJs :: Ident -> StringSource
Convert an Ident into a valid Javascript identifier:
- Alphanumeric characters are kept unmodified.
- Reserved javascript identifiers are prefixed with
$$
. - Symbols are prefixed with
$
followed by a symbol name or their ordinal value.
identNeedsEscaping :: String -> BoolSource
Test if a string is a valid JS identifier without escaping.
identCharToString :: Char -> StringSource
Attempts to find a human-readable name for a symbol, if none has been specified returns the ordinal value.
nameIsJsReserved :: String -> BoolSource
Checks whether an identifier name is reserved in Javascript.
lookupConstructor :: Environment -> Qualified ProperName -> (DataDeclType, ProperName, Type)Source
Finds the value stored for a data constructor in the current environment. This is a partial function, but if an invalid type has reached this far then something has gone wrong in typechecking.
isOnlyConstructor :: Environment -> Qualified ProperName -> BoolSource
Checks whether a data constructor is the only constructor for that type, used to simplify the check when generating code for binders.
isNewtypeConstructor :: Environment -> Qualified ProperName -> BoolSource
Checks whether a data constructor is for a newtype.
getConstructorArity :: Environment -> Qualified ProperName -> IntSource
Checks the number of arguments a data constructor accepts.
isNullaryConstructor :: Environment -> Qualified ProperName -> BoolSource
Checks whether a data constructor has no arguments, for example, Nothing
.