Created
September 19, 2021 16:02
-
-
Save UplinkCoder/2b20b2826fc66e397b44211e94e8e972 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import std.file; | |
| void main(string[] args) | |
| { | |
| // () @safe { assert(args.length == 2, "exactly one argument must be given") } (); | |
| auto text = cast(string) read(args[1]); | |
| long indent_level; | |
| long beginParenPos; | |
| bool inString = false; | |
| bool inStruct = false; | |
| bool inArray = false; | |
| char[] out_buffer; | |
| foreach(i,c;text) | |
| { | |
| auto p = i; | |
| if (c == '"') | |
| inString = !inString; | |
| if (!inString) | |
| { | |
| if (c == '(' || c == '[') | |
| { | |
| indent_level++; | |
| out_buffer ~= "\n"; | |
| foreach(_;0 .. indent_level) | |
| out_buffer ~= " "; | |
| } | |
| if (c == ')' || c == ']') | |
| { | |
| out_buffer ~= "\n"; | |
| foreach(_;0 .. indent_level) | |
| out_buffer ~= " "; | |
| indent_level--; | |
| } | |
| } | |
| out_buffer ~= c; | |
| /+ | |
| if (c == ',' && !inString) | |
| { | |
| out_buffer ~= "\n"; | |
| foreach(_;0 .. indent_level) | |
| out_buffer ~= " "; | |
| } | |
| +/ | |
| } | |
| (args[1] ~ ".tree").write(cast(void[])out_buffer);; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment