Capturing nodes of the given ast for traverse

Hi guys, I’m working with elixit AST’s, to create some custom checks in credo, and I was wondering if there is a way to capture 2 nodes by pattern matching in the params of the traverse function? I saw that always they use pattern matching in the AST param they always get a triplet of a node:
but I was trying to pattern match 2 nodes to validate if the second nodes comes exactly after the first one. looking to this ast:

it seems that all the code is inside the list of arguments of the triplet of the :do block, and I tryied to pattern pmatch like this :

[{:@, _, _}, {:def, _, arguments}] = ast but the clause is never matched.

thanks in advice for any help.

You are matching on a list with only 2 elements which is not matched in the AST you show. I suspect you might get a bit further with:

[{:@, _, _}, {:def, _, arguments} | _rest] = ast
1 Like

daamn, makes a lot of sense! I’m going to try that when I arrive home, I’m almost sure that is that !

ok, I tried but that wasn’t the problem, this is what im using top capture with pattern matching:

[{:@, _, _}, {:def, meta, [{name, _, args} | _]} | _] = ast,

this is the type of param I’m trying to match:

 {:@, [line: 15, column: 3],
          [{:doc, [line: 15, column: 4], ["  Adds 2 numbers\n"]}]},
         {:def, [line: 18, column: 3],
            {:add, [line: 18, column: 7],
               {:a, [line: 18, column: 11], nil},
               {:b, [line: 18, column: 14], nil}
              do: {:+, [line: 19, column: 7],
                 {:a, [line: 19, column: 5], nil},
                 {:b, [line: 19, column: 9], nil}