Overview  Index  Help 
SMLFormat

FORMAT_EXPRESSION

All Known Implementing Modules:

FormatExpressionSMLFormat.FormatExpression


signature FORMAT_EXPRESSION =
sig
  type assoc = { cut : bool,  strength : int,  direction : assocDirection}
  datatype priority = Preferred of int | Deferred
  datatype assocDirection = Left | Right | Neutral
  datatype expression =
           Term of int * string
         | Guard of assoc option * expression list
         | Indicator of
           { space : bool,  newline : { priority : priorityoption}
         | StartOfIndent of int
         | EndOfIndent
  val isHigherThan : priority * priority -> bool
  val assocToString : assoc -> string
  val priorityToString : priority -> string
  val toString : expression -> string
  val parse
      : (char, 'a) StringCvt.reader -> (expression list, 'a) StringCvt.reader
end

This module defines types which represents format expressions.

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

 
Type detail

assoc

type assoc =
     {
       (* true if the inheritance of associativity from the upper guard is cut.*)
       cut : bool,
       (* the strength of the association.*) strength : int,
       (* the direction of the association.*) direction : assocDirection
     }

the associativity between elements in guards.

 
Datatype detail

priority

datatype priority = Preferred of int | Deferred

priority of newline indicators.


assocDirection

datatype assocDirection = Left | Right | Neutral

direction of the associativity between elements in guards


expression

datatype expression =
         Term of int * string
       | Guard of assoc option * expression list
       | Indicator of
         {
           (* true if a whitespace should be inserted here.*) space : bool,
           (* NONE if newline indicator is not specified.*)
           newline : {(* priority to insert a newline *) priority : priorityoption
         }
       | StartOfIndent of int
       | EndOfIndent

format expressions

 
DataConstructor detail

Preferred

constructor Preferred : int -> priority

preferred priority of the specified priority


Deferred

constructor Deferred : priority

deferred priority


Left

constructor Left : assocDirection

indicates left associativity


Right

constructor Right : assocDirection

indicates right associativity


Neutral

constructor Neutral : assocDirection

indicates non-directional associativity


Term

constructor Term (columns, text) : int * string -> expression

string literal. The 'columns' is not always equal to the size of 'text'. For example, a HTML code snip "<a ref=http://www.jaist.ac.jp>JAIST</a>" is encoded as Term(5, "<a ref=http://www.jaist.ac.jp>JAIST</a>"). The 'columns' is 5 which is the length of the text 'JAIST' to be displayed.

Parameters:
columns
the number of columns which the text occupies in the displayed form
text
the text to be output which may include escape sequence to encode the form to be displayed

Guard

constructor Guard (assoc, expressions)
            : assoc option * expression list -> expression

scope of indicator's priority (with assoc indicator)

Parameters:
assoc
the associativity between the expressions
expressions
the elements of the guard

Indicator

constructor Indicator
            : {
                (* true if a whitespace should be inserted here.*) space : bool,
                (* NONE if newline indicator is not specified.*)
                newline :
                {(* priority to insert a newline *) priority : priorityoption
              } ->
                expression

format indicator


StartOfIndent

constructor StartOfIndent width : int -> expression

push a indent on the indent stack

Parameters:
width
colums of indent

EndOfIndent

constructor EndOfIndent : expression

pop a indent out of the indent stack

 
Value detail

isHigherThan

fun isHigherThan (left, right) : priority * priority -> bool

compare two priorities.

Parameters:
left
a priority
right
another priority
Returns:
true if the left is higher priority than the right

assocToString

fun assocToString assoc : assoc -> string

make a string representation of the assoc.

Parameters:
assoc
a assoc
Returns:
the string representation of the assoc

priorityToString

fun priorityToString priority : priority -> string

make a string representation of the priority.

Parameters:
priority
a priority
Returns:
the string representation of the priority

toString

fun toString expression : expression -> string

make a string representation of the expression.

Parameters:
expression
a expression
Returns:
the string representation of the expression

parse

val parse
    : (char, 'a) StringCvt.reader -> (expression list, 'a) StringCvt.reader

parse format expression list.

Any character follows a back slash is interpreted as is. Especially, a sequence of ['\', '"'] is interpreted as a character '"'.

 


Overview  Index  Help 
SMLFormat: Pretty-Printer library for SML