zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

token_ast_correlation.ex (910B)


      1 defmodule Credo.Code.TokenAstCorrelation do
      2   # Elixir >= 1.6.0
      3   def find_tokens_in_ast(wanted_token, ast) do
      4     Credo.Code.prewalk(ast, &traverse_ast_for_token(&1, &2, wanted_token))
      5   end
      6 
      7   defp traverse_ast_for_token({:., meta, arguments} = ast, acc, token)
      8        when is_list(arguments) do
      9     {line_no_start, col_start, _line_no_end, _col_end} = Credo.Code.Token.position(token)
     10 
     11     if meta[:line] == line_no_start && meta[:column] == col_start - 1 do
     12       {nil, acc ++ [ast]}
     13     else
     14       {ast, acc}
     15     end
     16   end
     17 
     18   defp traverse_ast_for_token({_name, meta, _arguments} = ast, acc, token) do
     19     {line_no_start, col_start, _line_no_end, _col_end} = Credo.Code.Token.position(token)
     20 
     21     if meta[:line] == line_no_start && meta[:column] == col_start do
     22       {nil, acc ++ [ast]}
     23     else
     24       {ast, acc}
     25     end
     26   end
     27 
     28   defp traverse_ast_for_token(ast, acc, _token) do
     29     {ast, acc}
     30   end
     31 end