Skip to content

Instantly share code, notes, and snippets.

@zaydek-owl
Last active August 21, 2017 21:36
Show Gist options
  • Save zaydek-owl/28823563ac2ec50ab4f794c34a0911d0 to your computer and use it in GitHub Desktop.
Save zaydek-owl/28823563ac2ec50ab4f794c34a0911d0 to your computer and use it in GitHub Desktop.
import std.file, std.regex, std.stdio;
void main(string[] args)
{
if (args.length != 2)
return;
auto text = readText(args[1]);
enum common = `((?:func|for|if|else)[^{\n]*)\n`;
text = replaceAll(text, ctRegex!(common ~ `\t*\{` ), "$1 {\n" );
text = replaceAll(text, ctRegex!(common ~ `([^\n]+)\n` ), "$1 {\n$2 }\n");
text = replaceAll(text, ctRegex!( `\}(\s+)else`), "$1} else" );
write(text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment