zpa icon indicating copy to clipboard operation
zpa copied to clipboard

Add a strongly typed AST

Open felipebz opened this issue 5 years ago • 0 comments

Currently to create new rules it's necessary to know the internals of the grammar and look at the generated AST using the zpa-toolkit. Ideally we should provide an easier API to navigate through the AST.

Example:

https://github.com/felipebz/zpa/blob/304aa892c0c59f42c08f32fc67c2488e4c538666/plsql-custom-rules/src/main/java/com/company/plsql/ForbiddenDmlCheck.java#L28-L34

With a strongly typed AST it could be write like:

    public void visit(TableExpressionClause tableExpression) {
        TableReference table = tableExpression.getTableReference();
        
        if (table != null && table.getName().equalsIgnoreCase("user")) {
            addIssue(table, "Replace this query by a function of the USER_WRAPPER package.");
        }
    }

The SSLR library provides a API to create a typed AST but it only works with lexerless grammars, but we can't migrate to a lexerless grammar because it's much slower than the lexerful one.

felipebz avatar Jun 23 '19 14:06 felipebz