Pretty-printing of AbstractCurry.
This library provides a pretty-printer for AbstractCurry modules.
data Qualification
Known instances:
data LayoutChoice
The choice for a generally preferred layout.
Constructors:
PreferNestedLayout
:: LayoutChoice
prefer a layout where the arguments of long expressions are vertically aligned Prefer a f a
if an expression does not fit the page
PreferFilledLayout
:: LayoutChoice
prefer a layout where the arguments of long expressions are filled as long as possible into one line Prefer a + b f a b
if an expression does not fit the page
data Options
The default options to pretty print a module. These are:
These options can be changed by corresponding setters
(setPageWith, setIndentWith, setShowLocalSigs
, set...Qualification
, setLayoutChoice).
Note: If these default options are used for pretty-print operations other than prettyCurryProg or ppCurryProg, then one has to set the current module name explicitly by setModName!
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.
setShowLocalSigs
:: Bool -> Options -> Options
Whether or not type signatures of local functions should be shown. In some instances, it might be necessary to show the signature of a local function, e.g., if the function's type cannot be inferred.
setImportQualification
:: Options -> 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.
setNoQualification
:: Options -> Options
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.
setFullQualification
:: Options -> Options
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.
setOnDemandQualification
:: [CurryProg] -> Options -> Options
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.
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.
showCProg
:: CurryProg -> String
Shows a pretty formatted version of an abstract Curry Program. The options for pretty-printing are the defaultOptions (and therefore the restrictions mentioned there apply here too).
:: CurryProg
|
a curry prog |
-> String
|
a string, which represents the input program prog
|
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.
This function will overwrite the module name given by options
with the name specified as the first component of CurryProg
.
The list of imported modules is extended to all modules mentioned
in the program if qualified pretty printing is used.
This is necessary to avoid errors w.r.t. names re-exported by modules.
Pretty-print a module name (just a string).
ppExports
:: Options -> [CClassDecl] -> [CInstanceDecl] -> [CTypeDecl] -> [CFuncDecl] -> Doc
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.
ppImports
:: Options -> [String] -> Doc
Pretty-print imports (list of module names) by prepending the word "import"
to the module name. If the qualification mode is Imports
or Full,
then the imports are declared as qualified
.
ppCOpDecl
:: Options -> COpDecl -> Doc
Pretty-print operator precedence declarations.
ppCTypeDecl
:: Options -> CTypeDecl -> Doc
Pretty-print type declarations, like data ... = ...
, type ... = ...
or
newtype ... = ...
.
ppCFuncDecl
:: Options -> CFuncDecl -> Doc
Pretty-print a function declaration.
ppCFuncDeclWithoutSig
:: Options -> CFuncDecl -> Doc
Pretty-print a function declaration without signature.
ppCFuncSignature
:: Options -> (String, String) -> CQualTypeExpr -> Doc
Pretty-print a function signature according to given options.
ppCQualTypeExpr
:: Options -> CQualTypeExpr -> Doc
Pretty-print a qualified type expression.
ppCTypeExpr
:: Options -> CTypeExpr -> Doc
Pretty-print a type expression.
ppCRules
:: Options -> (String, String) -> [CRule] -> Doc
Pretty-print a list of function rules, concatenated vertically. If there are no rules, an external rule is printed.
ppCRule
:: Options -> (String, String) -> CRule -> Doc
Pretty-print a rule of a function. Given a function
f x y = x * y
, then x y = x * y
is a rule consisting of x y
as list of
patterns and x * y
as right hand side.
ppCPattern
:: Options -> CPattern -> Doc
Pretty-print a pattern expression.
ppCLiteral
:: Options -> CLiteral -> Doc
Pretty-print given literal (Int, Float, ...).
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 =
, ->
.
If the right hand side contains local declarations, they will be pretty
printed too, further indented.
ppCExpr
:: Options -> CExpr -> Doc
Pretty-print an expression.
ppCStatement
:: Options -> CStatement -> Doc
ppQFunc
:: Options -> (String, String) -> Doc
Pretty-print a function name or constructor name qualified according to given options. Use ppQType or ppType for pretty-printing type names.
ppFunc
:: (String, String) -> Doc
Pretty-print a function name or constructor name non-qualified. Use ppQType or ppType for pretty-printing type names.
ppQType
:: Options -> (String, String) -> Doc
Pretty-print a type (QName
) qualified according to given options.
ppType
:: (String, String) -> Doc
Pretty-print a type (QName
) non-qualified.