Copyright | (c) Owen Bechtel 2023 |
---|---|
License | MIT |
Maintainer | ombspring@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
x
translates tox
ifx
is a function, and
ifpush
xx
is a data constructor. $x
translates to
. For example,liftS
x$reverse
will reverse the list on top of the stack.#x
translates to
. For example,liftS2
x#gcd
will pop the top two values and push their gcd.?x
translates to
. For example,pushM
x?getLine
will executegetLine
and push the result.!x
translates to
. For example,popM
x!putStrLn
will print the string on top of the stack.&x
translates to
. For example,liftSM
x&readFile
will pop a file path and push the contents of that file.
- An identifier
- A Haskell operator.
This translates to
liftS2
applied 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,
5
translates to
.push
5 - 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