Skip to content

Instantly share code, notes, and snippets.

@voluntas
Created April 17, 2012 08:42
Show Gist options
  • Save voluntas/2404659 to your computer and use it in GitHub Desktop.
Save voluntas/2404659 to your computer and use it in GitHub Desktop.
nodetool
%%
%% Given a string or binary, parse it into a list of terms, ala file:consult/0
%%
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.
@voluntas
Copy link
Author

rel/files/nodetool にあるし ...

@shino
Copy link

shino commented Apr 17, 2012

なんとw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment