inaka / inaka/katana-code

Error parsing macros with dashes

Open
#73 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Erlang
Stars
18
Forks
19
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided test_format.erl example and inspect the ktn_dodger:parse_file/1 output for the quoted macro with dashes. Trace how that parsed form is handled by katana-code, then verify that formatting preserves the single quotes and does not split the macro name.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.