> Erlang中文手册 > parse_erl_form/2 读取并解析 Erlang 表达式

io:parse_erl_form/2

读取并解析 Erlang 表达式

用法:

parse_erl_form(IoDevice, Prompt) -> Result

跟 io:parse_erl_exprs/2 一样,从指定输入端 IoDevice 读入数据,并把它解析为 Erlang 表达式

假如有一个名为 test.txt 的文件,其内容如下:

{line1, "a", "b", [{key1, val1}]}.
{line2, "c", "d", [{key2, val2}]}.

那么可以用 io:parse_erl_form/2 读取 test.txt 文件里的一行数据,并把它解析为 Erlang 表达式:

{ok, File} = file:open("test.txt", read), 
io:parse_erl_form(File, "").