Created
July 28, 2019 15:54
-
-
Save skaji/15751daa1931f5b6240f9b46020a577f to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub comment_for { | |
my $line = shift; | |
if ($line =~ /^ (type|func|var) \s+ (\(.*?\))? \s* ([A-Z]\w+) /x) { | |
my ($kind, $is_method, $name) = ($1, $2, $3); | |
if ($is_method && grep { $name ne $_ } qw(String Error)) { | |
# skip | |
return; | |
} else { | |
return "// $name is\n"; | |
} | |
} | |
if ($line =~ /^var\s+\(\n/) { | |
return "// constants\n"; | |
} | |
return; | |
} | |
my @out; | |
while (<>) { | |
my $comment = comment_for $_; | |
if (!$comment) { | |
push @out, $_; | |
next; | |
} | |
pop @out if $out[-1] =~ m{^//}; | |
push @out, $comment, $_; | |
} | |
print for @out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment