Earlier quoted context omitted.
Lexical analysis using these bespoke methods (writing the finite state machine) is so tedious and error prone. I don't have that much experience but I just went through crafting interpreters and replaced this same module with https://github.com/J-F-Liu/pom , which is a parser combinator library, and it was way easier.
Parser combinators are neat. nom is my go-to now in Rust, it's nice not have to separate your lexer and parser in simpler grammars.
Writing a SQL database from scratch in Go
11–20 of 55 posts
Re: Writing a SQL database from scratch in Go
#12Earlier quoted context omitted.
Parser combinators are neat. nom is my go-to now in Rust, it's nice not have to separate your lexer and parser in simpler grammars.
(it’s actually also straightforward to write a recursive descent parser directly on the char stream w/o a lexing step.)
Re: Writing a SQL database from scratch in Go
#13selectKeyword keyword = "select" I don't work with Go, so this may be a requirement of the language that I don't know, but whenever I see lines like this, it automatically brings up the question why? --- do you really expect to need to rename the SELECT keyword? Especially when it's named "selectKeyword". Why not just use the string constant? Ditto for the others like "leftparenSymbol" --- I see there's explicit char…
Another reason is that by providing an identifier for this string literal, misspellings of it can be detected by the compiler whereas there is nothing tying separate string literals together.
Re: Writing a SQL database from scratch in Go
#14Earlier quoted context omitted.
Parser combinators are neat. nom is my go-to now in Rust, it's nice not have to separate your lexer and parser in simpler grammars.
(it’s actually also straightforward to write a recursive descent parser directly on the char stream w/o a lexing step.)
Re: Writing a SQL database from scratch in Go
#15Earlier quoted context omitted.
Another reason is that by providing an identifier for this string literal, misspellings of it can be detected by the compiler whereas there is nothing tying separate string literals together.
I can hardly imagine a case where you would misspell "select" and not notice it at some point, nor use it in more than one place (the keyword detector) in the parser.
Re: Writing a SQL database from scratch in Go
#16Earlier quoted context omitted.
Another reason is that by providing an identifier for this string literal, misspellings of it can be detected by the compiler whereas there is nothing tying separate string literals together.
I can hardly imagine a case where you would misspell "select" and not notice it at some point, nor use it in more than one place (the keyword detector) in the parser.
Re: Writing a SQL database from scratch in Go
#17Unexpected, but welcome, to see the first part in the series on here right now. I just published the second part [0] today, featuring binary expressions and WHERE filtering. It also updates the REPL to use a prettier table-printing library and a readline implementation. The repo [1] has some additional bare notes on architecture and links to similar, more mature projects (primarily go-mysql-server and ramsql). [0] ht…
Re: Writing a SQL database from scratch in Go
#18Earlier quoted context omitted.
I can hardly imagine a case where you would misspell "select" and not notice it at some point, nor use it in more than one place (the keyword detector) in the parser.
The pattern (which I employ only sometimes) is to have almost all literals defined in this way. Perhaps SELECT isn’t likely to be the word you misspell, but I’m a careless typist and make 10 typos a minute. Taking this added step helps your editor save you from yourself.
Similar to how linters stop you from overthinking indentation in specific cases, or some naming standards, and later rename/reformat-wars.
Re: Writing a SQL database from scratch in Go
#19Re: Writing a SQL database from scratch in Go
#20I'd just like to add for the curious, that usually you'd use goyacc for parsing SQL.
And most serious SQL projects in Go have started with the SQL parser from vitess and adapted it to their use case (which is just funny trivia, but for anything big, I recommend it, did the same for OctoSQL [0]).