-
Notifications
You must be signed in to change notification settings - Fork 533
Grammar for tuple and tuple indexing expressions #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,13 @@ | |
|
||
## Tuple expressions | ||
|
||
> **<sup>Syntax</sup>** | ||
> _TupleExpression_ : | ||
> `(` `)` | ||
> | `(` [_Expression_] `,` `)` | ||
> | `(` [_Expression_] (`,` [_Expression_] )<sup>\+</sup> | ||
> `,`<sup>?</sup> `)` | ||
|
||
Tuples are written by enclosing zero or more comma-separated expressions in | ||
parentheses. They are used to create [tuple-typed](types.html#tuple-types) | ||
values. | ||
|
@@ -22,6 +29,10 @@ comma: | |
|
||
## Tuple indexing expressions | ||
|
||
> **<sup>Syntax</sup>** | ||
> _TupleIndexingExpression_ : | ||
> [_Expression_] `.` [INTEGER_LITERAL] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be TUPLE_INDEX There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. That's correct, but it's like the lexer is aware of context... which is strange. But yeah, the parser is the one that disallows prefixes, suffixes and nonzero numbers beginning in zero. |
||
|
||
[Tuples](types.html#tuple-types) and [struct tuples](items/structs.html) can be | ||
indexed using the number corresponding to the position of the field. The index | ||
must be written as a [decimal literal](tokens.html#integer-literals) with no | ||
|
@@ -36,3 +47,6 @@ assert_eq!(pair.1, 2); | |
let unit_x = Point(1.0, 0.0); | ||
assert_eq!(unit_x.0, 1.0); | ||
``` | ||
|
||
[INTEGER_LITERAL]: tokens.html#integer-literals | ||
[_Expression_]: expressions.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two can be merged into
`(` [_Expression_] `,` `)` <sup>\+</sup> [_Expression_]<sup>?</sup> `)`