Created
July 15, 2015 15:13
-
-
Save IgnoredAmbience/2920715b88f408d85f4e to your computer and use it in GitHub Desktop.
oh noes! perl!
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/perl -p | |
# Converts ml char-array constructions into strings | |
# eg: ('a'::('b'::('c'::[]))) => "abc" | |
# | |
# Makes use of all the horrific Perl regular expression features I could find: | |
# (?R) is the recursive subexpression pattern -- it recursively reuses the entire pattern as a sub-pattern. | |
# However, this doesn't support retrieving the nested pattern captures, so we use | |
# (?{ }) to execute the Perl expression $^R.($^N =~ s{^"}{\\"}r) which concatenates the last captured group (with " | |
# substituted for \") onto the result of the previous execution of this expression. | |
# $^R isn't cleared between regular expression matches, so we do this manually. | |
# The -p operator to Perl wraps this script in a foreach loop that operates over a given file. | |
$^R = ""; | |
s/'([^']|\\(?:\\|"|'|n|r|t|b| |\d{3}|x[0-9a-fA-F]{2}))(?{ $^R.($^N =~ s{^"}{\\"}r) })'::(?:\((?R)\)|\[\])/"$^R"/; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment