Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is that possible to get comments with macro?

Tags:

macros

elixir

I was trying to parse some code and reformat them, but it seems that quote will just ignore the comments.

Is there any way to achieve this? I guess I have to dive into the erlang side?

like image 253
Kabie Avatar asked May 30 '15 07:05

Kabie


People also ask

Where do comments appear of a macro?

Remarks. A Comment may be up to 1000 characters in length. However, by default, only the first line of the comment is displayed in the macro design window. To see the entire comment text, click or tab into the Comment statement in the Macro design window.


2 Answers

No, you cannot get code comments inside macros. They never become part of the AST and are discarded still in Elixir's tokenizer.

like image 76
José Valim Avatar answered Nov 15 '22 09:11

José Valim


It seems that comments are handled at the tokenizer level, so the parser will not even see them. The relevant parts from the elixir tokenizer indicate that comments are discarded pretty early in the pipeline. This test case from elixir core tells us the same thing:

comments_test() ->
  [{number, {1,1,2}, 1},{eol, {1,3,4}},{number,{2,1,2},2}] = tokenize("1 # Comment\n2").
like image 21
Patrick Oscity Avatar answered Nov 15 '22 09:11

Patrick Oscity