From: Jeff Ober Date: Sun, 22 Dec 2019 20:11:15 +0000 (-0500) Subject: Initial commit X-Git-Tag: nailing-cargo/1.0.0~234^2~69 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0e4078d2e45c2be7bcc82113149aef814f12e5c6;p=nailing-cargo.git Initial commit --- 0e4078d2e45c2be7bcc82113149aef814f12e5c6 diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..7fc1e16 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,21 @@ +skip_tags: true + +build: off + +cache: + - C:\strawberry + +platform: + - x86 + - x64 + +install: + - if not exist "C:\strawberry" cinst strawberryperl + - set PATH=C:\strawberry\perl\bin;C:\strawberry\perl\site\bin;C:\strawberry\c\bin;%PATH% + - cd C:\projects\%APPVEYOR_PROJECT_NAME% + - cpanm -n Dist::Zilla + - dzil authordeps --missing | cpanm -nq + - dzil listdeps --missing | cpanm -nq + +test_script: + - dzil test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f5bacd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.build +scratch.pl diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2fe7c27 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: perl + +sudo: false + +notifications: + email: false + +cache: + directories: + - ~/perl5 + +perl: + - "5.30" + - "5.28" + - "5.26" + - "5.24" + - "5.22" + - "5.20" + - "5.18" + - "5.16" + - "5.14" + - "5.12" + - "5.10" + +before_install: + - eval $(curl https://travis-perl.github.io/init) --auto --always-upgrade-modules diff --git a/Changes b/Changes new file mode 100644 index 0000000..aec11e9 --- /dev/null +++ b/Changes @@ -0,0 +1,2 @@ +{{$NEXT}} +-Initial release diff --git a/README.pod b/README.pod new file mode 100644 index 0000000..d09e5ea --- /dev/null +++ b/README.pod @@ -0,0 +1,24 @@ +=pod + +=encoding UTF-8 + +=head1 NAME + +TOML::Tiny - a minimal TOML parser and serializer + +=head1 VERSION + +version 0.01 + +=head1 AUTHOR + +Jeff Ober + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2020 by Jeff Ober. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b7cd55f --- /dev/null +++ b/TODO.md @@ -0,0 +1,4 @@ +* Serialization +* Line numbers +* Optimization +* More complete unit tests diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..7ec73c8 --- /dev/null +++ b/cpanfile @@ -0,0 +1,9 @@ +requires 'perl' => '>= 5.014'; +requires 'JSON::PP' => '0'; + +recommends 'Types::Serialiser' => 0; + +on test => sub{ + requires 'Test::Pod' => '0'; + requires 'Test2::V0' => '0'; +}; diff --git a/dist.ini b/dist.ini new file mode 100644 index 0000000..b62f9d6 --- /dev/null +++ b/dist.ini @@ -0,0 +1,7 @@ +name = TOML-Tiny +author = Jeff Ober +license = Perl_5 +copyright_holder = Jeff Ober + +[@Author::BLUEFEET] +[PodWeaver] diff --git a/lib/TOML/Tiny.pm b/lib/TOML/Tiny.pm new file mode 100644 index 0000000..32627fc --- /dev/null +++ b/lib/TOML/Tiny.pm @@ -0,0 +1,11 @@ +package TOML::Tiny; +# ABSTRACT: a minimal TOML parser and serializer + +use strict; +use warnings; + +use TOML::Tiny::Grammar; + +our $GRAMMAR_V5 = $TOML::Tiny::Grammar::GRAMMAR_V5; + +1; diff --git a/lib/TOML/Tiny/Grammar.pm b/lib/TOML/Tiny/Grammar.pm new file mode 100644 index 0000000..fc9c1cb --- /dev/null +++ b/lib/TOML/Tiny/Grammar.pm @@ -0,0 +1,248 @@ +package TOML::Tiny::Grammar; + +use strict; +use warnings; + +our $GRAMMAR_V5 = qr{ + +(?(DEFINE) + #----------------------------------------------------------------------------- + # Misc + #----------------------------------------------------------------------------- + (? + (?&Boolean) + | (?&DateTime) + | (?&Float) + | (?&Integer) + | (?&String) + | (?&Array) + | (?&InlineTable) + ) + + (? (?: \x0A) | (?: \x0D \x0A)) + (? (?&NLSeq) | (?&Comment)) + + (? [ \x20 \x09 ]) # (space, tab) + (? (?&WSChar)*) + + (? \x23 .* (?&NLSeq)) + + #----------------------------------------------------------------------------- + # Array of tables + #----------------------------------------------------------------------------- + (? + (?m) + (?s) + + \[\[ (?&Key) \]\] \n + (?: + (?: (?&KeyValuePair) \n ) + | (?&ArrayOfTables) + | (?&Table) + )* + + (?-s) + (?-m) + ) + + #----------------------------------------------------------------------------- + # Table + #----------------------------------------------------------------------------- + (? (?&Key) (?&WS) = (?&WS) (?&Value)) + (? (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&NL)) + + (? + (?&WS) + [,] + (?&WS) + (?&NLSeq)? + (?&WS) + ) + + (? + (?&KeyValuePair) (?&InlineTableSep) (?&KeyValuePairList)? + | (?&KeyValuePair) + ) + + (? + (?s) + + { + (?&WS) (?&NLSeq)? (?&WS) + + (?&KeyValuePairList) + + (?&WS) (?&NLSeq)? (?&WS) + } + + (?-s) + ) + + (? + \[ (?&Key) \] \n + ) + + (? + (?&TableDecl) + (?: + (?&KeyValuePairDecl) + | (?&ArrayOfTables) + )* + ) + + #----------------------------------------------------------------------------- + # Array + #----------------------------------------------------------------------------- + (? + (?&WS) + [,] + (?&WS) + (?&NLSeq)? + (?&WS) + ) + + (? + (?&Value) (?&ListSep) (?&List)? + | (?&Value) + ) + + (? + \[ + + (?&WS) (?&NLSeq)? (?&WS) + + (?&List) + + (?&WS) (?&NLSeq)? (?&WS) + + \] + ) + + #----------------------------------------------------------------------------- + # Key + #----------------------------------------------------------------------------- + (? [-_a-zA-Z0-9]+) + (? (?&BasicString) | (?&StringLiteral)) + (? + (?: (?&BareKey) | (?&QuotedKey) ) + (?: (?&WS) [.] (?&WS) (?: (?&BareKey) | (?&QuotedKey) ) )+ + ) + (? (?&DottedKey) | (?&BareKey) | (?&QuotedKey) ) + + #----------------------------------------------------------------------------- + # Boolean + #----------------------------------------------------------------------------- + (? \b(?:true)|(?:false))\b + + #----------------------------------------------------------------------------- + # Integer + #----------------------------------------------------------------------------- + (? [-+]? [_0-9]+) + (? 0x[_0-9a-fA-F]+) + (? 0o[_0-7]+) + (? 0b[_01]+) + (? (?&Hex) | (?&Oct) | (?&Bin) | (?&Dec)) + + #----------------------------------------------------------------------------- + # Float + #----------------------------------------------------------------------------- + (? [eE] (?&Dec)) + (? [-+]? (?:inf) | (?:nan)) + (? [.] [_0-9]+) + + (? + (?: + (?: (?&Dec) (?&Fraction) (?&Exponent) ) + | (?: (?&Dec) (?&Exponent) ) + | (?: (?&Dec) (?&Fraction) ) + ) + | + (?&SpecialFloat) + ) + + #----------------------------------------------------------------------------- + # String + #----------------------------------------------------------------------------- + (? + \\ # leading \ + (?: + [\\/"btnfr] # escapes: \\ \/ \b \t \n \f \r + | (?: u \d{4} ) # unicode (4 bytes) + | (?: U \d{8} ) # unicode (8 bytes) + ) + ) + + (? + (?: ' ([^']*) ') # single quoted string (no escaped chars allowed) + ) + + (? + (?m) + (?s) + ''' # opening triple-quote + (.)*? # capture + ''' # closing triple-quote + (?-s) + (?-m) + ) + + (? + (?: + " # opening quote + (?: # capture escape sequences or any char except " or \ + (?: (?&EscapeChar) ) + | [^"\\] + )* + " # closing quote + ) + ) + + (? + (?s) + """ # opening triple-quote + ( # capture: + (?: (?&EscapeChar) ) # escaped char + | . + )*? + """ # closing triple-quote + (?-s) + ) + + (? + (?&MultiLineString) + | (?&BasicString) + | (?&MultiLineStringLiteral) + | (?&StringLiteral) + ) + + #----------------------------------------------------------------------------- + # Dates (RFC 3339) + # 1985-04-12T23:20:50.52Z + #----------------------------------------------------------------------------- + (? \d{4}-\d{2}-\d{2}) + + (? + (?: [-+] \d{2}:\d{2} ) + | [Z] + ) + + (? + \d{2}:\d{2}:\d{2} + (?: [.] \d+ )? + ) + + (?