Created
July 13, 2017 22:10
-
-
Save anonymous/aa6fee7afcca717e8846f947bdf001cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| my $input = do {local $/; <STDIN>}; | |
| my $ind = ' '; | |
| my $indent = 0; | |
| my $output = ''; | |
| while ($input =~ s/\A \s* ( (?: \[\] | . )*? ) ( \( | \[ | \) | \],? | ,\ ) //x) { | |
| my ($str, $end) = ($1, $2); | |
| if ($end =~ /^[\(\[]/) { | |
| $output .= $ind x $indent++ . "$str$end\n"; | |
| } elsif ($end =~ /^[\)\]]/) { | |
| $output .= $ind x $indent . "$str\n"; | |
| $output .= $ind x --$indent . "$end\n"; | |
| } else { | |
| $output .= $ind x $indent . "$str\n"; | |
| } | |
| } | |
| $output =~ s/\s*\n/\n/g; | |
| $output =~ s/\[\s+\]/[]/g; | |
| # Collapse trailing brackets | |
| if ($ARGV[0] eq '-c') { | |
| $output =~ s/\s+([\)\]])/$1/g; | |
| $output =~ s/(\[\])/[] /g; | |
| } | |
| print $output; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Document.new(meta => [MetaPair.new(key => spec, value => schematype.org/v0.0.1) MetaPair.new(key => date, value => 2017-07-13T21:22:14Z) MetaPair.new(key => desc, value => A test schema)], type => [TypePair.new(key => color, value => $Schema.new(meta => [], pair => [HashPair.new(key => len, value => $Type.new(meta => [MetaPair.new(key => type, value => $TypeRef.new(ref => int, mods => []))], type => []), mods => [])], type => [TypePair.new(key => stem, value => $Schema.new(meta => [], pair => [HashPair.new(key => len, value => $Type.new(meta => [MetaPair.new(key => type, value => $TypeRef.new(ref => int, mods => []))], type => []), mods => [])], type => [])) TypePair.new(key => color, value => $Type.new(meta => [MetaPair.new(key => type, value => $TypeRef.new(ref => str, mods => [])) MetaPair.new(key => enum, value => $[red green])], type => []))]))], from => [MetaPair.new(key => from, value => github:schematype)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Document.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => spec | |
| value => schematype.org/v0.0.1) | |
| MetaPair.new( | |
| key => date | |
| value => 2017-07-13T21:22:14Z) | |
| MetaPair.new( | |
| key => desc | |
| value => A test schema)], | |
| type => [ | |
| TypePair.new( | |
| key => color | |
| value => $Schema.new( | |
| meta => [] , | |
| pair => [ | |
| HashPair.new( | |
| key => len | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => int | |
| mods => [] ))], | |
| type => [] ) | |
| mods => [] )], | |
| type => [ | |
| TypePair.new( | |
| key => stem | |
| value => $Schema.new( | |
| meta => [] , | |
| pair => [ | |
| HashPair.new( | |
| key => len | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => int | |
| mods => [] ))], | |
| type => [] ) | |
| mods => [] )], | |
| type => [] )) | |
| TypePair.new( | |
| key => color | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => str | |
| mods => [] )) | |
| MetaPair.new( | |
| key => enum | |
| value => $[ | |
| red green])], | |
| type => [] ))]))], | |
| from => [ | |
| MetaPair.new( | |
| key => from | |
| value => github:schematype)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Document.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => spec | |
| value => schematype.org/v0.0.1 | |
| ) | |
| MetaPair.new( | |
| key => date | |
| value => 2017-07-13T21:22:14Z | |
| ) | |
| MetaPair.new( | |
| key => desc | |
| value => A test schema | |
| ) | |
| ], | |
| type => [ | |
| TypePair.new( | |
| key => color | |
| value => $Schema.new( | |
| meta => [], | |
| pair => [ | |
| HashPair.new( | |
| key => len | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => int | |
| mods => [] | |
| ) | |
| ) | |
| ], | |
| type => [] | |
| ) | |
| mods => [] | |
| ) | |
| ], | |
| type => [ | |
| TypePair.new( | |
| key => stem | |
| value => $Schema.new( | |
| meta => [], | |
| pair => [ | |
| HashPair.new( | |
| key => len | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => int | |
| mods => [] | |
| ) | |
| ) | |
| ], | |
| type => [] | |
| ) | |
| mods => [] | |
| ) | |
| ], | |
| type => [] | |
| ) | |
| ) | |
| TypePair.new( | |
| key => color | |
| value => $Type.new( | |
| meta => [ | |
| MetaPair.new( | |
| key => type | |
| value => $TypeRef.new( | |
| ref => str | |
| mods => [] | |
| ) | |
| ) | |
| MetaPair.new( | |
| key => enum | |
| value => $[ | |
| red green | |
| ] | |
| ) | |
| ], | |
| type => [] | |
| ) | |
| ) | |
| ] | |
| ) | |
| ) | |
| ], | |
| from => [ | |
| MetaPair.new( | |
| key => from | |
| value => github:schematype | |
| ) | |
| ] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment