Expand language support to know more about language

So, I’ve managed to include codemirror into my application and utilize sql-hint and the sql.js mode to make a pretty respectable query editor. Ability to suck in table / columns for auto completion is great.

I’d like to make sure I could support aliasing (which I realize may require codemirror to have a much better understanding of what is valid in sql ( select * from users u where u.).

Also, perhaps even select * from <automatically pops up table/views>

So I guess my question is, is there a way to provide a syntax tree of possible options and somehow generate a mode definition, or perhaps bypass mode all together and implement a different way to make a language available to syntax highlighting and auto completion?

This kind of serious parsing is usually best done outside of the mode – run a real parser on your code when completion is activated, and use that to provide context-aware hints. The Tern addon does this for JavaScript, for example. As far as I am aware, no one has written something like that for SQL.