mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
parse.y/directives: Reject directives as statements
Avoid the issue outlined in #2289 where the @if or @else is taken as the statement of an `if`, `for` or `while` by rejecting such constructs. Effectively this means the following scripts are now rejected: # Print's "cond true" with Zeek 5.0 even though the `if ( F )` # should be in effect. if ( F ) @if ( T ) print "cond true"; @else print "cond false"; @endif or # Print's "hello" once with Zeek 5.0 local v = vector( 1, 2, 3 ); for ( i in v ) @if ( T ) print("hello") @endif To make above work as intended, additional braces can be used. if ( T ) { @if ( cond ) print "cond true"; @else print "cond false"; @endif } for ( i in v ) { @if ( T ) print("hello") @endif }
This commit is contained in:
parent
6721248da5
commit
171846a37a
16 changed files with 124 additions and 2 deletions
|
@ -847,6 +847,14 @@ void do_atendif()
|
|||
--conditional_depth;
|
||||
}
|
||||
|
||||
// If the given Stmt is a directive, trigger an error so that its usage is rejected.
|
||||
void reject_directive(zeek::detail::Stmt* s)
|
||||
{
|
||||
if ( s->Tag() == STMT_NULL )
|
||||
if ( s->AsNullStmt()->IsDirective() )
|
||||
zeek::reporter->Error("incorrect use of directive");
|
||||
}
|
||||
|
||||
// Be careful to never delete things from this list, as the strings
|
||||
// are referred to (in order to save the locations of tokens and statements,
|
||||
// for error reporting and debugging).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue