op-assign expansion now end at ']' and '}' too

This commit is contained in:
Celestino Amoroso 2024-07-24 06:37:57 +02:00
parent 1a1a475dd8
commit ffe1fa3aac
2 changed files with 4 additions and 3 deletions

View File

@ -510,8 +510,8 @@ func (parser *parser) expandOpAssign(scanner * scanner, tree *ast, tk *Token, al
if t, err = tree.addToken(NewToken(tk.row, tk.col, opSym, opString)); err == nil {
var subTree *ast
if subTree, err = parser.parseGeneral(scanner, false, allowVarRef, SymSemiColon, SymClosedRound); err == nil {
if scanner.Previous().IsOneOfA(SymSemiColon, SymClosedRound) {
if subTree, err = parser.parseGeneral(scanner, false, allowVarRef, SymSemiColon, SymClosedRound, SymClosedBrace, SymClosedSquare); err == nil {
if scanner.Previous().IsOneOfA(SymSemiColon, SymClosedRound, SymClosedBrace, SymClosedSquare) {
if err = scanner.UnreadToken(); err != nil {
return
}

View File

@ -27,7 +27,8 @@ func TestExpr(t *testing.T) {
/* 13 */ {`a=3; a*=2+1; a`, int64(9), nil},
/* 14 */ {`a=3; (a*=2)+1; a`, int64(6), nil},
/* 15 */ {`a=3; a*=2)+1; a`, nil, `[1:11] unexpected token ")"`},
/* 16 */ {`
/* 16 */ {`v=[2]; a=1; v[a-=1]=5; v[0]`, int64(5), nil},
/* 17 */ {`
ds={
"init":func(@end){@current=0 but true},
//"current":func(){current},