Last active
March 12, 2021 13:36
-
-
Save benkasminbullock/a55283a3b74aac94b8eedbf45e892260 to your computer and use it in GitHub Desktop.
Regex to match Perl package syntax
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
#!/home/ben/software/install/bin/perl | |
use warnings; | |
use strict; | |
use utf8; | |
use FindBin '$Bin'; | |
use Test::More; | |
my @stuff; | |
# package NAMESPACE | |
$stuff[0] =<<EOF; | |
package switch; | |
EOF | |
# package NAMESPACE VERSION | |
$stuff[1] =<<EOF; | |
package switch 0.001; | |
EOF | |
# package NAMESPACE BLOCK | |
$stuff[2] =<<EOF; | |
package switch | |
{ } | |
EOF | |
# package NAMESPACE VERSION BLOCK | |
$stuff[3] =<<EOF; | |
package switch 0.001 | |
{ } | |
EOF | |
my $gokeyw =<<EOF; | |
break default func interface select | |
case defer go map struct | |
chan else goto package switch | |
const fallthrough if range type | |
continue for import return var | |
EOF | |
my $re = qr!package\s+.*?\s*(;|\{)!; | |
for (@stuff) { | |
ok (m!$re!); | |
} | |
ok ($gokeyw !~ m!$re!); | |
done_testing (); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment