-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow parentheses (..)
in expressions
#66
Comments
(..)
in expressions(..)
in expressions
Closes #72 Fairly simple change: - Tuple types - Tuple expressions - Tuple indexing expressions. Error out on invalid indices such as `0xa` or anything that is not a `usize`. Note that `t.0.0` does not currently work, but `t.0 .0`. Once we implement #66, we can then write `(t.0).0`. In the future, we can support `t.0.0` which can be done in two ways: - Special case the lexer to _not_ parse the `0.0` as a real in the case of a tuple access (this means the lexer now has to concern itself with the context). - Break the real `0.0` apart in the pasrer, which kinda what Rust does (see rust-lang/rust#71322 after an attempt for the other method in rust-lang/rust#70420)
@mohammadfawaz What should a parentheses be called? Right now this is the test and result
Obviously, Tuple is incorrect. Do we just name it Paren? Is there a specific output for parentheses in expressions you're expecting? |
Right, yeah the parser should be careful what actually get prioritized here. I do imagine a expression enum variant called |
The difference between a single element Tuple and a parenthesised expression is subtle. Most languages handle it by putting a comma after the field in the tuple, i.e., |
Yeah makes sense. So should we assume that something like fn main() {
let x = (1,) + 2;
} but this does: fn main() {
let x = (1) + 2;
} This also works with a warning that says that the parentheses are unnecessary: fn main() {
let x:(u32) = 5;
} |
Yep. This works though: fn main() {
let x = (1,).0 + 2;
} |
When #138 is merged, there will no longer be any ambiguities here. |
Example:
let x = 1 + (2 * 3);
The text was updated successfully, but these errors were encountered: