[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\")"}.

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\")\"}.").
3> erl_parse:parse_term(Tokens).
{error,{1,erl_parse,["syntax error before: ","hi"]}}

So what is the proper way to escape strings in this context ?

Roberto Saccon

More information about the erlang-questions mailing list