#-----------------------------------------------------------------------------
# Misc
#-----------------------------------------------------------------------------
- (?<Value>
- (?&Boolean)
- | (?&DateTime)
- | (?&Float)
- | (?&Integer)
- | (?&String)
- | (?&Array)
- | (?&InlineTable)
- )
-
(?<WS> [ \x20 \x09 ]*) # space, tab
(?<CRLF> \x0D? \x0A) # cr? lf
(?<EOL> (?: \x23 .*)? (?&CRLF)) # crlf or comment -> crlf
- #-----------------------------------------------------------------------------
- # Array of tables
- #-----------------------------------------------------------------------------
- (?<ArrayOfTables>
- (?m)
- (?s)
-
- \[\[ (?&Key) \]\] (?&EOL)
-
- (?:
- (?: (?&KeyValuePair) (?=(?&CRLF)) )
- | (?&ArrayOfTables)
- | (?&Table)
- )*
-
- (?-s)
- (?-m)
- )
-
- #-----------------------------------------------------------------------------
- # Table
- #-----------------------------------------------------------------------------
- (?<KeyValuePair> (?&Key) (?&WS) = (?&WS) (?&Value))
- (?<KeyValuePairDecl> (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&EOL))
-
- (?<KeyValuePairList>
- (?&KeyValuePair) (?&WS) (?: [,] (?&WS) (?&KeyValuePairList) )?
- | (?&KeyValuePair)
- )
-
- (?<InlineTable>
- {
- (?&WS)
- (?&KeyValuePairList)
- (?&WS)
- }
- )
-
- (?<TableDecl> \[ (?&Key) \] (?&EOL))
-
- (?<Table>
- (?&TableDecl)
- (?:
- (?&KeyValuePairDecl)
- | (?&ArrayOfTables)
- )*
- )
-
- #-----------------------------------------------------------------------------
- # Array
- #-----------------------------------------------------------------------------
- (?<ListSep>
- (?&WS)
- [,]
- (?&WS)
- (?&CRLF)?
- (?&WS)
- )
-
- (?<List>
- (?&Value) (?&ListSep) (?&List)?
- | (?&Value)
- )
-
- (?<Array>
- \[
-
- (?&WS) (?&CRLF)? (?&WS)
-
- (?&List)
-
- (?&WS) (?&CRLF)? (?&WS)
-
- \]
- )
-
#-----------------------------------------------------------------------------
# Key
#-----------------------------------------------------------------------------
+++ /dev/null
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Array)) $TOML }x;
-
-my @valid = (
- q{[ 1, 2, 3 ]},
- q{[ "red", "yellow", "green" ]},
- q{[ [ 1, 2 ], [3, 4, 5] ]},
- q{[ [ 1, 2 ], ["a", "b", "c"] ]},
- q{[ "all", 'strings', """are the same""", '''type''' ]},
- q{[ 0.1, 0.2, 0.5, 1, 2, 5 ]},
- q{[ "Foo Bar <foo@example.com>", { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" } ]},
- q{[ 1, 2, 3 ]},
- q{[ 1, 2, ]},
- q{[
- 1,
- 2,
- ]},
- q{[
- 1,
- 2
- ]},
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
+++ /dev/null
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-sub test_simple_matches {
- my ($re, @tests) = @_;
- for (@tests) {
- my ($toml, $expected, $label) = @$_;
- my ($match) = $toml =~ $re;
- is $match, $expected, $label;
- }
-}
-
-subtest 'string group' => sub{
- my $re = qr{ ((?&String)) $TOML }x;
-
- test_simple_matches($re,
- [q{"A"}, q{"A"}, 'basic string'],
- [q{'A'}, q{'A'}, 'string literal'],
- [q{"""A"""}, q{"""A"""}, 'multi-line string'],
- [q{'''A'''}, q{'''A'''}, 'multi-line string literal'],
- );
-};
-
-subtest 'escaped characters' => sub{
- my $re = qr{
- ((?&EscapeChar))
- $TOML
- }x;
-
- test_simple_matches($re,
- ['\\\\', '\\\\', 'slash'],
- ['\\b', '\\b', 'backspace'],
- ['\\t', '\\t', 'tab'],
- ['\\n', '\\n', 'line feed'],
- ['\\f', '\\f', 'form feed'],
- ['\\r', '\\r', 'carriage return'],
- ['\\"', '\\"', 'quote'],
- ['\\\\', '\\\\', 'backslash'],
- ['\\u1234', '\\u1234', 'unicode (4 bytes)'],
- ['\\U12345678', '\\U12345678', 'unicode (8 bytes)'],
- ['\\x', undef, 'invalid'],
- );
-};
-
-subtest 'string literals' => sub{
- my $re = qr{
- ((?&StringLiteral))
- $TOML
- }x;
-
- test_simple_matches($re,
- [q{'abc'}, q{'abc'}, 'single-quoted'],
- [q{''}, q{''}, 'empty single-quoted'],
- );
-};
-
-subtest 'basic strings' => sub{
- my $re = qr{
- ((?&BasicString))
- $TOML
- }x;
-
- test_simple_matches($re,
- ['""', '""', "empty string"],
- ['"abc"', '"abc"', 'simple'],
- ['"\\tfoo"', '"\\tfoo"', 'escaped chars'],
- ['1234', undef, 'invalid'],
- );
-};
-
-subtest 'multi-line strings' => sub{
- my $re = qr{
- ((?&MultiLineString))
- $TOML
- }x;
-
- test_simple_matches($re,
- [ qq{"""\nabc"""}, qq{"""\nabc"""}, 'simple' ],
- [ qq{""" " """}, q{""" " """}, 'containing 1 quote' ],
- [ qq{""" "" """}, q{""" "" """}, 'containing 2 quotes' ],
- [ qq{"""a\n"b"\nc"""}, qq{"""a\n"b"\nc"""}, 'individual quotes within ml string' ],
- [ qq{"""foo"""bar"""}, qq{"""foo"""}, 'invalid: triple-quotes appear within ml string' ],
- );
-};
-
-subtest 'multi-line string literals' => sub{
- my $re = qr{ ((?&MultiLineStringLiteral)) $TOML }x;
-
- test_simple_matches($re,
- [ qq{'''\nabc'''}, qq{'''\nabc'''}, 'simple' ],
- [ qq{''' ' '''}, q{''' ' '''}, 'containing 1 single tick' ],
- [ qq{''' '' '''}, q{''' '' '''}, 'containing 2 single ticks' ],
- [ qq{'''foo'''bar'''}, qq{'''foo'''}, 'invalid: triple-quotes appear within ml string' ],
- );
-};
-
-done_testing;