mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Add support for _ placeholder. (#661)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
c3c89a77a4
commit
def98d1182
@@ -56,6 +56,7 @@ CONTINUATION_TYPE "__Continuation"
|
||||
CONTINUATION "__continuation"
|
||||
RUN "__run"
|
||||
AWAIT "__await"
|
||||
UNDERSCORE "_"
|
||||
|
||||
identifier [A-Za-z_][A-Za-z0-9_]*
|
||||
integer_literal [0-9]+
|
||||
@@ -116,6 +117,7 @@ operand_start [(A-Za-z0-9_"]
|
||||
{CONTINUATION} { return yy::parser::make_CONTINUATION(context.current_token_position); }
|
||||
{RUN} { return yy::parser::make_RUN(context.current_token_position); }
|
||||
{AWAIT} { return yy::parser::make_AWAIT(context.current_token_position); }
|
||||
{UNDERSCORE} { return yy::parser::make_UNDERSCORE(context.current_token_position); }
|
||||
|
||||
"=" return yy::parser::make_EQUAL(context.current_token_position);
|
||||
"-" return yy::parser::make_MINUS(context.current_token_position);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user