Pretty-printing of AbstractCurry.
This library provides a pretty-printer for AbstractCurry modules.
Author: Yannik Potdevin (with changes by Michael Hanus)
Version: March 2016
defaultOptions
:: Options
The default options to pretty print a module. |
setEvExp
:: FM ((Int,Int),(Int,Int)) [BoxLabel] -> Options -> Options
Sets the page width of the pretty printer options. |
setPageWith
:: Int -> Options -> Options
Sets the page width of the pretty printer options. |
setIndentWith
:: Int -> Options -> Options
Sets the indentation width of the pretty printer options. |
setImportQualification
:: Options -> Options
Sets the qualification method to be used to print identifiers to "import qualification" (which is the default). |
setNoQualification
:: Options -> Options
Sets the qualification method to be used to print identifiers to "unqualified". |
setFullQualification
:: Options -> Options
Sets the qualification method to be used to print identifiers to "fully qualified". |
setOnDemandQualification
:: [CurryProg] -> Options -> Options
Sets the qualification method to be used to print identifiers to "qualification on demand". |
setModName
:: String -> Options -> Options
Sets the name of the current module in the pretty printer options. |
setLayoutChoice
:: LayoutChoice -> Options -> Options
Sets the preferred layout in the pretty printer options. |
setRelatedMods
:: [CurryProg] -> Options -> Options
Sets the related modules in the pretty printer options. |
tlPrec
:: Int
precedence of top level (pattern or application) context -- lowest |
infAppPrec
:: Int
precedence of infix (pattern or application) context |
prefAppPrec
:: Int
precedence of standard prefix (pattern or application) context |
highestPrec
:: Int
precedence of atoms (variables, literals, tuples, lists ...) |
showCProg
:: CurryProg -> String
Shows a pretty formatted version of an abstract Curry Program. |
showDProg
:: FM ((Int,Int),(Int,Int)) [BoxLabel] -> CurryProg -> String
|
prettyCurryProg
:: Options -> CurryProg -> String
Pretty-print the document generated by ppCurryProg , using the page width
specified by given options.
|
ppCurryProg
:: Options -> CurryProg -> Doc
Pretty-print a CurryProg (the representation of a program, written in Curry, using AbstractCurry) according to given options. |
ppMName
:: String -> Doc
Pretty-print a module name (just a string). |
ppExports
:: Options -> [CTypeDecl] -> [CFuncDecl] -> Doc
Pretty-print exports, i.e. |
ppConsExports
:: Options -> [CConsDecl] -> Doc
|
ppImports
:: Options -> [String] -> Doc
Pretty-print imports (list of module names) by prepending the word "import" to the module name. |
ppCOpDecl
:: Options -> COpDecl -> Doc
Pretty-print operator precedence declarations. |
ppCFixity
:: CFixity -> Doc
Pretty-print the fixity of a function. |
ppCTypeDecl
:: Options -> CTypeDecl -> Doc
Pretty-print type declarations, like `data ... |
ppCConsDecls
:: Options -> [CConsDecl] -> Doc
Pretty-print a list of constructor declarations, including the =
sign.
|
ppCConsDecl
:: Options -> CConsDecl -> Doc
Pretty-print a constructor declaration. |
ppCFieldDecl
:: Options -> CFieldDecl -> Doc
Pretty-print a record field declaration ( field :: type ).
|
ppCFuncDecl
:: Options -> CFuncDecl -> Doc
Pretty-print a function declaration. |
ppCFuncDeclWithoutSig
:: Options -> CFuncDecl -> Doc
Pretty-print a function declaration without signature. |
ppCFuncSignature
:: Options -> (((Int,Int),(Int,Int)),String,String) -> CTypeExpr -> Doc
Pretty-print a function signature according to given options. |
ppCTypeExpr
:: Options -> CTypeExpr -> Doc
Pretty-print a type expression. |
ppCTypeExpr'
:: Int -> Options -> CTypeExpr -> Doc
|
ppCTVarINames
:: Options -> [(((Int,Int),(Int,Int)),Int,String)] -> Doc
Pretty-print a list of type variables horizontally separating them by space .
|
ppCTVarIName
:: Options -> (((Int,Int),(Int,Int)),Int,String) -> Doc
Pretty-print a type variable (currently the Int is ignored). |
ppCRules
:: Options -> (((Int,Int),(Int,Int)),String,String) -> [CRule] -> Doc
Pretty-print a list of function rules, concatenated vertically. |
ppCRule
:: Options -> (((Int,Int),(Int,Int)),String,String) -> CRule -> Doc
Pretty-print a rule of a function. |
ppCPattern
:: Options -> CPattern -> Doc
Pretty-print a pattern expression. |
ppCPattern'
:: Int -> Options -> CPattern -> Doc
|
ppCVarIName
:: Options -> (((Int,Int),(Int,Int)),Int,String) -> Doc
Pretty-print a pattern variable (currently the Int is ignored). |
ppCLiteral
:: Options -> CLiteral -> Doc
Pretty-print given literal (Int, Float, ...). |
ppCFieldPattern
:: Options -> ((((Int,Int),(Int,Int)),String,String),CPattern) -> Doc
Pretty-print a record pattern |
ppCRhs
:: Doc -> Options -> CRhs -> Doc
Pretty-print the right hand side of a rule (or case expression), including the d sign, where d
is the relation (as doc) between the left hand side
and the right hand side -- usually this is one of = , -> .
|
ppFuncRhs
:: Options -> CRhs -> Doc
Like ppCRhs , but do not pretty-print local declarations.
|
ppCaseRhs
:: Options -> CRhs -> Doc
|
ppCGuardedRhs
:: Options -> Doc -> [(((Int,Int),(Int,Int)),CExpr,CExpr)] -> Doc
Pretty-print guard, i.e. |
ppCLocalDecls
:: Options -> Doc -> [CLocalDecl] -> Doc
Pretty-print local declarations . |
ppCLocalDecl
:: Options -> CLocalDecl -> Doc
Pretty-print local declarations (the part that follows the where
keyword).
|
ppWhereDecl
:: Options -> [CLocalDecl] -> Doc
Pretty-print a where
block, in which the word where
stands alone in a
single line, above the following declarations.
|
ppLetDecl
:: Options -> [CLocalDecl] -> Doc
Pretty-print a let
block without in .
|
ppCExpr
:: Options -> CExpr -> Doc
Pretty-print an expression. |
colorExp
:: Options -> ((Int,Int),(Int,Int)) -> Doc -> Doc
|
ppCExpr'
:: Int -> Options -> CExpr -> Doc
|
ppCStatement
:: Options -> CStatement -> Doc
|
ppCCaseType
:: CCaseType -> Doc
Pretty-print case , fcase
keywords.
|
ppCases
:: Options -> [(CPattern,CRhs)] -> Doc
Pretty-print a list of case expressions, i.e. |
ppCase
:: Options -> (CPattern,CRhs) -> Doc
Pretty-print a case expression. |
ppRecordFields
:: Options -> [((((Int,Int),(Int,Int)),String,String),CExpr)] -> Doc
Pretty-print record field assignments like this: { lab1 = exp1, ..., labn expn } if it fits the page, or { lab1 = exp1 , ... |
ppRecordField
:: Options -> ((((Int,Int),(Int,Int)),String,String),CExpr) -> Doc
Pretty-print a record field assignment ( fieldLabel = exp ).
|
genericPPQName
:: [(((Int,Int),(Int,Int)),String,String)] -> [(((Int,Int),(Int,Int)),Int,String)] -> ((((Int,Int),(Int,Int)),String,String) -> Doc -> Doc) -> Options -> (((Int,Int),(Int,Int)),String,String) -> Doc
Pretty-print a QName qualified according to given options. |
genericPPName
:: ((((Int,Int),(Int,Int)),String,String) -> Doc -> Doc) -> (((Int,Int),(Int,Int)),String,String) -> Doc
|
ppQFunc
:: Options -> (((Int,Int),(Int,Int)),String,String) -> Doc
Pretty-print a function name or constructor name qualified according to given options. |
ppQFuncParsIfInfix
:: Options -> (((Int,Int),(Int,Int)),String,String) -> Doc
Like ppQFunc , but surround name with parentheses if it is an infix
identifier.
|
ppFunc
:: (((Int,Int),(Int,Int)),String,String) -> Doc
Pretty-print a function name or constructor name non-qualified. |
ppQType
:: Options -> (((Int,Int),(Int,Int)),String,String) -> Doc
Pretty-print a type ( QName ) qualified according to given options.
|
ppQTypeParsIfInfix
:: Options -> (((Int,Int),(Int,Int)),String,String) -> Doc
Like ppQType , but surround name with parentheses if it is an infix
identifier.
|
ppType
:: (((Int,Int),(Int,Int)),String,String) -> Doc
Pretty-print a type ( QName ) non-qualified.
|
isInfixId
:: (((Int,Int),(Int,Int)),String,String) -> Bool
Check whether an operator is an infix identifier. |
isUnitCons
:: (((Int,Int),(Int,Int)),String,String) -> Bool
Check whether an identifier represents the unit constructor |
isListCons
:: (((Int,Int),(Int,Int)),String,String) -> Bool
Check whether an identifier represents the empty list constructor |
isConsCons
:: (((Int,Int),(Int,Int)),String,String) -> Bool
Check whether an identifier represents the list constructor :
|
isTupleCons
:: (((Int,Int),(Int,Int)),String,String) -> Bool
Check whether an identifier represents a tuple constructor |
extractITE
:: CExpr -> Maybe (CExpr,CExpr,CExpr)
Check if given application tree represents an if then else construct. |
extractInfix
:: CExpr -> Maybe ((((Int,Int),(Int,Int)),String,String),CExpr,CExpr)
Check if given application tree represents an infix operator application. |
extractTuple
:: CExpr -> Maybe [CExpr]
Check if given application tree represents a tuple contructor application. |
extractFiniteListExp
:: CExpr -> Maybe [CExpr]
Check if given application tree represents a finite list [x1, ..., xn] .
|
extractFiniteListPattern
:: CPattern -> Maybe [CPattern]
Check if given construct pattern represents a finite list [x1, ..., xn] .
|
hsepMap
:: (a -> Doc) -> [a] -> Doc
|
vcatMap
:: (a -> Doc) -> [a] -> Doc
|
vsepMap
:: (a -> Doc) -> [a] -> Doc
|
vsepBlankMap
:: (a -> Doc) -> [a] -> Doc
|
vvsep
:: [Doc] -> Doc
|
vvsepMap
:: (a -> Doc) -> [a] -> Doc
|
fillSepMap
:: (a -> Doc) -> [a] -> Doc
|
encloseSepSpaced
:: Doc -> Doc -> Doc -> [Doc] -> Doc
|
alignedList
:: [Doc] -> Doc
|
filledList
:: [Doc] -> Doc
|
alignedSetSpaced
:: [Doc] -> Doc
|
alignedTupled
:: [Doc] -> Doc
|
filledTupled
:: [Doc] -> Doc
|
filledTupledSpaced
:: [Doc] -> Doc
|
nest'
:: Options -> Doc -> Doc
|
indent'
:: Options -> Doc -> Doc
|
bquotesIf
:: Bool -> Doc -> Doc
|
parsIfInfix
:: (((Int,Int),(Int,Int)),String,String) -> Doc -> Doc
|
larrow
:: Doc
|
where_
:: Doc
|
nil
:: Doc
|
on'
:: (a -> a -> b) -> (c -> a) -> (c -> a) -> c -> b
|
emptyCol
:: [a]
|
appendCol
:: [a] -> [a] -> [a]
|
anyCol
:: (a -> Bool) -> [a] -> Bool
|
fromList
:: [a] -> [a]
|
addVarsToOpts
:: [(((Int,Int),(Int,Int)),Int,String)] -> Options -> Options
|
addFuncNamesToOpts
:: [(((Int,Int),(Int,Int)),String,String)] -> Options -> Options
|
addVarsAndFuncNamesToOpts
:: [(((Int,Int),(Int,Int)),Int,String)] -> [(((Int,Int),(Int,Int)),String,String)] -> Options -> Options
|
optsWithIncreasingNamespaces
:: (a -> [(((Int,Int),(Int,Int)),Int,String)]) -> (a -> [(((Int,Int),(Int,Int)),String,String)]) -> [a] -> Options -> [Options]
Generates a list of options with increasing numbers of visible variables and function names. |
varsOfLDecl
:: CLocalDecl -> [(((Int,Int),(Int,Int)),Int,String)]
In contrast to AbstractCurry.Select.varsOfLDecl , this function does not
include variables of right hand sides.
|
varsOfFDecl
:: CFuncDecl -> [(((Int,Int),(Int,Int)),Int,String)]
In contrast to AbstractCurry.Select.varsOfFDecl , this function does not
include variables of right hand sides.
|
varsOfStat
:: CStatement -> [(((Int,Int),(Int,Int)),Int,String)]
In contrast to AbstractCurry.Select.varsOfStat , this function does not
include variables of right hand sides.
|
third
:: (a,b,c) -> c
|
second
:: (a,b,c) -> b
|
Type synonym: Collection a = [a]
Constructors:
Full
:: Qualification
Imports
:: Qualification
OnDemand
:: Qualification
None
:: Qualification
The choice for a generally preferred layout.
Constructors:
PreferNestedLayout
:: LayoutChoice
: prefer a layout where the arguments of
long expressions are vertically aligned
PreferFilledLayout
:: LayoutChoice
: prefer a layout where the arguments of
long expressions are filled as long as possible
into one line
Constructors:
Options
:: Int -> Int -> Qualification -> String -> Bool -> LayoutChoice -> (Collection QName) -> (Collection QName) -> (Collection CVarIName) -> (FM Span [BoxLabel]) -> Options
Fields:
pageWidth
:: Int
indentationWidth
:: Int
qualification
:: Qualification
moduleName
:: String
showLocalSigs
:: Bool
layoutChoice
:: LayoutChoice
visibleTypes
:: (Collection QName)
visibleFunctions
:: (Collection QName)
visibleVariables
:: (Collection CVarIName)
evaluatedExpressions
:: (FM Span [BoxLabel])
The default options to pretty print a module. These are:
These options can be changed by corresponding setters
(
Note: If these default options are used for pretty-print operations
other than |
Sets the page width of the pretty printer options.
|
Sets the page width of the pretty printer options.
|
Sets the indentation width of the pretty printer options.
|
Sets the qualification method to be used to print identifiers to "import qualification" (which is the default). In this case, all identifiers imported from other modules (except for the identifiers of the prelude) are fully qualified.
|
Sets the qualification method to be used to print identifiers to "unqualified". In this case, no identifiers is printed with its module qualifier. This might lead to name conflicts or unintended references if some identifiers in the pretty-printed module are in conflict with imported identifiers.
|
Sets the qualification method to be used to print identifiers to "fully qualified". In this case, every identifiers, including those of the processed module and the prelude, are fully qualified.
|
Sets the qualification method to be used to print identifiers to "qualification on demand". In this case, an identifier is qualified only if it is necessary to avoid a name conflict, e.g., if a local identifier has the same names as an imported identifier. Since it is necessary to know the names of all identifiers defined in the current module (to be pretty printed) and imported from other modules, the first argument is the list of modules consisting of the current module and all imported modules (including the prelude). The current module must always be the head of this list. |
Sets the name of the current module in the pretty printer options.
|
Sets the preferred layout in the pretty printer options.
|
Sets the related modules in the pretty printer options. See |
precedence of top level (pattern or application) context -- lowest
|
precedence of infix (pattern or application) context
|
precedence of standard prefix (pattern or application) context
|
precedence of atoms (variables, literals, tuples, lists ...)
|
Shows a pretty formatted version of an abstract Curry Program.
The options for pretty-printing are the
|
Pretty-print the document generated by |
Pretty-print a CurryProg (the representation of a program, written in Curry,
using AbstractCurry) according to given options.
This function will overwrite the module name given by options
with the name specified as the first component of |
Pretty-print a module name (just a string).
|
Pretty-print exports, i.e. all type and function declarations which are public. extract the type and function declarations which are public and gather their qualified names in a list. |
|
Pretty-print imports (list of module names) by prepending the word "import"
to the module name. If the qualification mode is |
Pretty-print the fixity of a function.
|
Pretty-print type declarations, like |
Pretty-print a list of constructor declarations, including the |
Pretty-print a constructor declaration. |
Pretty-print a record field declaration ( |
Pretty-print a function declaration. |
Pretty-print a function declaration without signature. |
Pretty-print a function signature according to given options. |
Pretty-print a type expression. |
|
Pretty-print a list of type variables horizontally separating them by |
Pretty-print a type variable (currently the Int is ignored).
|
Pretty-print a list of function rules, concatenated vertically. |
Pretty-print a rule of a function. Given a function
|
Pretty-print a pattern expression. |
|
Pretty-print a pattern variable (currently the Int is ignored).
|
Pretty-print given literal (Int, Float, ...). |
Pretty-print a record pattern |
Pretty-print the right hand side of a rule (or case expression), including
the d sign, where |
Like |
Pretty-print guard, i.e. the |
Pretty-print local declarations . If the second argument is |
Pretty-print local declarations (the part that follows the |
Pretty-print a |
Pretty-print a |
|
Pretty-print
|
Pretty-print a list of case expressions, i.e. the |
Pretty-print record field assignments like this: { lab1 = exp1, ..., labn expn } if it fits the page, or { lab1 = exp1 , ... , labn = expn } otherwise. |
Pretty-print a record field assignment ( |
Pretty-print a QName qualified according to given options.
|
|
Pretty-print a function name or constructor name qualified according to
given options. Use |
Like |
Pretty-print a function name or constructor name non-qualified.
Use |
Pretty-print a type ( |
Like |
Check whether an operator is an infix identifier. |
Check whether an identifier represents the unit constructor |
Check whether an identifier represents the empty list constructor |
Check whether an identifier represents the list constructor |
Check whether an identifier represents a tuple constructor |
Check if given application tree represents an if then else construct.
If so, return the condition, the "then expression" and the "else expression".
Otherwise, return |
Check if given application tree represents an infix operator application.
If so, return the operator, its left and its right argument. Otherwise,
return |
Check if given application tree represents a tuple contructor application.
If so, return the constructor and its arguments in a list. Otherwise, return
|
Check if given application tree represents a finite list |
Check if given construct pattern represents a finite list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Generates a list of options with increasing numbers of visible variables
and function names. Resulting lists are useful to match the scopes of
do expressions and list comprehensions, where latter statements see previous
variables and functions names, but prior elements do not see subsequent
variables and function names.
Note that
|
In contrast to |
In contrast to |
In contrast to |
|
|