mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Allow event/function definitions to be wrapped in directives.
This makes @if (conditions) event a(...) @else event b(...) @endif work, which threw an error in the past. This is useful when event definition change in newer Bro version and code wants to accept both kinds of events.
This commit is contained in:
parent
8d9408c795
commit
fb95a7750e
3 changed files with 41 additions and 0 deletions
|
@ -1142,9 +1142,16 @@ decl:
|
|||
| func_hdr func_body
|
||||
{ }
|
||||
|
||||
| func_hdr conditional_list func_body
|
||||
{ }
|
||||
|
||||
| conditional
|
||||
;
|
||||
|
||||
conditional_list:
|
||||
conditional
|
||||
| conditional conditional_list
|
||||
|
||||
conditional:
|
||||
TOK_ATIF '(' expr ')'
|
||||
{ do_atif($3); }
|
||||
|
|
3
testing/btest/Baseline/language.at-if-event/out
Normal file
3
testing/btest/Baseline/language.at-if-event/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
1
|
||||
2
|
||||
3
|
31
testing/btest/language/at-if-event.bro
Normal file
31
testing/btest/language/at-if-event.bro
Normal file
|
@ -0,0 +1,31 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
# Check if @if can be used to alternative function/event definitions
|
||||
|
||||
@if ( 1==1 )
|
||||
function test_case(msg: string)
|
||||
@else
|
||||
lalala
|
||||
@endif
|
||||
{
|
||||
print msg;
|
||||
}
|
||||
|
||||
@if ( 1==1 )
|
||||
event bro_init()
|
||||
@else
|
||||
lalala
|
||||
@endif
|
||||
{
|
||||
print "1";
|
||||
test_case("2");
|
||||
}
|
||||
|
||||
@if ( 1==0 )
|
||||
lalala
|
||||
@else
|
||||
event bro_init()
|
||||
@endif
|
||||
{
|
||||
print "3";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue