-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprintf.peg
41 lines (34 loc) · 802 Bytes
/
printf.peg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
PrintfFormat
= tokens:PrintfFormatToken* {
return tokens;
}
PrintfFormatToken
= PrintfFormatSpecifier / PrintfFormatLiteral
PrintfFormatSpecifier
= "%"
flags: [-+ #0]*
width: FormatInteger?
prec:("." FormatInteger?)?
length:FormatLengthModifier
value:PrintfConversionSpecifier
{
const precision = prec ? (prec[1] ?? '.') : null;
return {typ: "%", flags, width, precision, length, value};
}
FormatInteger
= "*" / FormatDecimalInteger
FormatDecimalInteger
= ("0" / [1-9][0-9]*) {
return Number(text());
}
FormatLengthModifier
= "hh" / "h" / "ll" / "l" / "j" / "z" / "t" / "L" / ""
PrintfFormatLiteral
= [^\"%]+ {
return {
typ: "literal",
value: text()
};
}
PrintfConversionSpecifier
= [%csdioxXufFeEaAgGnp]