Closed djmattyg007 closed 3 years ago
Great idea, would like to add that
I've managed to add single-word synonyms for some of the operators, like "plus"
and "minus"
. However, the multi-word synonyms (like "multiplied by"
and "divided by"
) don't seem to work. I just get a message like this:
❯ target/release/cpc '5 divided by 2'
Lexing error: Invalid string: divided
The section where most words are lexed just deal with single-word keywords. Don't remember 100% how it works, but this is where two-word units are handled: https://github.com/probablykasper/cpc/blob/9bf7c69c038d5c747108e7e82bd3564532d28389/src/lexer.rs#L86-L90
Yeah I just came across that as your message came through :stuck_out_tongue: I also noticed that lexing of units such as "oil barrels" and "fluid ounces" don't seem to work because they aren't in that list.
Perhaps it needs to be reworked such that if we find a prefix of an operator, but haven't found an actually valid operator, we need to add the next word and try matching again.
I have no idea of how to actually implement that XD I'm brand new to rust.
Ah lol, no wonder you were confused.
Not really sure what would be the best way to go about it. The way it is now makes it nice and readable, but easier to add bugs.
An alternative would be checking for cubic
, and then having a nested match statement with meter
, centimeter
etc. This kinda disconnects the two-word units from the others, and probably results in a few more lines, but harder to add bugs.
Yeah, that's not a bad idea. That would support arbitrary matching too.
I'll see what I can come up with.
I thought I'd made some decent progress with this, then I proceeded to spend a decent chunk of the next 24 hours fighting the borrow checker :(
I'm going to submit a draft PR to kinda demonstrate the approach I took, but I suspect it won't actually be viable for the final product.
That's rough :/ I'll make sure to check out the draft PR and see if I have any ideas
Added by #21 and #18
Is it possible to support queries like this?