Static Analysis with Lezer

Hi Folks,

We have a loose SQL grammar based on PostGreSQL from here.

We wanted to also use this parse tree to build some basic dependency analysis for various SQL constructs. I was wondering how feasible would such a static analysis use case be using lezer?

Simple static analysis should be viable, but it gets a bit more awkward than with a proper abstract syntax tree, because nodes’ children aren’t structured and don’t contain their ‘value’ (such as identifier name). So you’ll want to move through the tree with the SyntaxNode abstraction and its getChild/getChildren methods, and refer back to the document when you need to figure out what the content of a node is.

@marijn Thank you for your prompt response. We are also writing a formatter and hence we’ve got the hang of using the indexes in the cursor to navigate through the code.

We’re trying to a very crude static analysis like run through multiple SQL queries and parsing out the tables being referenced and so we’d to look for all objects inside the FromStmt node. So for things like that, I think this may work out.

I’ll keep this community posted regarding the results of doing the static analysis. Again thank you for your time.