问题
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?
回答1:
No, you cannot get code comments inside macros. They never become part of the AST and are discarded still in Elixir's tokenizer.
回答2:
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").
来源:https://stackoverflow.com/questions/30543321/is-that-possible-to-get-comments-with-macro