mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Allow named record constructors. Addresses #983.
This commit is contained in:
parent
d67123d0c3
commit
a0ad87b4c2
6 changed files with 105 additions and 7 deletions
35
src/parse.y
35
src/parse.y
|
@ -522,10 +522,39 @@ expr:
|
|||
$$ = new VectorConstructorExpr($3);
|
||||
}
|
||||
|
||||
| expr '(' opt_expr_list ')'
|
||||
| expr '('
|
||||
{
|
||||
set_location(@1, @4);
|
||||
$$ = new CallExpr($1, $3, in_hook > 0);
|
||||
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
|
||||
++in_init;
|
||||
}
|
||||
opt_expr_list
|
||||
{
|
||||
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
|
||||
--in_init;
|
||||
}
|
||||
')'
|
||||
{
|
||||
set_location(@1, @6);
|
||||
|
||||
BroType* ctor_type = 0;
|
||||
|
||||
if ( $1->Tag() == EXPR_NAME &&
|
||||
(ctor_type = $1->AsNameExpr()->Id()->AsType()) )
|
||||
{
|
||||
switch ( ctor_type->Tag() ) {
|
||||
case TYPE_RECORD:
|
||||
$$ = new RecordConstructorExpr($4, ctor_type);
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
case TYPE_VECTOR:
|
||||
default:
|
||||
$1->Error("constructor type not implemented");
|
||||
YYERROR;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
$$ = new CallExpr($1, $4, in_hook > 0);
|
||||
}
|
||||
|
||||
| TOK_HOOK { ++in_hook; } expr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue