mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
Change substring index notation to use a colon (addresses #422).
String slice notation is written as `s[1:2]` instead of `s[1, 2]` because the later is ambiguous with composite index types.
This commit is contained in:
parent
e638f04301
commit
8b46bbb1c0
5 changed files with 46 additions and 24 deletions
16
src/Expr.cc
16
src/Expr.cc
|
@ -2801,12 +2801,26 @@ bool AssignExpr::DoUnserialize(UnserialInfo* info)
|
|||
return UNSERIALIZE(&is_init);
|
||||
}
|
||||
|
||||
IndexExpr::IndexExpr(Expr* arg_op1, ListExpr* arg_op2)
|
||||
IndexExpr::IndexExpr(Expr* arg_op1, ListExpr* arg_op2, bool is_string_slice)
|
||||
: BinaryExpr(EXPR_INDEX, arg_op1, arg_op2)
|
||||
{
|
||||
if ( IsError() )
|
||||
return;
|
||||
|
||||
if ( is_string_slice )
|
||||
{
|
||||
if ( ! IsString(op1->Type()->Tag()) )
|
||||
ExprError("slice notation indexing can apply only to strings");
|
||||
}
|
||||
else if ( IsString(op1->Type()->Tag()) )
|
||||
{
|
||||
if ( arg_op2->Exprs().length() != 1 )
|
||||
ExprError("invalid string index expression");
|
||||
}
|
||||
|
||||
if ( IsError() )
|
||||
return;
|
||||
|
||||
int match_type = op1->Type()->MatchesIndex(arg_op2);
|
||||
if ( match_type == DOES_NOT_MATCH_INDEX )
|
||||
SetError("not an index type");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue