Continue from the previous result when a line starts with an operator - #397
Open
ChrisJr404 wants to merge 1 commit into
Open
Continue from the previous result when a line starts with an operator#397ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
If a line begins with a binary operator that can't start an expression on its own (like `* 2` or `to miles`), fend now treats it as continuing from the previous result, so it becomes `_ * 2` or `_ to miles`. This matches how pocket and on-screen calculators behave. Operators with a prefix form (`+`, `-`, `/`) are left untouched so `-5` and `/2` keep their existing meanings, and nothing changes when there is no previous result to continue from. Closes printfn#306
Author
|
The ubuntu job didn't fail on a test, it timed out in the "Test (Linux i686)" step while apt-get was installing gcc-i686-linux-gnu (the download of cpp-13-i686-linux-gnu stalled on the azure mirror and the job hit the 20 minute limit). clippy, fmt and the macos/windows builds all passed, so this looks like a transient mirror hiccup rather than anything in the change. Could you re-run that job when you get a chance? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements #306: if a line starts with a binary operator that can't begin an expression on its own, fend continues from the previous result, the way a pocket or on-screen calculator does.
Under the hood, when a previous result is available in
_, an input whose first token is an operator that needs a left-hand operand (*,^,mod,to/as, bit shifts, bitwise ops, ...) is rewritten to prepend_. Operators that also have a prefix form (+,-,/) are deliberately left alone, so-5and/2still mean negative five and one half. Nothing changes when there is no previous result yet, so a leading operator in a fresh context is still an error as before.I added integration tests covering the rewritten operators, chaining (
* 2then^ 2), the interaction with a leading@attribute, the untouched-//cases, and the no-previous-result case, and documented the behaviour in the expressions chapter.cargo test,cargo fmt --checkandcargo clippy --all-targetsare all clean.