Skip to content

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

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/expressions/tuple-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Tuple expressions

> **<sup>Syntax</sup>**
> _TupleExpression_ :
> &nbsp;&nbsp; &nbsp;&nbsp; `(` `)`
> &nbsp;&nbsp; | `(` [_Expression_] `,` `)`
> &nbsp;&nbsp; | `(` [_Expression_] (`,` [_Expression_] )<sup>\+</sup>
> `,`<sup>?</sup> `)`
Copy link
Contributor

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> `)`


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.
Expand All @@ -22,6 +29,10 @@ comma:

## Tuple indexing expressions

> **<sup>Syntax</sup>**
> _TupleIndexingExpression_ :
> &nbsp;&nbsp; [_Expression_] `.` [INTEGER_LITERAL]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be TUPLE_INDEX

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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