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

Updating tuples spec with grammar #11271

Merged
merged 11 commits into from
May 12, 2016
Merged
Changes from 10 commits
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
62 changes: 62 additions & 0 deletions docs/features/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,65 @@ M1((1, ()=>(2, 3))); // the first overload is used due to "exact match"

```

Language grammar changes
Copy link
Member

Choose a reason for hiding this comment

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

Ultimately I think you want to integrate the related sections of the spec. That is, for each context integrate the syntax, semantics, and dynamic semantics, rather than having the prose above and syntax below without relating them to each other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree.

---------------------
This is based on the [ANTLR grammar](https://raw.githubusercontent.com/ljw1004/csharpspec/gh-pages/csharp.g4) from Lucian.

For tuple type declarations:

```ANTLR
struct_type
: type_name
| simple_type
| nullable_type
| tuple_type // new
;

tuple_type
: '(' tuple_type_element_list ')'
;

tuple_type_element_list
: tuple_type_element ',' tuple_type_element
| tuple_type_element_list ',' tuple_type_element
;

tuple_type_element
: type_parameter identifier?
Copy link
Member

@gafter gafter May 12, 2016

Choose a reason for hiding this comment

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

I think this should be type identifier? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Thanks

;
```

For tuple literals:

```ANTLR
literal
: boolean_literal
| integer_literal
| real_literal
| character_literal
| string_literal
| null_literal
| tuple_literal // new
;

tuple_literal
: '(' tuple_literal_element_list ')'
;

tuple_literal_element_list
: tuple_literal_element ',' tuple_literal_element
| tuple_literal_element_list ',' tuple_literal_element
;

tuple_literal_element
: ( identifier ':' )? literal
Copy link
Member

@gafter gafter May 12, 2016

Choose a reason for hiding this comment

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

I think literal here should be expression. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I'll fix.

;
```

A tuple literal cannot be used as default value for an optional parameter.
Copy link
Member

@gafter gafter May 12, 2016

Choose a reason for hiding this comment

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

This is non-normative (it is implied by rules elsewhere), so perhaps precede by "Because it is not a constant expression, " #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that was the reason (not a constant). I'll add a note.


Open issues:
-----------

- Provide more details on semantics of tuple type declarations, both static (Type rules, constraints, all-or-none names, can't be used on right-hand-side of a 'is', ...) and dynamic (what does it do at runtime?).
- Provide more details on semantics of tuple literals, both static (new kind of conversion from expression, new kind of conversion from type, all-or-none, scrambled names, underlying types, underlying names, listing the members of this type, what it means to access, ) and dynamic (what happens when you do this conversion?).
Copy link
Member

@gafter gafter May 12, 2016

Choose a reason for hiding this comment

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

Please add "exactly matching expression" to this list. I suggest the checkbox syntax to list them

  • CheckboxItem
    #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Done