News for hackers. Stuff that matters.
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by simonw on Sunday August 13, 2023 @06:09PM (#37115052)
Thanks to this post I learned about Lark, which looks like a really nice parser library for Python.

The JSON tutorial on their site is excellent - shows how to build a basic parser for JSON, then goes into some great detail about how to improve its performance: https://lark-parser.readthedocs.io/en/latest/json_tutorial.h...

Here's the grammar used for the RDBMS project: https://github.com/spandanb/learndb-py/blob/master/learndb/l...

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by OJFord on Sunday August 13, 2023 @06:44PM (#37115386)
DSL in a string? Is that 'really nice'? I haven't used or needed this in Python that I can think of, but surely we can do better than that?

Even a dict with expected keys and construction via the bitwise or operator (which would roughly match the form of a lot of the grammar) would be better wouldn't it? Imports could be imports, just mixed in somehow.

This is just first thoughts at a glance, maybe I'm missing something.

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by simonw on Sunday August 13, 2023 @07:39PM (#37115743)
That's pretty standard for parsing libraries - have you seen any good ones (for Python or other languages) that don't use a DSL like this?

The only one I've seen is this one: https://parsy.readthedocs.io/en/latest/tutorial.html

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by dleslie on Monday August 14, 2023 @12:42AM (#37117536)
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by zelphirkalt on Monday August 14, 2023 @04:23AM (#37118687)
Here is another PEG one, though Guile allows expressing things as strings and as macro calls / s-expressions:

5: https://www.gnu.org/software/guile/manual/html_node/PEG-Pars...

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by tmpX7dMeXU on Sunday August 13, 2023 @07:21PM (#37115625)
It’s an existing, standard, language for describing grammars. Quite clearly the trade-off being made here. Seemingly not the one you would’ve made. Don’t act like it’s objectively bad.
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by OJFord on Sunday August 13, 2023 @08:28PM (#37116095)
in a string. I didn't say the DSL was novel. I learnt BNF too. (It does have extras that are either unique to it or standard beyond my familiarity though.)
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by mejutoco on Monday August 14, 2023 @07:40AM (#37119851)
I was always surprised at how the Ruby community talks about DSLs when using Ruby classes and catch all methods, overloading, etc. Nothing bad with it, but I feel it is not really a language, just very dynamic Ruby code.

A DSL that is a string, while having some downsides, does not have the arbitrary limitations of the "host" language. Either approach has its pros an cons.

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by OJFord on Monday August 14, 2023 @08:53AM (#37120461)
I'm not that versed in Ruby, but I think similarly say the Django ORM in Python borders on DSL - especially with use of bitwise operators to build a query.

It's the tooling aspect that's my gripe with it in a string really, it makes it less likely (and more editor-specific) that I can have syntax highlighting, LSP, etc. That's incidentally the only way in which I don't prefer SQL to Django ORM - i.e. it really isn't that it's a DSL (SQL) that bothers me, it's the string.

But hopefully obviously it's not a big deal, I was just surprised at the look of it when I saw it described as 'really nice' and that the project describes itself as 'focussed on ergonomics'. It just doesn't seem brilliant to me, fine perhaps, par for the course apparently, but not remarkable.

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by semiquaver on Sunday August 13, 2023 @07:45PM (#37115778)
It is https://en.m.wikipedia.org/wiki/Backus–Naur_form or something similar. A python DSL would certainly be less expressive and useful.
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by OJFord on Sunday August 13, 2023 @08:26PM (#37116089)
I realise that (with some additions, certainly - it has imports) I just don't think embedding it in a string is 'really nice', personally. The 'developer experience' will be crap or reliant on hyper-specific tooling; so likely crap. (The RHS of that 'or' will be too niche to be good and well-maintained, probably.)
Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by spanspan on Sunday August 13, 2023 @08:14PM (#37116006)
This string is the grammar that lark uses to parse the user submitted sql into an AST. This parsing is far more complete and robust than what doing this in pure python would allow (without of course implementing the entire lexer and parser that lark implements).

There may be some post parsing validation that can be done here- but that would be something that's beyond the domain of the parser.

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by erezsh on Sunday August 20, 2023 @02:48AM (#37196818)
Lark supports, and recommends, writing and storing the grammar in a .lark file. We have syntax highlighting support in all major IDEs, and even in github itself. For example, here is Lark's built-in grammar for Python: https://github.com/lark-parser/lark/blob/master/lark/grammar...

The rationale is that it's more terse and has less visual clutter than a DSL over Python, which makes it easier to read and write.

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by jarulraj on Sunday August 13, 2023 @09:11PM (#37116328)
Highly recommend Lark for Python projects -- it's easy to use :)

Their IDE was super useful for debugging the grammar: https://www.lark-parser.org/ide/

We use Lark for a SQL-like language tailored for using AI models in EvaDB: https://github.com/georgia-tech-db/evadb/blob/master/evadb/p... https://github.com/georgia-tech-db/evadb/

If you like Lark, please consider sponsoring them: https://github.com/sponsors/lark-parser

Re:Show HN: I wrote a RDBMS (SQLite clone) from scratch in p... by itissid on Monday August 14, 2023 @05:06AM (#37118938)
Not to be coy or disrespectful( and this is excellent work and a way to learn new things) but if one is generating a parser as a means to an end(the end being execution of the AST on the database), what are the learnings one gets from just the parser bit? Is it some kind of optimization you need to keep doing to the generated parser to make it more efficient?

Would a logical next step be Generate an optimal query plan from the AST(somehow..)?