mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Support omission of string slice low/high indices, BIT-1097.
Omission of the low index defaults to 0: s = "12345"; s[:3] == "123" Omission of the high index defaults to length of the string: s = "12345"; s[3:] == "45"
This commit is contained in:
parent
4014cdc277
commit
8515d3aa57
3 changed files with 56 additions and 4 deletions
17
src/parse.y
17
src/parse.y
|
@ -55,7 +55,7 @@
|
|||
%type <expr> opt_init
|
||||
%type <val> TOK_CONSTANT
|
||||
%type <re> pattern
|
||||
%type <expr> expr init anonymous_function
|
||||
%type <expr> expr opt_expr init anonymous_function
|
||||
%type <event_expr> event
|
||||
%type <stmt> stmt stmt_list func_body for_head
|
||||
%type <type> type opt_type enum_body
|
||||
|
@ -261,6 +261,13 @@ decl_list:
|
|||
|
|
||||
;
|
||||
|
||||
opt_expr:
|
||||
expr
|
||||
{ $$ = $1; }
|
||||
|
|
||||
{ $$ = 0; }
|
||||
;
|
||||
|
||||
expr:
|
||||
'(' expr ')'
|
||||
{
|
||||
|
@ -418,11 +425,13 @@ expr:
|
|||
$$ = new IndexExpr($1, $3);
|
||||
}
|
||||
|
||||
| expr '[' expr ':' expr ']'
|
||||
| expr '[' opt_expr ':' opt_expr ']'
|
||||
{
|
||||
set_location(@1, @6);
|
||||
ListExpr* le = new ListExpr($3);
|
||||
le->Append($5);
|
||||
Expr* low = $3 ? $3 : new ConstExpr(new Val(0, TYPE_COUNT));
|
||||
Expr* high = $5 ? $5 : new SizeExpr($1);
|
||||
ListExpr* le = new ListExpr(low);
|
||||
le->Append(high);
|
||||
$$ = new IndexExpr($1, le, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue