Module AbstractCurry.Pretty

Pretty-printing of AbstractCurry.

This library provides a pretty-printer for AbstractCurry modules.

Author: Yannik Potdevin (with changes by Michael Hanus)

Version: June 2018

Summary of exported operations:

defaultOptions :: Options   
The default options to pretty print a module.
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.
showCProg :: CurryProg -> String   
Shows a pretty formatted version of an abstract Curry Program.
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.
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.
ppCTypeDecl :: Options -> CTypeDecl -> Doc   
Pretty-print type declarations, like `data ...
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.
ppCRule :: Options -> (String,String) -> CRule -> Doc   
Pretty-print a rule of a function.
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 =, ->.
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.
ppFunc :: (String,String) -> Doc   
Pretty-print a function name or constructor name non-qualified.
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.

Exported datatypes:


Qualification

Constructors:


LayoutChoice

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

Options

Constructors:


Exported operations:

defaultOptions :: Options   

The default options to pretty print a module. These are:

  • page width: 78 characters
  • indentation width: 2 characters
  • qualification method: qualify all imported names (except prelude names)
  • layout choice: prefer nested layout (see LayoutChoice)

These options can be changed by corresponding setters (setPageWith, setIndentWith, 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!

Further infos:
  • solution complete, i.e., able to compute all solutions

setPageWith :: Int -> Options -> Options   

Sets the page width of the pretty printer options.

Further infos:
  • solution complete, i.e., able to compute all solutions

setIndentWith :: Int -> Options -> Options   

Sets the indentation width of the pretty printer options.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

setLayoutChoice :: LayoutChoice -> Options -> Options   

Sets the preferred layout in the pretty printer options.

Further infos:
  • solution complete, i.e., able to compute all solutions

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).

Example call:
(showCProg prog)
Parameters:
  • prog : a curry prog
Returns:
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.

ppMName :: String -> Doc   

Pretty-print a module name (just a string).

Further infos:
  • solution complete, i.e., able to compute all solutions

ppExports :: Options -> [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.

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.