This is something you could do with tree-sitter https://tree-sitter.github.io/tree-sitter/