Opposite of flatten

Torbjorn Tornkvist tobbe@REDACTED
Wed Sep 26 11:29:44 CEST 2001


Does this program do what you want to do ?

Cheers /Tobbe
================= str2tokens.erl ================================
-module(str2tokens).
-compile(export_all).

%% 2> str2tokens:str2terms("{hello,23}. [arne,43]. 5.6. {5.5,1.0}. ").
%% [{hello,23},[arne,43],5.60000,{5.50000,1.00000}]

str2tokenlists("") ->
    [];
str2tokenlists(String) ->
    case erl_scan:tokens([], String, 1) of
	{done, {ok, Tokens, _}, Rest} ->
	    [Tokens | str2tokenlists(Rest)]
    end.

tokenlists2terms(Lists) ->
    lists:map(fun(L) ->
		      {ok, Term} = erl_parse:parse_term(L),
		      Term
	      end,
	      Lists).

str2terms(String) ->
    tokenlists2terms(str2tokenlists(String)).

================================================================



More information about the erlang-questions mailing list