mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:11:04 +01:00
Update executable semantics for choice to match final state of p0157 (#304)
* Make parentheses optional for alternatives with no arguments. * Use `,` instead of `;` as separator for alternatives, and make the trailing separator optional.
This commit is contained in:
@@ -289,14 +289,26 @@ member_list:
|
||||
{ $$ = $2; $$->push_front($1); }
|
||||
;
|
||||
alternative:
|
||||
identifier tuple ';'
|
||||
identifier tuple
|
||||
{ $$ = new std::pair<std::string, Carbon::Expression*>($1, $2); }
|
||||
| identifier
|
||||
{
|
||||
$$ = new std::pair<std::string, Carbon::Expression*>(
|
||||
$1, Carbon::MakeTuple(
|
||||
yylineno,
|
||||
new std::vector<std::pair<std::string, Carbon::Expression*>>()));
|
||||
}
|
||||
;
|
||||
alternative_list:
|
||||
// Empty
|
||||
{ $$ = new std::list<std::pair<std::string, Carbon::Expression*>>(); }
|
||||
| alternative alternative_list
|
||||
{ $$ = $2; $$->push_front(*$1); }
|
||||
| alternative
|
||||
{
|
||||
$$ = new std::list<std::pair<std::string, Carbon::Expression*>>();
|
||||
$$->push_front(*$1);
|
||||
}
|
||||
| alternative ',' alternative_list
|
||||
{ $$ = $3; $$->push_front(*$1); }
|
||||
;
|
||||
declaration:
|
||||
function_definition
|
||||
|
||||
+4
-4
@@ -3,9 +3,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
choice Ints {
|
||||
None();
|
||||
One(Int);
|
||||
Two(Int,Int);
|
||||
None,
|
||||
One(Int),
|
||||
Two(Int,Int)
|
||||
}
|
||||
|
||||
fn main() -> Int {
|
||||
@@ -13,7 +13,7 @@ fn main() -> Int {
|
||||
var auto: y = Ints.One(42);
|
||||
var auto: n = 0;
|
||||
match (y) {
|
||||
case Ints.None() =>
|
||||
case Ints.None =>
|
||||
n = n + 2;
|
||||
case Ints.One(auto: x) =>
|
||||
n = x + 1 - 42;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ var auto: x = Ints.None();
|
||||
var auto: y = Ints.One(0 = 42);
|
||||
var auto: n = 0;
|
||||
match (y) {
|
||||
case Ints.None() =>
|
||||
case Ints.None =>
|
||||
n = (n + 2);
|
||||
case Ints.One(0 = auto: x) =>
|
||||
n = ((x + 1) - 42);
|
||||
|
||||
Reference in New Issue
Block a user