I’m polishing up an old syntax I wrote for Oracle SQL. A key feature is detailed meta scopes. Consider the following:
with foo as (
select * from tableA
)
select x, y, z
from foo
where x = 1
The entire snippet would be contained within meta.query
. Then, parts of the query would have their own meta scopes.
The first approach I tried was to use new meta scopes for parts of the query. For instance, select x, y, z
would be scoped as meta.query meta.select
. But this can result in very deeply nested scopes. For instance, the select *
on the second line would be meta.query meta.with meta.query meta.select
. This can be problematic for very complex queries.
The second approach that I’m using now is to emulate scopes like meta.function
and meta.function.parameters
. Thus, select x, y, z
would be scoped meta.query.select
and select *
would be scoped meta.query.with meta.query.select
. I think that this should work for SQL because a query is unambiguously partitioned into distinct sections. However, I rarely see another syntax use this approach.
What do people think about this? Is there a good reason to prefer one approach or the other?