Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a strongly typed AST #121

Open
felipebz opened this issue Jun 23, 2019 · 0 comments
Open

Add a strongly typed AST #121

felipebz opened this issue Jun 23, 2019 · 0 comments

Comments

@felipebz
Copy link
Owner

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:

public void visitNode(AstNode node) {
AstNode table = node.getFirstChild(DmlGrammar.TABLE_REFERENCE);
if (table != null && table.getTokenOriginalValue().equalsIgnoreCase("user")) {
addIssue(table, "Replace this query by a function of the USER_WRAPPER package.");
}
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant