Skip to content
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

Parse tuple types and expressions #93

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Conversation

mohammadfawaz
Copy link
Contributor

@mohammadfawaz mohammadfawaz commented Jul 10, 2023

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:

@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/72 branch 4 times, most recently from fdeb90d to 61f3301 Compare July 10, 2023 19:38
@mohammadfawaz mohammadfawaz self-assigned this Jul 10, 2023
@mohammadfawaz mohammadfawaz marked this pull request as ready for review July 10, 2023 19:39
@mohammadfawaz mohammadfawaz changed the title tuples Parse tuple types and expressions Jul 10, 2023
specs/src/lang/language_primitives.md Outdated Show resolved Hide resolved
yurtc/src/ast.rs Outdated Show resolved Hide resolved
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/72 branch 2 times, most recently from 969a9bc to 3a09819 Compare July 11, 2023 18:41
@@ -62,6 +63,11 @@ pub(super) enum Expr {
},
Block(Block),
If(IfExpr),
Tuple(Vec<Expr>),
Copy link

Choose a reason for hiding this comment

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

is a tuple a kind of immediate or literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could have something more complex such as:

let tuple = (
    { ... }, // code block
    if cond { .. } else { .. }, // if expressions
    foo(), // function call,
    etc.
);

I suppose adding tests for these would be quite useful.

sezna
sezna previously approved these changes Jul 11, 2023
Copy link

@sezna sezna left a comment

Choose a reason for hiding this comment

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

approved but curious if a tuple could be a literal

Tuple indexing expressions are written as:

```ebnf
<tuple-index-expr> ::= <expr-atom> "." [0-9]+
Copy link
Contributor

Choose a reason for hiding this comment

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

What's an expr-atom? It can be any expression which has a tuple type, which might be a fn call, identifier or other tuple index. So it should just be expr?

Copy link
Contributor Author

@mohammadfawaz mohammadfawaz Jul 12, 2023

Choose a reason for hiding this comment

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

Yeah I will restructure this. See #99

yurtc/src/parser.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse tuple types, tuple literals, tuple expressions, and tuple indexing expressions
3 participants