1 package TOML::Tiny::Grammar;
2 # ABSTRACT: exports regex definitions used to parse TOML source
26 $MultiLineStringLiteral
44 our $WS = qr/[\x20\x09]/; # space, tab
45 our $CRLF = qr/\x0D?\x0A/; # cr? lf
46 our $Comment = qr/\x23.*/; # #comment
47 our $EOL = qr/$Comment?$CRLF/; # crlf or comment + crlf
52 [\x5C"btnfr] # escapes: \\ \" \b \t \n \f \r
53 | (?> u [_0-9a-fA-F]{4}) # unicode (4 bytes)
54 | (?> U [_0-9a-fA-F]{8}) # unicode (8 bytes)
58 our $StringLiteral = qr/'[^']*'/; # single quoted string (no escaped chars allowed)
60 our $MultiLineStringLiteral = qr{
61 ''' # opening triple-quote
63 ''' # closing triple-quote
66 our $BasicString = qr{
68 (?> # escape sequences or any char except " or \
75 our $MultiLineString = qr{
76 """ # opening triple-quote
79 | "{1,2} # 1-2 quotation marks
81 | (?: \\ $CRLF) # backslash-terminated line
83 """ # closing triple-quote
86 our $String = qr/$MultiLineString | $BasicString | $MultiLineStringLiteral | $StringLiteral/x;
88 our $BareKey = qr/[-_a-zA-Z0-9]+/;
89 our $QuotedKey = qr/$BasicString|$StringLiteral/;
90 our $SimpleKey = qr/$BareKey|$QuotedKey/;
91 our $DottedKey = qr/$SimpleKey(?:\.$SimpleKey)+/;
92 our $Key = qr/$BareKey|$QuotedKey|$DottedKey/;
94 our $Boolean = qr/\b(?:true)|(?:false)\b/;
96 #-----------------------------------------------------------------------------
98 # 1985-04-12T23:20:50.52Z
99 #-----------------------------------------------------------------------------
100 our $Date = qr/\d{4}-\d{2}-\d{2}/;
101 our $Offset = qr/(?: [-+] \d{2}:\d{2} ) | Z/x;
102 our $Time = qr/\d{2}:\d{2}:\d{2} (?: \. \d+)? $Offset?/x;
103 our $DateTime = qr/(?> $Date (?> [T ] $Time )?) | $Time/x;
105 #-----------------------------------------------------------------------------
107 #-----------------------------------------------------------------------------
108 our $DecFirstChar = qr/[1-9]/;
109 our $DecChar = qr/[0-9]/;
110 our $HexChar = qr/[0-9 a-f A-F]/;
111 our $OctChar = qr/[0-7]/;
112 our $BinChar = qr/[01]/;
114 our $Zero = qr/[-+]? 0/x;
115 our $Hex = qr/0x $HexChar (?> _? $HexChar )*/x;
116 our $Oct = qr/0o $OctChar (?> _? $OctChar )*/x;
117 our $Bin = qr/0b $BinChar (?> _? $BinChar )*/x;
118 our $Dec = qr/$Zero | (?> [-+]? $DecFirstChar (?> _? $DecChar )* )/x;
119 our $Integer = qr/$Hex | $Oct | $Bin | $Dec/x;
121 #-----------------------------------------------------------------------------
123 #-----------------------------------------------------------------------------
124 our $Exponent = qr/[eE] $Dec/x;
125 our $SpecialFloat = qr/[-+]? (?:inf) | (?:nan)/x;
126 our $Fraction = qr/\. $DecChar (?> _? $DecChar)*/x;
129 (?> $Dec (?> (?> $Fraction $Exponent?) | $Exponent ) )
138 use TOML::Tiny::Grammar;
140 if ($src =~ /$MultiLineString/) {
146 Exports various regexex for parsing TOML source.
150 =head2 White space and ignorables
178 =head3 $StringLiteral
180 =head3 $MultiLineStringLiteral
184 =head3 $MultiLineString