In the production application I would probably also use chumsky crate, since it simplifies the whole process. But it was interesting for me to implement parser and tokenizer myself, so I didn’t use it this time :)
Simplifies boilerplate for defining custom error types. I used it in parser and tokenizer modules.
Self-explanatory :)
The calculator accepts expressions via STDIN:
echo '2 / (3 - 1)' | castor_calculatorNo special build steps required, cargo build is enough :)
The calculator uses the grammar described in the parser.rs in combination with the recursive descent.
Before parser is invoked, the input is run through the tokenizer, preventing invalid input at the beginning. Parser only works with the list of tokens, not with the raw string.