Skip to content

Instantly share code, notes, and snippets.

@skaji
Created July 28, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaji/15751daa1931f5b6240f9b46020a577f to your computer and use it in GitHub Desktop.
Save skaji/15751daa1931f5b6240f9b46020a577f to your computer and use it in GitHub Desktop.
#!/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