Samasaur1 / DiceKit

A Swift module for simulating dice both real and unreal
https://samasaur1.github.io/DiceKit/
Academic Free License v3.0
4 stars 4 forks source link

Rewrite Dice parsing #98

Open Samasaur1 opened 2 years ago

Samasaur1 commented 2 years ago

https://github.com/Samasaur1/DiceKit/blob/d67f52f6d2b483180814644cd1d96edb97e060d1/Sources/DiceKit/Dice.swift#L168-L252

So just by looking at the code for the string parsing of dice expressions, I think it should be pretty clear that it’s not a great implementation. To be fair, it does pass my fairly comprehensive set of unit tests, but I still think that a) that’s probably due to luck; b) even if it works, it’s not maintainable.

I’d like to replace it with recursive-descent parsing (or really, any structured type of parsing, but I have experience with recursive-descent, and I think it would work with this scenario.