mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Fix parsing of "local" named table constructors.
This commit is contained in:
parent
b1fd161274
commit
bf3c3887fd
3 changed files with 33 additions and 7 deletions
20
src/parse.y
20
src/parse.y
|
@ -207,6 +207,22 @@ static void extend_record(ID* id, type_decl_list* fields, attr_list* attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool expr_is_table_type_name(const Expr* expr)
|
||||||
|
{
|
||||||
|
if ( expr->Tag() != EXPR_NAME )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BroType* type = expr->Type();
|
||||||
|
|
||||||
|
if ( type->IsTable() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( type->Tag() == TYPE_TYPE )
|
||||||
|
return type->AsTypeType()->Type()->IsTable();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
|
@ -538,13 +554,13 @@ expr:
|
||||||
|
|
||||||
| expr '('
|
| expr '('
|
||||||
{
|
{
|
||||||
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
|
if ( expr_is_table_type_name($1) )
|
||||||
++in_init;
|
++in_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_expr_list
|
opt_expr_list
|
||||||
{
|
{
|
||||||
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
|
if ( expr_is_table_type_name($1) )
|
||||||
--in_init;
|
--in_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,7 @@
|
||||||
[three] = 3.0
|
[three] = 3.0
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
|
{
|
||||||
|
[42] = forty-two,
|
||||||
|
[37] = thirty-seven
|
||||||
|
}
|
||||||
|
|
|
@ -17,8 +17,14 @@ global mytablecomp: FooTableComp = FooTableComp(["test", 1] = "test1", ["cool",
|
||||||
2] = "cool2");
|
2] = "cool2");
|
||||||
global mytabley: FooTableY = FooTableY(["one"] = 1, ["two"] = 2, ["three"] = 3) &default=0;
|
global mytabley: FooTableY = FooTableY(["one"] = 1, ["two"] = 2, ["three"] = 3) &default=0;
|
||||||
|
|
||||||
print mytable;
|
event bro_init()
|
||||||
print mytablerec;
|
{
|
||||||
print mytablecomp;
|
print mytable;
|
||||||
print mytabley;
|
print mytablerec;
|
||||||
print mytabley["test"];
|
print mytablecomp;
|
||||||
|
print mytabley;
|
||||||
|
print mytabley["test"];
|
||||||
|
|
||||||
|
local loctable = FooTable([42] = "forty-two", [37] = "thirty-seven");
|
||||||
|
print loctable;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue