Skip to content

Language Specification (H) : IO Library Format Specifiers

Benjamin Kowarsch edited this page Aug 18, 2020 · 3 revisions

IO Library Format Specifiers

Format Specifier Syntax for Type BOOLEAN

boolFmtStr := shortBool | longBool ;
shortBool := ’[’ ( trueSym | falseSym ) ’]’ ;
alias trueSym, falseSym = PrintableChar ;
longBool := ’TF’ | ’Tf’ | ’tf’ | ’YN’ | ’Yn’ | ’yn’ ;
WRITE #("TF", bool); (*TRUE or FALSE*)   WRITE #("[0|1]", bool); (*0 or 1*)

Format Specifier Syntax for Character Types

charFmt := quoted? glyph | codePoint ;
quoted := ’Q’ | ’QQ’ ;
glyph = ’A’ | ’UTF8’ ;
codePoint := ’U+’ digitCount | ’0u’ digitFmt? ; digitFmt := digitCount digitGrouping? ;
digitCount := leastNumOfDigits | fixedNumOfDigits ; alias leastNumOfDigits = ’*’ ;
fixedNumOfDigits := Digit+ ;
digitGrouping := digitSep digitsPerGroup ;
digitSep := localeDependent | apostrophe | space ;
alias digitsPerGroup = fixedNumOfDigits ;
alias localeDependent = ’:’ ;
alias apostrophe = "" ;
alias space = ’_’ ;
WRITE #("Q", char); (*’$’*)   WRITE #("QQ", char); (*"$"*)   WRITE #("0u8’2", char); (*0u00’00’00’24*)

Format Specifier Syntax for Type OCTET

octetFmt := decimalOctet | octetBase16 | base2 ;
decimalOctet := leadSpace? compact | leadZeroes ;
alias leadSpace = ’_’ ;
alias leadZeroes = ’Z’ ;
alias compact = ’*’ ;
octetBase16 := ’0x’ | ’X’ ;
base2 := ( ’0b’ | ’B’ ) digitFmt ;
WRITE #("0x", n); (*0x2A*)   WRITE #("Z", n); (*042*)   WRITE #("0b8’4", n); (*0b0010’1010*)

Format Specifier Syntax for Cardinal Types

cardinalFmt := decimalCardinal | base16 | base2 ;
decimalCardinal := leadZeroes? ( digitFmt justification? )? ;
alias leadZeroes = ’Z’;
digitFmt := intDigits digitGrouping? ;
alias intDigits, digitsPerGroup = digitCount ;
digitCount := Digit+ ;
digitGrouping := digitSep digitsPerGroup ;
digitSep := ’:’ | ’_’ | "" ;
justification := ’|’ position ’|’ ;
position := ’<’ | ’>’ ;
base16 := ( ’0x’ | ’X’ ) digitFmt ;
base2 := ( ’0b’ | ’B’ ) digitFmt ;

Format Specifier Syntax for Integer Types

integerFmt := sign? decimalCardinal | base16 | base2 ;
sign := ’+’ | ’-’ ;
WRITE #("0x", i); (*0x2A*)   WRITE #("Z", i); (*042*)   WRITE #("0b8’4", i); (*0b0010’1010*)

Format Specifier Syntax for Real Number Types

realFmt := engOrSciFmt | acctFmt ;
engOrSciFmt := ( ’E’ )? sign? significand exponent? justification? ;
sign := ’+’ | ’-’ ;
significand := intDigits digitGrouping? ’;’ fracDigits digitGrouping? ;
digitGrouping := ’:’ digitsPerGroup ;
exponent := ’e’ sign? expDigits digitGrouping? ;
alias intDigits, fracDigits, expDigits, digitsPerGroup = digitCount ;
digitCount := Digit+ ;
acctFmt := ’A’ ( standard | ledger ) ;
standard := ( sign spacer? | spacer sign ) significand ;
alias spacer = ’_’ ;
ledger := filler? significand acctSign ;
filler := ’*’ | ’=’ ;
acctSign := ’CR’ | ’()’ ;
WRITE #("E-2;9e3", r); (* 12.345,678,900e006*)   WRITE #("A7:3;2_CR", r); (*1,234,567.89 CR*)

Format Specifier Syntax for Character Arrays

strFmt := quoted? glyphs ;
quoted := ’Q’ | ’QQ’ ;
glyphs = ’A’ | ’UTF8’ ;

Format Specifier Syntax for Non-Character Arrays

arrayFmt := ’{’ itemSep ’}’ ( ’|’ valueFmt )? ;
itemSep := ( ’,’ | ’;’ )? ’_’ ;
valueFmt := boolFmt | octetFmt | cardinalFmt | integerFmt | realFmt ;
Clone this wiki locally