erl_scan:string ignores /' and /"
Raimo Niskanen
raimo.niskanen@REDACTED
Mon Aug 25 14:50:46 CEST 2003
Have you not simply forgotten the double parsing problem that everything
you type in is parsed (by erl_parse et.al) before erl_parse:string/1 is
called?
Try this:
%%% A
16> f(S),S="A",io:format("~w -> ",[S]),erl_scan:string(S).
[65] -> {ok,[{var,1,'A'}],1}
%%% "A"
17> f(S),S="\"A\"",io:format("~w -> ",[S]),erl_scan:string(S).
[34,65,34] -> {ok,[{string,1,"A"}],1}
%%% "\^A"
18> f(S),S="\"\\^A\"",io:format("~w",[S]),erl_scan:string(S).
[34,92,94,65,34]{ok,[{string,1,[1]}],1}
%%% "\^A\""
19> f(S),S="\"\\^A\\\"\"",io:format("~w -> ",[S]),erl_scan:string(S).
[34,92,94,65,92,34,34] -> {ok,[{string,1,[1,34]}],1}
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
Roger Price wrote:
> "Concurrent Programming in Erlang", chapter 2.1.2 says "Within a quoted
> atom the following conventions apply"... Chapter 2.1.4 says "Within a
> string the quoting conventions used within an atom also apply." However
> erl_scan:string/1 seems to ignore \' and \". Here are the results for all
> the conventions:
>
> 15> erl_scan:string("\b") .
> {ok,[],1}
> 16> erl_scan:string("\d") .
> {ok,[{'\d',1}],1}
> 17> erl_scan:string("\e") .
> {ok,[],1}
> 18> erl_scan:string("\f") .
> {ok,[],1}
> 19> erl_scan:string("\n") .
> {ok,[],2}
> 20> erl_scan:string("\r") .
> {ok,[],1}
> 21> erl_scan:string("\t") .
> {ok,[],1}
> 22> erl_scan:string("\v") .
> {ok,[],1}
> 23> erl_scan:string("\\") .
> {ok,[{'\\',1}],1}
> 24> erl_scan:string("\^A") .
> {ok,[],1}
> 25> erl_scan:string("\'") .
> {error,{1,erl_scan,{string,39,[]}},1}
> 26> erl_scan:string("\"") .
> {error,{1,erl_scan,{string,34,[]}},1}
> 27> erl_scan:string("\266") .
> {ok,[{'?',1}],1}
> 28> erl_scan:string("\266\
> 28> \266") .
> {ok,[{'?',1},{'?',2}],2}
>
> Roger
>
>
More information about the erlang-questions
mailing list