Overview  Index  Help 
SMLFormat

PRETTYPRINTER

All Known Implementing Modules:

PrettyPrinter


signature PRETTYPRINTER =
sig
  type environmentEntry =
       {
          requiredColumns : int,
          newline : bool ref,
          priority : FormatExpression.priority
       }
  type environment = environmentEntry list
  datatype symbol =
           Term of int * string
         | List of { symbols : symbol list,  environment : environment}
         | Indicator of { space : bool,  newline : bool ref}
         | DeferredIndicator of { space : bool,  requiredColumns : int ref}
         | StartOfIndent of int
         | EndOfIndent
  exception Fail of string
  val format : PrinterParameter.parameter list -> symbol -> string
end

This module translates the symbols into a text representation which fits within the specified column width.

Author:
YAMATODANI Kiyoshi
Version:
$Id: SigPRETTYPRINTER.html,v 1.5 2007/03/27 15:03:01 kiyoshiy Exp $

 
Type detail

environmentEntry

type environmentEntry =
     {
       (* the number of columns required to print the text without inserting newlines at the indicators of the priority.*)
       requiredColumns : int,
       (* indicates whether to begin a newline at the all indicators of the priority *)
       newline : bool ref,
       (* the priority *) priority : FormatExpression.priority
     }

The entry which contains the information needed to decide to begin newlines at the newline indicators. The preferred indicators of the same priority share a entry. Separate entries are generated for each deferred indicators.


environment

type environment = environmentEntry list

 
Datatype detail

symbol

datatype symbol =
         Term of int * string
       | List of
         {
           (* the list of symbols *) symbols : symbol list,
           (* the environment consisting of entries for preferred indicators.*)
           environment : environment
         }
       | Indicator of
         {
           (* true if the space indicator is specified.*) space : bool,
           (* become true if a newline should begin at this indicator.*)
           newline : bool ref
         }
       | DeferredIndicator of
         {
           (* true if the space indicator is specified.*) space : bool,
           (* the number of columns required to print the text without inserting newlines at this indicator.*)
           requiredColumns : int ref
         }
       | StartOfIndent of int
       | EndOfIndent

 
DataConstructor detail

Term

constructor Term : int * string -> symbol

the term string literal


List

constructor List
            : {
                (* the list of symbols *) symbols : symbol list,
                (* the environment consisting of entries for preferred indicators.*)
                environment : environment
              } ->
                symbol

non terminal


Indicator

constructor Indicator
            : {
                (* true if the space indicator is specified.*) space : bool,
                (* become true if a newline should begin at this indicator.*)
                newline : bool ref
              } ->
                symbol

the format indicators


DeferredIndicator

constructor DeferredIndicator
            : {
                (* true if the space indicator is specified.*) space : bool,
                (* the number of columns required to print the text without inserting newlines at this indicator.*)
                requiredColumns : int ref
              } ->
                symbol

the format indicators with deferred newline priority


StartOfIndent

constructor StartOfIndent : int -> symbol

the width of indent.


EndOfIndent

constructor EndOfIndent : symbol

the end of indent scope

 
Value detail

format

fun format parameter symbol
    : PrinterParameter.parameter list -> symbol -> string

translates the symbol into a text representation which fits within the specified column width.

This function tries to insert newline characters so that the text can fit within the specified column width, but it may exceed the specified column width if the column width is too small.

Parameters:
parameter
parameters which control the printer
symbol
the symbol to be translated.
Returns:
the text representation of the symbol.

 
Exception detail

Fail

exception Fail of string

raised when any error occurs.

Parameters:
message
the error message


Overview  Index  Help 
SMLFormat: Pretty-Printer library for SML