This is a very rudimentry sql lexing and parsing logic for use in sqlite toy implementation project.
Lexing technique is inspired by the Talk of Rob Pike on Lexing on go html/templating std lib
Create Table
go run main.go
Scanning SQL: CREATE TABLE oranges ( id integer primary key autoincrement, name text, description text ) Parsed Stmt: &{create oranges {oranges [{id [integer primary key autoincrement]} {name [text]} {description [text]}]}}
Select statement
go run main.go
Scanning SQL: SELECT name, id from apples Parsed Stmt: &{select [name id] [apples] []}
Select statement with functions
go run main.go
Scanning SQL: SELECT Count(*) from apples, oranges Parsed Stmt: &{select [] [apples oranges] [{count [*]}]}
go run main.go
Scanning SQL: SELECT name, id, from apples, oranges Parsing error: Unexpected trailing comma near "from" at line 1 pos 17
go run main.go
Scanning SQL: SELECT Count(name id) from apples, oranges Parsing error: Missing comma between arguments near "id" at line 1 pos 18