mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/2075-if-conditional-parsing'
* origin/topic/awelzel/2075-if-conditional-parsing: parse.y/anonymous_function: Allow conditionals between begin_lambda and lambda_body
This commit is contained in:
commit
8829490045
12 changed files with 130 additions and 3 deletions
7
CHANGES
7
CHANGES
|
@ -1,3 +1,10 @@
|
|||
5.1.0-dev.439 | 2022-08-23 20:28:05 -0700
|
||||
|
||||
* parse.y/anonymous_function: Allow conditionals between begin_lambda and lambda_body (Arne Welzel, Corelight)
|
||||
|
||||
This is to allow conditional statements following a lambda header
|
||||
(begin_lambda) just as is done with func_hdr conditional_list func_body.
|
||||
|
||||
5.1.0-dev.436 | 2022-08-23 10:19:23 -0700
|
||||
|
||||
* Deprecate misc/scan.zeek (Arne Welzel, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
5.1.0-dev.436
|
||||
5.1.0-dev.439
|
||||
|
|
|
@ -1531,8 +1531,8 @@ lambda_body:
|
|||
;
|
||||
|
||||
anonymous_function:
|
||||
TOK_FUNCTION begin_lambda lambda_body
|
||||
{ $$ = $3; }
|
||||
TOK_FUNCTION begin_lambda conditional_list lambda_body
|
||||
{ $$ = $4; }
|
||||
;
|
||||
|
||||
begin_lambda:
|
||||
|
|
1
testing/btest/Baseline/language.at-if-lambda-2/.stderr
Normal file
1
testing/btest/Baseline/language.at-if-lambda-2/.stderr
Normal file
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
3
testing/btest/Baseline/language.at-if-lambda-2/.stdout
Normal file
3
testing/btest/Baseline/language.at-if-lambda-2/.stdout
Normal file
|
@ -0,0 +1,3 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
cookie
|
||||
function(pass_name:string;) : function(ts:time;) : time, function(ts:time;) : time, time, 1660671192.0
|
1
testing/btest/Baseline/language.at-if-lambda-3/.stderr
Normal file
1
testing/btest/Baseline/language.at-if-lambda-3/.stderr
Normal file
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
2
testing/btest/Baseline/language.at-if-lambda-3/.stdout
Normal file
2
testing/btest/Baseline/language.at-if-lambda-3/.stdout
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
function(ts_str:string;) : time, time, 1660671192.0
|
1
testing/btest/Baseline/language.at-if-lambda-4/.stderr
Normal file
1
testing/btest/Baseline/language.at-if-lambda-4/.stderr
Normal file
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
2
testing/btest/Baseline/language.at-if-lambda-4/.stdout
Normal file
2
testing/btest/Baseline/language.at-if-lambda-4/.stdout
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
function(ts_str:string; offset:count &default=10, &optional;) : time, time, 1660671202.0
|
1
testing/btest/Baseline/language.at-if-lambda/.stderr
Normal file
1
testing/btest/Baseline/language.at-if-lambda/.stderr
Normal file
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
3
testing/btest/Baseline/language.at-if-lambda/.stdout
Normal file
3
testing/btest/Baseline/language.at-if-lambda/.stdout
Normal file
|
@ -0,0 +1,3 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
cookie
|
||||
function(pass_name:string;) : function(ts:time;) : time, function(ts:time;) : time, time, 1660671192.0
|
106
testing/btest/language/at-if-lambda.zeek
Normal file
106
testing/btest/language/at-if-lambda.zeek
Normal file
|
@ -0,0 +1,106 @@
|
|||
# @TEST-DOC: Regression test for #2075 from 0xxon
|
||||
# @TEST-EXEC: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER= btest-diff .stdout
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER= btest-diff .stderr
|
||||
|
||||
@load base/misc/version
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
local make_epoch_result = function(pass_name: string): function(ts: time): time
|
||||
{
|
||||
@if ( Version::at_least("4.1") )
|
||||
return function [pass_name] (ts: time): time
|
||||
@else
|
||||
return function (ts: time)
|
||||
@endif
|
||||
{
|
||||
print pass_name;
|
||||
return ts;
|
||||
};
|
||||
};
|
||||
|
||||
local ts = double_to_time(1660671192.0);
|
||||
local f = make_epoch_result("cookie");
|
||||
local result = f(ts);
|
||||
print type_name(make_epoch_result), type_name(f), type_name(result), result;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Place braces differently
|
||||
|
||||
@load base/misc/version
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
local make_epoch_result = function(pass_name: string): function(ts: time): time
|
||||
{
|
||||
@if ( Version::at_least("4.1") )
|
||||
return function [pass_name] (ts: time): time {
|
||||
@else
|
||||
return function (ts: time) {
|
||||
@endif
|
||||
print pass_name;
|
||||
return ts;
|
||||
};
|
||||
};
|
||||
|
||||
local ts = double_to_time(1660671192.0);
|
||||
local f = make_epoch_result("cookie");
|
||||
local result = f(ts);
|
||||
print type_name(make_epoch_result), type_name(f), type_name(result), result;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# This example doesn't make a whole lot of sense, but adding more @ifdef'ery
|
||||
# around lambdas.
|
||||
|
||||
@load base/misc/version
|
||||
@load base/utils/numbers
|
||||
|
||||
global toggle = F;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
@if ( toggle )
|
||||
local f = function(ts_str: string, offset: count &default=10): time
|
||||
@else
|
||||
local f = function(ts_str: string): time
|
||||
@endif
|
||||
{
|
||||
local c = extract_count(ts_str);
|
||||
@if ( toggle )
|
||||
c += offset;
|
||||
@endif
|
||||
return double_to_time(c);
|
||||
};
|
||||
|
||||
local result = f("1660671192.0");
|
||||
print type_name(f), type_name(result), result;
|
||||
}
|
||||
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Same as above, but toggle T
|
||||
@load base/utils/numbers
|
||||
|
||||
global toggle = T;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
@if ( toggle )
|
||||
local f = function(ts_str: string, offset: count &default=10): time
|
||||
@else
|
||||
local f = function(ts_str: string): time
|
||||
@endif
|
||||
{
|
||||
local c = extract_count(ts_str);
|
||||
@if ( toggle )
|
||||
c += offset;
|
||||
@endif
|
||||
return double_to_time(c);
|
||||
};
|
||||
|
||||
local result = f("1660671192.0");
|
||||
print type_name(f), type_name(result), result;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue