[erlang-questions] clarify: escaping strings in erl_scan:string / erl_parse:parse_term
Roberto Saccon
rsaccon@REDACTED
Fri Dec 28 14:26:33 CET 2007
How do I escape strings in Erlang before tokenizing / parsing with
erl_scan:string/1 and erl_parse:parse_term/1 ?
E.g. in the interactive Erlang shell I simply do:
1> {a_string, "foo(\"hi\")"}.
{a_string,"foo(\"hi\")"}
But if I try to do the same with erl_scan:string and
erl_parse:parse_term, it is tokenizing not as expected and parsing
gives an error:
2> {ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\"hi\")\"}.").
{ok,[{'{',1},
{atom,1,a_string},
{',',1},
{string,1,"foo("},
{atom,1,hi},
{string,1,")"},
{'}',1},
{dot,1}],
1}
3> erl_parse:parse_term(Tokens).
{error,{1,erl_parse,["syntax error before: ","hi"]}}
4>
So what is the proper way to escape strings in this context ?
--
Roberto Saccon
http://rsaccon.com
More information about the erlang-questions
mailing list