-
-
Save rightfold/ab3e534287ed33fcd9ca 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
-- in Haskell, you can do this: | |
data T = | |
A | |
| B | |
-- or this: | |
data T | |
= A | |
| B | |
-- but not this: | |
data T = | |
| A -- note leading "|" | |
| B | |
-- which makes sorting/diffs/merging a nightmare | |
-- this preprocessor fixes that. just invoke the Haskell | |
-- compiler with "-F -pgmF ./preprocessor.pl" |
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; | |
shift @ARGV; | |
open my $in, '<', shift(@ARGV); | |
open my $out, '>', shift(@ARGV); | |
my $data_decl_start = 0; | |
while (<$in>) { | |
if ($data_decl_start) { | |
s/^\s+\|//; | |
$data_decl_start = 0; | |
} elsif (/^data .*?=$/) { | |
$data_decl_start = 1; | |
} | |
print $out $_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment