go-sqlite / sqlite3

pure-Go sqlite3 file reader
BSD 3-Clause "New" or "Revised" License
140 stars 19 forks source link

SQL parser #23

Open sbinet opened 6 years ago

sbinet commented 6 years ago

We'd need a SQLite 3 SQL statements parser.

Possible candidate(s?) before writing our own:

zellyn commented 6 years ago

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

sri-soham commented 6 years ago

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.

sbinet commented 6 years ago

@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 ? :)

sri-soham commented 6 years ago

@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 commented 6 years ago

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?