【问题标题】:Erlang Parse_trans Form translate to Erlang Source CodeErlang Parse_trans 形式翻译为 Erlang 源代码
【发布时间】:2013-03-15 17:38:32
【问题描述】:

通过使用 parse_trans,我得到了模块的表单。然后我对其进行了一些修改。有没有办法将表单转换回实际的 erlang 代码?说形式如下:

[{attribute,1,file,
        {"/program.erl",
         1}},
{attribute,1,module,program},
{attribute,3,export,[{run,0}]},
{function,5,run,0,
       [{clause,5,[],[],
                [{match,5,
                        {var,5,'T'},
                        {cons,5,
                              {atom,40,program},
                              {cons,5,{atom,40,...},{cons,...}}}},
                 {call,5,
                       {remote,5,{atom,5,advices},{atom,5,before_advice}},
                       [{var,5,'T'}]},
                 {match,5,{var,5,'R'},{call,5,{atom,5,run_@},[]}},
                 {var,5,'R'}]}]},
{function,5,run_@,0,
       [{clause,5,[],[],
                [{call,6,
                       {remote,6,{atom,6,program2},{atom,6,calc_service}},
                       [{integer,6,1},{integer,6,0}]},
                 {call,7,
                       {remote,7,{atom,7,program2},{atom,7,calc_service}},
                       [{integer,7,2},{integer,7,2}]},
                 {call,8,
                       {remote,8,{atom,8,program2},{atom,8,process_message}},
                       [{string,8,"Add 3 to 5"}]},
                 {call,9,
                       {remote,9,{atom,9,program2},{atom,9,...}},
                       [{string,9,"Message to process"}]},
                 {call,10,{remote,10,{atom,10,...},{atom,...}},[]},
                 {atom,11,ok}]}]},
{eof,11}]

【问题讨论】:

    标签: erlang


    【解决方案1】:

    使用erl_pp:form/1。 这是一个例子:

    parse_transform(Forms, _Options) ->
        IOList = [erl_pp:form(Form) || Form <- Forms],
        io:format(user, "~s", [IOList]),
        Forms.
    

    【讨论】:

      【解决方案2】:

      您可以使用 parse_trans 应用程序中的漂亮打印机:https://github.com/esl/parse_trans/blob/master/src/parse_trans_pp.erl

      【讨论】:

        猜你喜欢
        • 2011-04-14
        • 1970-01-01
        • 2019-01-16
        • 2011-12-05
        • 2015-05-12
        • 1970-01-01
        • 2010-11-19
        • 2013-10-27
        • 2012-02-28
        相关资源
        最近更新 更多