Safe Haskell | None |
---|---|
Language | Haskell2010 |
A parser for the STG language, modeled after the grammar given in the description in the 1992 paper (link) with a couple of differences to enhance usability:
- Function application uses no parentheses or commas like in Haskell
(
f x y z
), not with curly parentheses and commas like in the paper (f {x,y,z}
). - Comment syntax like in Haskell:
-- inline
,{- multiline -}
. - Constructors may end with a
#
to allow labelling primitive boxes e.g. withInt#
. - A lambda's head is written
\(free) bound -> body
, wherefree
andbound
are space-separated variable lists, instead of the paper's{free} \n {bound} -> body
, which uses comma-separated lists. The update flag\u
is signified using a double arrow=>
instead of the normal arrow->
.
- parse :: StgParser ast -> Text -> Either Doc ast
- data StgParser ast
- program :: (Monad parser, TokenParsing parser) => parser Program
- binds :: (Monad parser, TokenParsing parser) => parser Binds
- lambdaForm :: (Monad parser, TokenParsing parser) => parser LambdaForm
- expr :: (Monad parser, TokenParsing parser) => parser Expr
- alts :: (Monad parser, TokenParsing parser) => parser Alts
- nonDefaultAlts :: (Monad parser, TokenParsing parser) => parser NonDefaultAlts
- algebraicAlt :: (Monad parser, TokenParsing parser) => parser AlgebraicAlt
- primitiveAlt :: (Monad parser, TokenParsing parser) => parser PrimitiveAlt
- defaultAlt :: (Monad parser, TokenParsing parser) => parser DefaultAlt
- literal :: TokenParsing parser => parser Literal
- primOp :: TokenParsing parser => parser PrimOp
- atom :: (Monad parser, TokenParsing parser) => parser Atom
- var :: (Monad parser, TokenParsing parser) => parser Var
- con :: (Monad parser, TokenParsing parser) => parser Constr
General parsing
A parser for an STG syntax element.
Parser rules
program :: (Monad parser, TokenParsing parser) => parser Program Source
Parse an STG program.
binds :: (Monad parser, TokenParsing parser) => parser Binds Source
Parse a collection of bindings, used by let(rec)
expressions and at the
top level of a program.
lambdaForm :: (Monad parser, TokenParsing parser) => parser LambdaForm Source
Parse a lambda form, consisting of a list of free variables, and update flag, a list of bound variables, and the function body.
expr :: (Monad parser, TokenParsing parser) => parser Expr Source
Parse an expression, which can be
- let,
let(rec) ... in ...
- case,
case ... of ...
- function application,
f (...)
- constructor application,
C (...)
- primitive application,
p# (...)
- literal,
1#
alts :: (Monad parser, TokenParsing parser) => parser Alts Source
Parse the alternatives given in a case
expression.
nonDefaultAlts :: (Monad parser, TokenParsing parser) => parser NonDefaultAlts Source
Parse non-default alternatives. The list of alternatives can be either empty, all algebraic, or all primitive.
Nil -> ... Cons x xs -> ...
1# -> ... 2# -> ...
algebraicAlt :: (Monad parser, TokenParsing parser) => parser AlgebraicAlt Source
Parse a single algebraic alternative.
Cons x xs -> ...
primitiveAlt :: (Monad parser, TokenParsing parser) => parser PrimitiveAlt Source
Parse a single primitive alternative, such as 1#
.
1# -> ...
defaultAlt :: (Monad parser, TokenParsing parser) => parser DefaultAlt Source
Parse the default alternative, taken if none of the other alternatives
in a case
expression match.
default -> ...
v -> ...
literal :: TokenParsing parser => parser Literal Source
primOp :: TokenParsing parser => parser PrimOp Source
Parse a primitive operation.
+#
atom :: (Monad parser, TokenParsing parser) => parser Atom Source
var :: (Monad parser, TokenParsing parser) => parser Var Source
Parse a variable identifier. Variables start with a lower-case letter or
_
, followed by a string consisting of alphanumeric characters or '
, _
.
con :: (Monad parser, TokenParsing parser) => parser Constr Source
Parse a constructor identifier. Constructors follow the same naming
conventions as variables, but start with an upper-case character instead, and
may end with a #
symbol.