Formatting strings for output.
List of Import References :
See BOOL
See BTUnion
See Char
See DENOTATION
See Int
See Nat
See Option
See Real
See Seq
See String
SIGNATURE StringFormat
$Date: 2010-09-30 18:24:17 +0200 (Do, 30. Sep 2010) $ ($Revision: 616 $)
IMPORT Nat ONLY nat Int ONLY int Real ONLY real Char ONLY char String ONLY string Seq[union] ONLY seq BTUnion ONLY union
format(pattern, args)
converts arguments as described in
pattern
to a string. The pattern format is modelled after C and
specified below.
FUN format : denotation ** seq[union] -> string FUN format : string ** seq[union] -> string
The expression format(Pattern <- Val1 & Val2 & ... & ValN)
is equivalent to
format(Pattern, %(t1(Val1),t2(Vale),...,tN(ValN)))
,
where tI
is the according union constructor from
BTUnion.
SORT script FUN <- : denotation ** denotation -> script FUN <- : denotation ** string -> script FUN <- : denotation ** real -> script FUN <- : denotation ** nat -> script FUN <- : denotation ** int -> script FUN & : script ** denotation -> script FUN & : script ** string -> script FUN & : script ** real -> script FUN & : script ** nat -> script FUN & : script ** int -> script FUN formatS: script -> string
The format of pattern
is interpreted with the following grammar.
Metasymbols are bold, comments are in italics.
format | ::= | { formatEl } |
formatEl | ::= | % % output single % | % { flag } [ len ] [ . [ prec ] ] type | other char |
flag | ::= | - left justify | |
+ always prepend sign | | ||
space prepend space if not negative | | ||
0 justify with zeros | | ||
# alternate format | ||
len | ::= | * read length from seq[union] , must be nat | number
|
prec | ::= | * read precision from seq[union] , must be nat |
|
number | ||
number | ::= | { 0 | .. | 9 } no leading zeros |
type | ::= | n nat | i int | s string | c char | b bool | r real-1 | R real-2 | e real-3 | d denotation |
other char | ::= | print as themselve |
%
- formats are interpreted thus:
*
is given for len or precision the value is given by
the
current head of the seq[union]
, which must be of type nat
.
The head of the seq[union]
must be of the given type. It is removed from
the seq and formatted as specified.
%r | real-1 | if (abs(number) <= max'Nat and abs(number) > 1e-4) or number = 0 then output [+|-]nnnn.ddddd else [+|-]n.dddddd e[+|-]nnn |
%R | real-2 | output as [+|-]nnnnnnnnnnn.ddddddddd |
%e | real-3 | output as [+|-]n.dddddd[e][+|-]nnnn |
next node: StringScan,
prev node: BTUnionConv,
up to node: Subsystem String Formatting And Scanning