-
-
Save keynslug/8c98ae28fedcc45b7e86 to your computer and use it in GitHub Desktop.
bpr
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
| #!/usr/bin/env escript | |
| %% | |
| %%! -noshell +pc unicode | |
| main([BinTerm]) -> | |
| [Bin] = consult(BinTerm ++ "."), | |
| io:setopts(user, [{encoding, unicode}]), | |
| io:format(user, "~ts~n", [Bin]), | |
| erlang:halt(); | |
| main(_) -> | |
| io:format( | |
| "Print Erlang binaries in human consumable representation. For Christ sake.~n" | |
| "~n" | |
| "Usage: bpr \"<<...>>\"~n" | |
| ). | |
| consult(Str) when is_list(Str) -> | |
| consult([], Str, []); | |
| consult(Bin) when is_binary(Bin)-> | |
| consult([], binary_to_list(Bin), []). | |
| consult(Cont, Str, Acc) -> | |
| case erl_scan:tokens(Cont, Str, 0) of | |
| {done, Result, Remaining} -> | |
| case Result of | |
| {ok, Tokens, _} -> | |
| {ok, Term} = erl_parse:parse_term(Tokens), | |
| consult([], Remaining, [Term | Acc]); | |
| {eof, _Other} -> | |
| lists:reverse(Acc); | |
| {error, Info, _} -> | |
| {error, Info} | |
| end; | |
| {more, Cont1} -> | |
| consult(Cont1, eof, Acc) | |
| end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment