Is that possible to get comments with macro?

泪湿孤枕 提交于 2019-12-08 19:36:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!