been a long time since I posted anything about coding, probably because I haven't been doing much of anything for a while since I had a really bad experience at my job which burned me out so bad I had to switch industries.
but I just implemented an amazing feature for my library, untwine, which is a parser generator macro enabling extremely easy parsing of any format (and it's even capable of doing context-sensitive parsing!).
look at how a boolean parser would be defined before:
this isn't so bad, but it's duplicating the string equality check, so it will check if the string is equal to "true" twice - once when it parses the pattern, and once when converting the data in the code block.
this approach also doesn't scale. in the case where you're matching weekdays, you end up needing a match statement inside your code block:
this gave me the ick for a long time because you have to repeat yourself and you have an ugly unreachable case which will trigger if you ever forget to add a case to the match statement after adding it to the pattern (which is very easy to do).
so now I've implemented a parser type which looks and acts like a match statement, allowing you to express things like that much more elegantly:
it's also extremely handy for command parsing, allowing me to express branching parsing paths that evaluate to the same type very cleanly. you can capture the values of the patterns you parse, which is perfect for grabbing arguments:
for all my 2 (± 1) followers who understand and care about parsing, you can see the full project up at https://crates.io/crates/untwine














