Preserves Quick Reference
Tony Garnock-Jones tonyg@leastfixedpoint.com
September 2024. Version 0.996.0.
These are non-normative “reference card” definitions. See also the normative semantics, text syntax specification, and machine-oriented syntax specification, and the experimental P-expressions definition.
Machine-Oriented Binary Syntax
For a value V, we write «V» for the binary encoding of V.
«#f » |
= | 80 |
«#t » |
= | 81 |
«@ W V» |
= | 85 «W» «V» |
«#: V» |
= | 86 «V» |
«V» | = | 87 08 binary64(V) |
if V ∈ Double |
«V» | = | B0 varint(|intbytes(V)|) intbytes(V) |
if V ∈ SignedInteger |
«V» | = | B1 varint(|utf8(V)|) utf8(V) |
if V ∈ String |
«V» | = | B2 varint(|V|) V |
if V ∈ ByteString |
«V» | = | B3 varint(|utf8(V)|) utf8(V) |
if V ∈ Symbol |
«< L F1 … Fm> » |
= | B4 «L» «F1» … «Fm» 84 |
«[ X1 … Xm] » |
= | B5 «X1» … «Xm» 84 |
«#{ E1 … Em} » |
= | B6 «E1» … «Em» 84 |
«{ K1: V1 … Km: Vm} » |
= | B7 «K1» «V1» … «Km» «Vm» 84 |
varint(n) | = | n | if n < 128 |
(n & 127) | 128 varint(n >> 7) | if n ≥ 128 |
intbytes(n) | = | the empty sequence if n = 0, otherwise signedBigEndian(n) |
signedBigEndian(n) | = | n & 255 | if −128 ≤ n ≤ 127 |
signedBigEndian(n >> 8) n & 255 | otherwise |
The function binary64(D) yields the big-endian 8-byte IEEE 754 binary representation of D.
Human-Oriented Text Syntax
Document | := | Value ws |
Value | := | ws (Record | Collection | Embedded | Annotated | Atom) |
Collection | := | Sequence | Dictionary | Set |
Record | := | < Value+ ws> |
Sequence | := | [ (commas Value)⋆ commas] |
Set | := | #{ (commas Value)⋆ commas} |
Dictionary | := | { (commas Value ws: Value)⋆ commas} |
commas | := | (ws , )⋆ ws |
Embedded | := | #: Value |
Annotated | := | Annotation Value |
Annotation | := | @ Value |# ((space | tab | ! ) linecomment) (cr | lf) |
Atom | := | Boolean | ByteString | String | QuotedSymbol | Symbol | Number |
Boolean | := | #t |#f |
ByteString | := | #" binchar⋆ " |#x" (ws hex hex)⋆ ws" |#[ (ws base64char)⋆ ws] |
String | := | " (« any unicode scalar value except \ or " » | escaped |\" )⋆ " |
QuotedSymbol | := | ' (« any unicode scalar value except \ or ' » | escaped |\' )⋆ ' |
Symbol | := | (A ..Z |a ..z |0 ..9 | sympunct | symuchar)+ |
Number | := | Double | SignedInteger |
Double | := | flt |#xd" (ws hex hex)8 ws" |
SignedInteger | := | int |
escaped | := | \\ |\/ |\b |\f |\n |\r |\t |\u hex hex hex hex |
binescaped | := | \\ |\/ |\b |\f |\n |\r |\t |\x hex hex |
binchar | := | « any unicode scalar value ≥32 and ≤126, except \ or " » | binescaped |\" |
base64char | := | A ..Z |a ..z |0 ..9 |+ |/ |- |_ |= |
sympunct | := | ~ |! |$ |% |^ |& |* |? |_ |= |+ |- |/ |. || |
symuchar | := | « any scalar value ≥128 whose Unicode category is Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pc, Pd, Po, Sc, Sm, Sk, So, or Co » |
flt | := | int ( frac exp | frac | exp ) |
int | := | (- |+ ) (0 ..9 )+ |
frac | := | . (0 ..9 )+ |
exp | := | (e |E ) (- |+ ) (0 ..9 )+ |
hex | := | A ..F |a ..f |0 ..9 |
ws | := | (space | tab | cr | lf)⋆ |
delimiter | := | ws | < | > | [ | ] | { | } | # | : | " | ' | @ | ; | , |
linecomment | := | « any unicode scalar value except cr or lf »⋆ |
P-expression Syntax
The definitions of Atom
, ws
, and linecomment
are as given in the Preserves text syntax.
Document | := | Expr⋆ Trailer ws |
Expr | := | ws (SimpleExpr | Punct) |
SimpleExpr | := | Compound | Embedded | Annotated | Atom |
Compound | := | Sequence | Record | Block | Group | Set |
Punct | := | , | ; | : + |
Sequence | := | [ Expr⋆ Trailer ws ] |
Record | := | < Expr⋆ Trailer ws > |
Block | := | { Expr⋆ Trailer ws } |
Group | := | ( Expr⋆ Trailer ws ) |
Set | := | #{ Expr⋆ Trailer ws } |
Trailer | := | (ws Annotation)⋆ |
Embedded | := | #: SimpleExpr |
Annotated | := | Annotation SimpleExpr |
Annotation | := | @ SimpleExpr | # ((space | tab | ! ) linecomment) (cr | lf) |