I'm trying to dynamically evalutate Erlang terms
Start up Erlang
basho-catah% erl
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.4 (abort with ^G)
Create a term
1> {a,[b,c,d]}.
{a,[b,c,d]}
Try to scan in the same term
2> {ok, Tokens, _ } = erl_scan:string("{a,[b,c,d]}").
{ok,[{'{',1},
{atom,1,a},
{',',1},
{'[',1},
{atom,1,b},
{',',1},
{atom,1,c},
{',',1},
{atom,1,d},
{']',1},
{'}',1}],
1}
3> Tokens.
[{'{',1},
{atom,1,a},
{',',1},
{'[',1},
{atom,1,b},
{',',1},
{atom,1,c},
{',',1},
{atom,1,d},
{']',1},
{'}',1}]
But it can't parse that tokenized string.
4> Foo = erl_parse:parse(Tokens).
{error,{1,erl_parse,["syntax error before: ","'{'"]}}
Any ideas what I'm doing wrong?
erl_parse:parse/1
is the generic parse function genereated byyecc
(used to build the parser) which parses exactly what the grammar dictates. Normally you call some defined wrapper functions likeerl_parse:parse_term/1
. – Layamon