Add support for _ placeholder. (#661)

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
Geoff Romer
2021-07-19 10:33:06 -07:00
committed by GitHub
co-authored by Jon Meow
parent c3c89a77a4
commit def98d1182
15 changed files with 88 additions and 20 deletions
+7 -1
View File
@@ -104,6 +104,7 @@ void yy::parser::error(
%type <const Carbon::Expression*> return_type
%type <const Carbon::Expression*> paren_expression
%type <const Carbon::Expression*> tuple
%type <std::optional<std::string>> binding_lhs
%type <Carbon::Member*> variable_declaration
%type <Carbon::Member*> member
%type <std::list<Carbon::Member*>> member_list
@@ -146,6 +147,7 @@ void yy::parser::error(
%token DBLARROW "=>"
%token DEFAULT
%token AUTO
%token UNDERSCORE
%token
EQUAL "="
MINUS "-"
@@ -199,6 +201,10 @@ pattern:
expression
{ $$ = $1; }
;
binding_lhs:
identifier { $$ = $1; }
| UNDERSCORE { $$ = std::nullopt; }
;
expression:
identifier
{ $$ = Carbon::Expression::MakeIdentifierExpression(yylineno, $1); }
@@ -206,7 +212,7 @@ expression:
{ $$ = Carbon::Expression::MakeFieldAccessExpression(yylineno, $1, $2); }
| expression "[" expression "]"
{ $$ = Carbon::Expression::MakeIndexExpression(yylineno, $1, $3); }
| identifier ":" expression
| binding_lhs ":" expression
{
$$ = Carbon::Expression::MakeBindingExpression(yylineno, $1, $3);
}