mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/string-indexing'
* origin/topic/jsiwek/string-indexing: Change substring index notation to use a colon (addresses #422). Tweaked slightly to make it more generic, we may index other types with slices eventually too. Closes #422.
This commit is contained in:
commit
564e27abb6
7 changed files with 53 additions and 25 deletions
17
src/Expr.cc
17
src/Expr.cc
|
@ -2801,12 +2801,27 @@ 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_slice)
|
||||
: BinaryExpr(EXPR_INDEX, arg_op1, arg_op2)
|
||||
{
|
||||
if ( IsError() )
|
||||
return;
|
||||
|
||||
if ( is_slice )
|
||||
{
|
||||
if ( ! IsString(op1->Type()->Tag()) )
|
||||
ExprError("slice notation indexing only supported for strings currently");
|
||||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -646,7 +646,7 @@ protected:
|
|||
|
||||
class IndexExpr : public BinaryExpr {
|
||||
public:
|
||||
IndexExpr(Expr* op1, ListExpr* op2);
|
||||
IndexExpr(Expr* op1, ListExpr* op2, bool is_slice = false);
|
||||
|
||||
int CanAdd() const;
|
||||
int CanDel() const;
|
||||
|
|
|
@ -418,6 +418,14 @@ expr:
|
|||
$$ = new IndexExpr($1, $3);
|
||||
}
|
||||
|
||||
| expr '[' expr ':' expr ']'
|
||||
{
|
||||
set_location(@1, @6);
|
||||
ListExpr* le = new ListExpr($3);
|
||||
le->Append($5);
|
||||
$$ = new IndexExpr($1, le, true);
|
||||
}
|
||||
|
||||
| expr '$' TOK_ID
|
||||
{
|
||||
set_location(@1, @3);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue