Commit 62561ad2 authored by Andrew Mayorov's avatar Andrew Mayorov

Add bpr script for printing Erlang unicode strings

parent dfb74cec
#!/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.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment