mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/string-slicing-fix'
* origin/topic/jsiwek/string-slicing-fix: Support omission of string slice low/high indices, BIT-1097.
This commit is contained in:
commit
81096820f3
3 changed files with 56 additions and 4 deletions
17
src/parse.y
17
src/parse.y
|
@ -52,7 +52,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
|
||||
|
@ -265,6 +265,13 @@ decl_list:
|
|||
|
|
||||
;
|
||||
|
||||
opt_expr:
|
||||
expr
|
||||
{ $$ = $1; }
|
||||
|
|
||||
{ $$ = 0; }
|
||||
;
|
||||
|
||||
expr:
|
||||
'(' expr ')'
|
||||
{
|
||||
|
@ -422,11 +429,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,41 @@ word[5] =
|
|||
word[6] =
|
||||
word[7] =
|
||||
word[100] =
|
||||
word[:-100] =
|
||||
word[:-7] =
|
||||
word[:-6] =
|
||||
word[:-5] =
|
||||
word[:-4] = H
|
||||
word[:-3] = He
|
||||
word[:-2] = Hel
|
||||
word[:-1] = Help
|
||||
word[:0] =
|
||||
word[:1] = H
|
||||
word[:2] = He
|
||||
word[:3] = Hel
|
||||
word[:4] = Help
|
||||
word[:5] = HelpA
|
||||
word[:6] = HelpA
|
||||
word[:7] = HelpA
|
||||
word[:100] = HelpA
|
||||
word[-100:] = HelpA
|
||||
word[-7:] = HelpA
|
||||
word[-6:] = HelpA
|
||||
word[-5:] = HelpA
|
||||
word[-4:] = elpA
|
||||
word[-3:] = lpA
|
||||
word[-2:] = pA
|
||||
word[-1:] = A
|
||||
word[0:] = HelpA
|
||||
word[1:] = elpA
|
||||
word[2:] = lpA
|
||||
word[3:] = pA
|
||||
word[4:] = A
|
||||
word[5:] =
|
||||
word[6:] =
|
||||
word[7:] =
|
||||
word[100:] =
|
||||
HelpA
|
||||
|
||||
A
|
||||
1234
|
||||
|
|
|
@ -24,6 +24,14 @@ s = "012345";
|
|||
for ( i in indices )
|
||||
print fmt("word[%s] = %s", indices[i], word[indices[i]]);
|
||||
|
||||
for ( i in indices )
|
||||
print fmt("word[:%s] = %s", indices[i], word[:indices[i]]);
|
||||
|
||||
for ( i in indices )
|
||||
print fmt("word[%s:] = %s", indices[i], word[indices[i]:]);
|
||||
|
||||
print word[:];
|
||||
|
||||
print "";
|
||||
|
||||
print "A";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue