Skip to content

Error parsing macros with dashes #73

@carlosedp

Description

@carlosedp

Bug Description

While using rebar3_format (that uses katana-code for its formatter), I've seen a bug that it's removing the single quotes from macros that have dashes in the name.

For ref: https://github.com/AdRoll/rebar3_format/issues/311

To Reproduce

So code like:

-define(CCR_INITIAL, ?'CC-REQUEST-TYPE_INITIAL_REQUEST').
-define(CCR_UPDATE, ?'CC-REQUEST-TYPE_UPDATE_REQUEST').

becomes

-define(CCR_INITIAL, ?CC-REQUEST-TYPE_INITIAL_REQUEST).
-define(CCR_UPDATE, ?CC-REQUEST-TYPE_UPDATE_REQUEST).

Breaking the code.

I created a small test file as:

-module(test_format).

-include_lib("rfc4006_cc_Gy.hrl").

-define(WORK, abc).
-define(CCR_INITIAL, ?'CC-REQUEST-TYPE_INITIAL_REQUEST').
-define(CCR_UPDATE, ?'WORK').

parsing it manually with ktn_dodger gave me:

1> ktn_dodger:parse_file("apps/dccaserver/src/test_format.erl").
{ok,[{tree,attribute,
           {attr,1,[],none},
           {attribute,{tree,atom,{attr,1,[],none},module},
                      [{tree,atom,{attr,1,[],none},test_format}]}},
     {tree,attribute,
           {attr,3,[],none},
           {attribute,{atom,3,include_lib},
                      [{string,3,"rfc4006_cc_Gy.hrl"}]}},
     {tree,attribute,
           {attr,5,[],none},
           {attribute,{tree,atom,{attr,5,[],none},define},
                      [{var,5,'WORK'},{tree,text,{attr,5,[],none},"abc"}]}},
     {tree,attribute,
           {attr,6,[],none},
           {attribute,{tree,atom,{attr,6,[],none},define},
                      [{var,6,'CCR_INITIAL'},
                       {tree,text,
                             {attr,6,[],none},
                             "?CC - REQUEST - TYPE_INITIAL_REQUEST"}]}},
     {tree,attribute,
           {attr,7,[],none},
           {attribute,{tree,atom,{attr,7,[],none},define},
                      [{var,7,'CCR_UPDATE'},
                       {tree,text,{attr,7,[],none},"?WORK"}]}}]}

As seen, ktn_dodger separated the word in the dashes but it's quoted(the attr 6).

Expected Behavior

The code should not be separated and single quotes removed.

rebar3 Logs

If applicable, run rebar3 with DIAGNOSTIC=1 and attach all the logs to your report.

Additional Context

  • OS: MacOS
  • Erlang version 25.0.1
  • rebar3 version 3.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions