sqlite3 icon indicating copy to clipboard operation
sqlite3 copied to clipboard

SQL parser

Open sbinet opened this issue 7 years ago • 5 comments

We'd need a SQLite 3 SQL statements parser.

Possible candidate(s?) before writing our own:

  • https://github.com/xo/usql
  • https://github.com/src-d/go-mysql-server

sbinet avatar Jan 18 '18 21:01 sbinet

I think it's doing just enough parsing to syntax highlight… link.

zellyn avatar Jan 18 '18 22:01 zellyn

Lexer and parser generated with antlr4 for go seems to be working okay. https://github.com/antlr/antlr4/blob/master/doc/go-target.md https://github.com/antlr/grammars-v4/blob/master/sqlite/SQLite.g4 Lines 34 and 37 in the grammar file have the word 'error' which is a keyword in golang, had to change that to sqlite_error. The generated sqlite_parser.go had a statement, 'throw new RuntimeException' that I had changed to a panic.

sri-soham avatar Mar 31 '18 11:03 sri-soham

@sri-soham: seems interesting. I assume the way the Go code is generated, one wouldn't need anything from antlr afterwards ?

would you be up for a PR ? :)

sbinet avatar Apr 03 '18 20:04 sbinet

@sbinet : Files generated make use of the antlr go libraries. Java and the antlr jar file will not be needed though.

About the PR: I am new to lexer/parser business. It will take time.

sri-soham avatar Apr 04 '18 17:04 sri-soham

From what I have understood, sqlite3 generates bytecode by traversing through the parse tree. That bytecode and engine are internal to sqlite3 and can change without notice. https://www.sqlite.org/opcode.html

What do I do after parse tree is built? Generate golang struct for each type of statement or something else?

sri-soham avatar Apr 27 '18 11:04 sri-soham