Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing macros with dashes #73

Open
carlosedp opened this issue Jun 14, 2022 · 0 comments
Open

Error parsing macros with dashes #73

carlosedp opened this issue Jun 14, 2022 · 0 comments
Labels

Comments

@carlosedp
Copy link

carlosedp commented Jun 14, 2022

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: AdRoll/rebar3_format#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
@carlosedp carlosedp added the bug label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant