| Copyright | (c) Owen Bechtel 2023 |
|---|---|
| License | MIT |
| Maintainer | ombspring@gmail.com |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Jaskell.Quote
Contents
Description
The jsl quasiquoter converts Jaskell syntax into Haskell syntax.
A Jaskell expression is a sequence of commands. An command is one of the following:
A Haskell identifier, optionally preceded by
$,#,?,!, or&. The identifier can be qualified or unqualified, and can be lowercase (function) or uppercase (data constructor). It cannot be an operator.- An identifier
xtranslates toxifxis a function, andifpushxxis a data constructor. $xtranslates to. For example,liftSx$reversewill reverse the list on top of the stack.#xtranslates to. For example,liftS2x#gcdwill pop the top two values and push their gcd.?xtranslates to. For example,pushMx?getLinewill executegetLineand push the result.!xtranslates to. For example,popMx!putStrLnwill print the string on top of the stack.&xtranslates to. For example,liftSMx&readFilewill pop a file path and push the contents of that file.
- An identifier
- A Haskell operator.
This translates to
liftS2applied to the operator. - A list of zero or more expressions, surrounded in square brackets and separated by commas.
For example,
[ 1, 3, 4 1 + ]pushes the list[ 1, 3, 5 ]onto the stack. - A tuple of two expressions.
For example,
( 0, "a" "b" ++ )pushes the tuple( 0, "ab" )onto the stack. - An empty tuple. This translates to
.push() - An integer, floating-point, character, or string literal.
For example,
5translates to.push5 - A (potentially empty) expression surrounded in curly brackets. This pushes the translation of the expression onto the stack, allowing for higher-order programming.
Jaskell programs can be preceded by zero or more definitions, each of the form DEF name = expr ;.
Definitions can be recursive and even mutually recursive.
Synopsis
- jsl :: QuasiQuoter
- data NameMode
- data Name
- data Literal
- data Command
- newtype Expr = Expr (NonEmpty Command)
- data Program = Program [(String, Expr)] Expr
- type Parser = Parsec Void String
- parseName :: Parser Name
- parseLiteral :: Parser Literal
- parseCommand :: Parser Command
- parseExpr :: Parser Expr
- parseProgram :: Parser Program