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

Offending token will sometimes be unexpected #32

Open
surister opened this issue Jun 7, 2024 · 1 comment
Open

Offending token will sometimes be unexpected #32

surister opened this issue Jun 7, 2024 · 1 comment
Labels
grammar For antlr4 related grammar issues

Comments

@surister
Copy link
Collaborator

surister commented Jun 7, 2024

from cratedb_sqlparse import sqlparse

query = """
SELECT COUNT(*) FOM doc.tbl f WHERE f.id = 1;

INSERT INTO doc.tbl VALUES (1, 23, 4);
"""
t = sqlparse(query)
t1 = t[0]
print(t1.exception.original_query_with_error_marked)

Error message:

SELECT COUNT(*) FOM doc.tbl f WHERE f.id = 1;
                    ^^^

INSERT INTO doc.tbl VALUES (1, 23, 4);

I assume this happens because antlr4 doesn't know that 'FOM' should be a 'FROM' and therefore the error it finds is InputMismatchException[line 2:20 mismatched input 'doc' expecting {<EOF>, ';'}]

The offendingToken that antrl4 gives is:

class ExceptionCollectorListener(ErrorListener):
    def __init__(self):
        self.errors = []

    def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
        print(offendingSymbol)
[@10,21:23='doc',<312>,2:20]
@surister surister added the grammar For antlr4 related grammar issues label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grammar For antlr4 related grammar issues
Projects
None yet
Development

No branches or pull requests

1 participant