mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Introduce special treatment for the blank identifier _
Mostly: Do not instantiate variables within for loops and allow reusing differently typed blanks which previously wasn't possible. This may be missing some corner-cases, but the added tests seem to work as expected and nothing else fell apart it seems.
This commit is contained in:
parent
7f7c77ab07
commit
46334f8b59
21 changed files with 318 additions and 20 deletions
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-expr-errors.zeek, line 4: blank identifier used in expression (_)
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-expr-errors.zeek, line 6: blank identifier used in expression (MyModule::_)
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-expr-errors.zeek, line 11: blank identifier used in expression (MyModule::_)
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-expr-errors.zeek, line 6: blank identifier used in expression (MyModule::_)
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-expr-errors.zeek, line 9: blank identifier used in expression (_)
|
31
testing/btest/Baseline/language.blank-for/output
Normal file
31
testing/btest/Baseline/language.blank-for/output
Normal file
|
@ -0,0 +1,31 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
== vec 1
|
||||
a
|
||||
b
|
||||
c
|
||||
== vec 2
|
||||
idxsum(vec), 3
|
||||
== vec 3
|
||||
veclen(vec), 3
|
||||
== t1 1
|
||||
c
|
||||
b
|
||||
a
|
||||
== t1 2
|
||||
keyc
|
||||
keyb
|
||||
keya
|
||||
== t1 3
|
||||
t1len, 3
|
||||
== t2 1
|
||||
1, a1a
|
||||
3, c3c
|
||||
2, b2b
|
||||
== t2 2
|
||||
a, T
|
||||
c, T
|
||||
b, F
|
||||
== t2 3
|
||||
t2concat, a1ac3cb2b
|
||||
== s
|
||||
strlen(s), 10
|
1
testing/btest/Baseline/language.blank-local-2/.stderr
Normal file
1
testing/btest/Baseline/language.blank-local-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.
|
1
testing/btest/Baseline/language.blank-local-3/.stderr
Normal file
1
testing/btest/Baseline/language.blank-local-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.
|
1
testing/btest/Baseline/language.blank-local-4/.stderr
Normal file
1
testing/btest/Baseline/language.blank-local-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.
|
1
testing/btest/Baseline/language.blank-local/.stderr
Normal file
1
testing/btest/Baseline/language.blank-local/.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.
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/blank-option-error.zeek, line 9: blank identifier used as option (MyModule::_)
|
54
testing/btest/language/blank-expr-errors.zeek
Normal file
54
testing/btest/language/blank-expr-errors.zeek
Normal file
|
@ -0,0 +1,54 @@
|
|||
# @TEST-DOC: Do not allow to reference the blank identifier.
|
||||
|
||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
event zeek_init()
|
||||
{
|
||||
local vec = vector( "1", "2", "3" );
|
||||
for ( _, v in vec )
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure it does not work in a module, either.
|
||||
module MyModule;
|
||||
event zeek_init()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure _ can not referenced when it's a const in an export section.
|
||||
# Adding the const _ isn't an error though.
|
||||
module MyModule;
|
||||
|
||||
export {
|
||||
const _: count = 1;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print MyModule::_;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure it does not work in a function.
|
||||
module MyModule;
|
||||
function helper()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
helper();
|
||||
}
|
70
testing/btest/language/blank-for.zeek
Normal file
70
testing/btest/language/blank-for.zeek
Normal file
|
@ -0,0 +1,70 @@
|
|||
# @TEST-DOC: Some blank identifier tests iterating over vectors, tables and strings.
|
||||
# @TEST-EXEC: zeek -b %INPUT > output
|
||||
# @TEST-EXEC: btest-diff output
|
||||
event zeek_init()
|
||||
{
|
||||
local vec = vector("a", "b", "c");
|
||||
local t1 = table(["keya"] = "a", ["keyb"] = "b", ["keyc"] = "c");
|
||||
local t2 = table(["a",1,T] = "a1a", ["b",2,F] = "b2b", ["c",3,T] = "c3c");
|
||||
local s = "the string";
|
||||
|
||||
# Ignore just the index.
|
||||
print "== vec 1";
|
||||
for ( _, v in vec )
|
||||
print v;
|
||||
|
||||
# Ignore just the value.
|
||||
print "== vec 2";
|
||||
local idxsum = 0;
|
||||
for ( idx, _ in vec )
|
||||
idxsum += idx;
|
||||
print "idxsum(vec)", idxsum;
|
||||
|
||||
# Ignore index and value
|
||||
print "== vec 3";
|
||||
local veclen = 0;
|
||||
for ( _, _ in vec )
|
||||
++veclen;
|
||||
print "veclen(vec)", veclen;
|
||||
|
||||
# Ignore just the key
|
||||
print "== t1 1";
|
||||
for ( _, v in t1 )
|
||||
print v;
|
||||
|
||||
# Ignore just the value
|
||||
print "== t1 2";
|
||||
for ( k, _ in t1 )
|
||||
print k;
|
||||
|
||||
# Ignore index and value
|
||||
local t1len = 0;
|
||||
print "== t1 3";
|
||||
for ( _, _ in t1 )
|
||||
++t1len;
|
||||
print "t1len", t1len;
|
||||
|
||||
# Ignore part of the index and the value.
|
||||
print "== t2 1";
|
||||
for ( [_,c,_], v in t2 )
|
||||
print c, v;
|
||||
|
||||
# Ignore part of the index and the value.
|
||||
print "== t2 2";
|
||||
for ( [t2a,_,t2b], _ in t2 )
|
||||
print t2a, t2b;
|
||||
|
||||
# Ignore the whole index with a single _
|
||||
print "== t2 3";
|
||||
local t2concat = "";
|
||||
for ( _, v in t2 )
|
||||
t2concat += v;
|
||||
print "t2concat", t2concat;
|
||||
|
||||
# String iteration ignoring the value
|
||||
print "== s";
|
||||
local i = 0;
|
||||
for ( _ in s )
|
||||
++i;
|
||||
print "strlen(s)", i;
|
||||
}
|
29
testing/btest/language/blank-local.zeek
Normal file
29
testing/btest/language/blank-local.zeek
Normal file
|
@ -0,0 +1,29 @@
|
|||
# @TEST-DOC: Locals work with the blank identifier, but can not be referenced.
|
||||
|
||||
# @TEST-EXEC: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
event zeek_init()
|
||||
{
|
||||
local _ = "1";
|
||||
}
|
||||
|
||||
#@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local _: string = "1";
|
||||
local _: count = 1;
|
||||
}
|
||||
|
||||
#@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local _: string = "1";
|
||||
const _: count = 1;
|
||||
}
|
||||
|
||||
#@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
const _: string = "1";
|
||||
const _: count = 1;
|
||||
}
|
10
testing/btest/language/blank-option-error.zeek
Normal file
10
testing/btest/language/blank-option-error.zeek
Normal file
|
@ -0,0 +1,10 @@
|
|||
# @TEST-DOC: Do not allow blank options.
|
||||
|
||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
|
||||
module MyModule;
|
||||
|
||||
export {
|
||||
option _: count = 42;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue