Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1092

epp_dodger can't parse macro with arguments and ;

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Help Wanted
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: syntax_tools
    • Labels:
      None

      Description

      Symptoms

      epp_dodger:parse_file/1 returns an error when trying to parse a module with a macro with arguments and ; in its body.

      Steps to Reproduce It

      1. Create a module like the following one:

       -module(demo).
      -define(MACRO(Arg), false; true).

       2. Try to parse it using epp_dodger.

      What Should Happen

      Something along the lines of…

       
      1> epp_dodger:parse_file("demo.erl").
      {ok,[

      {tree,attribute, \{attr,1,[],none},
      {attribute,{tree,atom,{attr,1,[],none},module},
      [{tree,atom,{attr,1,[],none},demo}]}},
      {tree,attribute, \{attr,2,[],none},
      {attribute,{atom,2,define},
      [{tree,application, \{attr,2,[],none},
      {application,{var,2,'MACRO'},[\{var,2,'Arg'}]}},
      {tree,text,{attr,2,[],none},"false ; true "}]}}]}
      h2. What Happens

      1> epp_dodger:parse_file("demo.erl").
      {ok,[{tree,attribute, {attr,1,[],none}

      ,
      {attribute,{tree,atom,

      {attr,1,[],none},module},
      [{tree,atom,{attr,1,[],none}

      ,demo}]}},
      {error,{2,erl_parse,["syntax error before: ","';'"]}}]} 

      Additional Notes

      If we remove the argument but not the parentheses, it still fails

       12> io:format("~s~n", [os:cmd("cat demo.erl")]), epp_dodger:parse_file("demo.erl").
      -module(demo).
      -define(MACRO(), false; true).
      {ok,[

      {tree,attribute, \{attr,1,[],none},
      {attribute,{tree,atom,{attr,1,[],none},module},
      [{tree,atom,{attr,1,[],none},demo}]}},
      {error,{2,erl_parse,["syntax error before: ","';'"]}}]}
      h3. If we remove the parentheses, it works

      13> io:format("~s~n", [os:cmd("cat demo.erl")]), epp_dodger:parse_file("demo.erl").
      -module(demo).
      -define(MACRO, false; true).
      {ok,[{tree,attribute, {attr,1,[],none}

      ,
      {attribute,{tree,atom,

      {attr,1,[],none},module},
      [{tree,atom,{attr,1,[],none}

      ,demo}]}},

      {tree,attribute, \{attr,2,[],none},
      {attribute,{tree,atom,{attr,2,[],none},define},
      [{var,2,'MACRO'},
      {tree,text,{attr,2,[],none},"false ; true "}]}}]}
      h3. If we remove the ;, it works

      14> io:format("~s~n", [os:cmd("cat demo.erl")]), epp_dodger:parse_file("demo.erl").
      -module(demo).
      -define(MACRO(), false or true).
      {ok,[{tree,attribute, \{attr,1,[],none},
      {attribute,{tree,atom,{attr,1,[],none},module},
      [{tree,atom,{attr,1,[],none},demo}]}},
      {tree,attribute, {attr,2,[],none}

      ,
      {attribute,

      {atom,2,define}

      ,
      [

      {tree,application, \{attr,2,[],none}

      ,
      {application,

      {var,2,'MACRO'}

      ,[]}},

      {tree,infix_expr, \{attr,2,[],none}

      ,
      {infix_expr,{tree,operator,

      {attr,2,[],none}

      ,'or'},
      {atom,2,false},
      {atom,2,true}}}]}}]}

      If we use quick_parse_file/1, it works but it ignores the macro

       15> io:format("~s~n", [os:cmd("cat demo.erl")]), epp_dodger:quick_parse_file("demo.erl").
      -module(demo).
      -define(MACRO(), false; true).

      {ok,[\{attribute,1,module,demo}

      ]}

       

        Attachments

          Activity

            People

            Assignee:
            otp_team_vm Team VM
            Reporter:
            elbrujohalcon Brujo Benavides
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: