Since I got feedback, that I don’t write enough devlogs I will try to improve that and do one every 5h. (Not sure if I can keep that up, but we’ll see…).
What did I do
This was not my first time writing a parser, specifically a Pratt-Parser, so kind of knew what I was doing, but at the same time wanted to do a bit too much. I decided, since I already had experience, that I wanted to do some nice error handling this time, so that the error messages can at least point you into the right direction.
Testing
Then I started to write some tests for the parser, but quickly stopped again, because I realized that it would be a huge pain creating all these nested data-structures by hand, so I threw my concept of a library overboard and turned it into an executable. Not the “correct” choice, I know, and yes, I could have done it with AI, but I didn’t feel like doing either of that, so I just skipped it. Maybe I will generate some test-cases later on.
What did I learn
Even though I already did one of these things, creating one with proper error handling was quite the experience. First I just wanted to create my own error type, but then Copilot told me to use a library instead, so I spent about an hour figuring out how that worked and which library to use (There are some massive differences between thiserror and anyhow).
static vs const
After that was done I wanted to create a truly const parsing table this time after just using a function with hard-coded values last time. I again tried to ask AI and it told me to use static for that. Of course, shortly after I discovered that static is not the way to go and const is actually preferable here. Who would have thought that you use const for constants…
refactoring error-handling
I again tried using AI for refactoring the creation of errors (I know, I should have learned my lesson by now), as constructing one takes 5 lines and is quite verbose. Of course I first tried myself, but all of my solutions were rejected by the borrow-checker, so eventually I gave up. The AI however managed to create something that worked: A static function that takes every single field of my Error struct as arguments, puts them together and returns the product. Using that would save exactly 0 lines of code and make it even more confusing. Well done Copilot!