partiql / partiql-lang-kotlin

PartiQL libraries and tools in Kotlin.
https://partiql.org/
Apache License 2.0
536 stars 60 forks source link

ANTLR Parser doesn't throw the intuitive error location #731

Open johnedquinn opened 1 year ago

johnedquinn commented 1 year ago

Yeah, Trino actually does something interesting (that I tried to replicate). ANTLR essentially throws exceptions at the last evaluated rule, but it doesn't throw the exception in the "deepest" rule. So, Trino, upon receiving a SyntaxError, creates some state machine to try to figure out the "deepest" rule to find the most precise location where the syntax error is really coming from.

I tried to replicate their state machine, but it didn't end up working for me. Decided to also just punt it because it seemed that it would add complexity to this PR when what we really need is to understand parse errors happening as a whole.

So, yeah, I'll create an issue and reference this and the Trino implementation. Linking soon.

_Originally posted by @johnedquinn in https://github.com/partiql/partiql-lang-kotlin/pull/718#discussion_r959813844_

johnedquinn commented 1 year ago

The Trino workaround for this can be found here