dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.4k stars 657 forks source link

using sql_yacc.yy to generate more complete keywords list #9

Open grooverdan opened 9 years ago

grooverdan commented 9 years ago

select * from mysql.help_keyword order by name;

grooverdan commented 9 years ago

alternate ref: https://github.com/MariaDB/server/blob/10.1/sql/sql_yacc.yy#L1024 / https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L478

amjith commented 9 years ago

I did originally plan to include all the reserved words from https://dev.mysql.com/doc/refman/5.0/en/reserved-words.html.

But I refrained from it since there are some arcane keywords that are not in use by most people. But adding them will bring in more noise to the completion menu. So I decided to add more keywords when people request certain keywords that are missing.

But I can be convinced otherwise. Thoughts?

grooverdan commented 9 years ago

I'd suggest trying to use "bison -g sq_yacc.yy" to generate sql_yacc.dot and then using this for the keyword list. Note https://github.com/erocarrera/pydot/blob/master/dot_parser.py needs this patch https://github.com/nlhepler/pydot-py3/issues/1 and even then I found it exhausted my memory on the generated file. Perhaps there are loops in the generated dot file it doesn't handle.

Using this file this way the supporting of future syntaxes is rerunning a script over the dot file from future mysql release and future maintenance is lessened (or could even be done by a user).

As you parse though this list you'll see which bits are syntactic sugar that aren't needed and can be hidden from the generation list (until a user starts typing part of one?). You'll also see the bits that need to correspond to a table, a view a database, a character set etc... If you can script the generation of this into a keyword map file you can get a map file that corresponds to a particular MySQL variant and version. If you distribute a few of these you can load the right map file at connect time based on the server version or at least something close.

The reserved list is still active so using it for colourization of text could be useful when users use reserved words as column names and wonder why it gets a syntax error.

amjith commented 9 years ago

That's an interesting idea. To have an extended keywords list for completion that is auto-generated from the yacc files in mysql and mariadb.

I also like the idea of layered suggestions where the common cases are readily suggested but the more obscure commands are only suggested after the current suggestions have been exhausted.

It might take some time to implement it, but I definitely like the idea. Thank you for the suggestion. :)