KV : SP* K SP* ':' SP* V SP*
M1 : KV (',' KV)* ','? SP*
M2 : SP* '{' M1 '}' SP*
M3 : SP*
M : M2 | M1 | M3
K1 = V1 : [^{}:"\s]+
K2 = V2 : '"' [^"]+ '"'
K3 = V3 : '"""' .*? '"""'
K4 = V4 : '<<' D \s .*? D
V5 : M2
K : K1 | K2 | K3 | K4
V : V1 | V2 | V3 | V4 | V5
The parser will emit events for KV.
Usage:
kv INPUT <<EOF
A
B B1
C C1 C2
EOF
Will output concatenated values of INPUT for keys A, B.B1 and C.C1.C2.
kv -quote < INPUT
Will quote INPUT according to (K1 | K2 | K3 | K4) whichever is best.
The reference implementation of kv is implemented in ANSI C.