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

Aleppo is eating includes #45

Closed
elbrujohalcon opened this issue Jul 26, 2017 · 5 comments
Closed

Aleppo is eating includes #45

elbrujohalcon opened this issue Jul 26, 2017 · 5 comments

Comments

@elbrujohalcon
Copy link
Member

Coming from inaka/elvis#467, it looks like aleppo is misunderstanding include attributes.

1> MinContent = "-module(x).\n-include(\"x.hrl\").",
{ok, MinTokens, _} = erl_scan:string(MinContent, {1,1}, [text]),
rp({MinTokens, aleppo:process_tokens(MinTokens)}).
{[{'-',[{text,"-"},{location,{1,1}}]},
  {atom,[{text,"module"},{location,{1,2}}],module},
  {'(',[{text,"("},{location,{1,8}}]},
  {atom,[{text,"x"},{location,{1,9}}],x},
  {')',[{text,")"},{location,{1,10}}]},
  {dot,[{text,".\n"},{location,{1,11}}]},
  {'-',[{text,"-"},{location,{2,1}}]},
  {atom,[{text,"include"},{location,{2,2}}],include},
  {'(',[{text,"("},{location,{2,9}}]},
  {string,[{text,"\"x.hrl\""},{location,{2,10}}],"x.hrl"},
  {')',[{text,")"},{location,{2,17}}]},
  {dot,[{text,"."},{location,{2,18}}]}],
 {ok,[{'-',[{location,{1,1}},{text,"-"},{location,{1,1}}]},
      {atom,[{location,{1,2}},{text,"module"},{location,{1,2}}],
            module},
      {'(',[{location,{1,8}},{text,"("},{location,{1,8}}]},
      {atom,[{location,{1,9}},{text,"x"},{location,{1,9}}],x},
      {')',[{location,{1,10}},{text,")"},{location,{1,10}}]},
      {dot,[{location,{1,11}},{text,".\n"},{location,{1,11}}]},
      {string,[{location,{2,10}},
               {text,"\"x.hrl\""},
               {location,{2,10}}],
              "x.hrl"},
      {eof,0}]}}
ok

As you can see… aleppo is interpreting -include("x.hrl"). as just…

      {string,[{location,{2,10}},
               {text,"\"x.hrl\""},
               {location,{2,10}}],
              "x.hrl"},

…as if it was just "x.hrl", i.e. the string floating around in the module.

@elbrujohalcon
Copy link
Member Author

This works well if we use aleppo:process_tokens(MinTokens, [{include, ["include"]}])., but only if that include folder exists

@elbrujohalcon
Copy link
Member Author

We have the same issue with -include_lib(…)

@elbrujohalcon
Copy link
Member Author

elbrujohalcon commented Jul 31, 2017

Weirdly, @harenson detected that this works appropriately…

MinContent = "-module(x).-include(\"x.hrl\")."

i.e. without the \n in between, it works.

@elbrujohalcon
Copy link
Member Author

Digging deeper, the wrong behaviour works as this:
If aleppo is parsing a file and it finds an -include or -include_lib attribute for which it can't find the header file, that attribute is incorrectly parsed as a string.
That makes tools dependent on it fail while trying to make sense of the tokens generated by aleppo:process_* functions.

@elbrujohalcon
Copy link
Member Author

Fixed by #55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant