| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
ReWire.Eidos.Pretty
Contents
Description
The Eidos concrete syntax (.eir) pretty-printer, implementing
doc/eidos.md §9. ReWire.Eidos.Parse is the other half of the
round-trip contract: parse . pretty is the identity on programs
modulo annotations (annotations are semantically inert and never
printed), and pretty . parse . pretty == pretty is a tested fixpoint.
Conventions (§9): term names, type variables, and labels print with
their uniques (x#12, Main.loop#3, a#7); type and data constructor
names print bare (Main.CPUState, Vec); primitives print by their
builtin name (rwPrimBind) — the rwPrim prefix and absence of #
distinguishes them lexically from constructors and variables. Binders
print (occ#uniq :: ty) (the case binder, whose type is the
scrutinee's, prints bare); Con, Prim, and integer-literal
occurrences print in the parenthesized-ascription form (name :: ty);
type arguments print @tyatom. The default case alternative, when
present, is first in the AST (the Core convention) and prints first,
as _ -> e.
Nothing in this module introduces a soft line break: layout is fixed
by vsep alone, so signatures (and every type) always print on one
line — the defn production's newline between the signature line and
the equation line is what terminates the signature's type.
The machine level's process declarations print through ReWire.Synolon.Pretty, which reuses these printers for the expressions, definitions, and datatypes a Synolon program embeds.
Synopsis
- prettyProgram :: Program -> Text
- ppProgram :: Program -> Doc an
- ppDataDefn :: DataDefn -> Doc an
- ppDefn :: Defn -> Doc an
- ppExp :: Exp -> Doc an
- ppBind :: Bind -> Doc an
- ppAlt :: Alt -> Doc an
- ppTy :: Ty -> Doc an
- ppSig :: Sig -> Doc an
- ppKind :: Kind -> Doc an
- ppId :: Id -> Doc an
- ppTyVar :: TyVar -> Doc an
- ppBinder :: Id -> Doc an
- ppName :: Text -> Uniq -> Doc an
- ppOcc :: Text -> Doc an
- ppOcc' :: Text -> Doc an
- ppAtom :: Exp -> Doc an
- ppStrLit :: Text -> Doc an
Documentation
prettyProgram :: Program -> Text Source #
Render a whole program in the .eir concrete syntax.
ppProgram :: Program -> Doc an Source #
A whole program: datatypes, definitions, and the top designation,
separated by blank lines.
ppDataDefn :: DataDefn -> Doc an Source #
data T kind { C1 :: sig1; ... }.
ppDefn :: Defn -> Doc an Source #
A definition: the signature line, then the equation line (attributes, name, parameter telescope) with the body on a continuation line.
ppExp :: Exp -> Doc an Source #
Expression at top level: lambda, let, case, and jump live here; all are parenthesized down at atom level.
ppAlt :: Alt -> Doc an Source #
A case alternative. Default and literal alternatives bind no fields (the grammar has no slot for them; the linter enforces emptiness).
Type, at top (arrow) level: arrows are right-associative and bind loosest; application binds tighter.
ppSig :: Sig -> Doc an Source #
A signature: forall (a#1 :: kind) ... . ty, or bare ty when the
quantifier list is empty.
ppBinder :: Id -> Doc an Source #
A term binder: (occ#uniq :: ty). Local binders are monomorphic
(doc/eidos.md §3.2), so only the signature's type is printed.
ppName :: Text -> Uniq -> Doc an Source #
A unique-carrying name occurrence: occ#uniq. Occurrence text that
does not lex as an identifier (operator names, reserved words) prints
backtick-quoted: .&
ppOcc :: Text -> Doc an Source #
Occurrence text, backtick-quoted unless it lexes as an identifier (the lexer's own predicate and reserved-word table decide).
ppOcc' :: Text -> Doc an Source #
Like ppOcc, but the tuple, unit, and list constructor names print
bare (they have their own lexemes in the grammar).