@@ -1444,68 +1444,6 @@ local function parseNameOrList(parent)
14441444 return list or first
14451445end
14461446
1447- local function dropTail ()
1448- local token = Tokens [Index + 1 ]
1449- if token ~= ' ?'
1450- and token ~= ' :' then
1451- return
1452- end
1453- local pl , pt , pp = 0 , 0 , 0
1454- while true do
1455- local token = Tokens [Index + 1 ]
1456- if not token then
1457- break
1458- end
1459- if NLMap [token ] then
1460- break
1461- end
1462- if token == ' ,' then
1463- if pl > 0
1464- or pt > 0
1465- or pp > 0 then
1466- goto CONTINUE
1467- else
1468- break
1469- end
1470- end
1471- if token == ' <' then
1472- pl = pl + 1
1473- goto CONTINUE
1474- end
1475- if token == ' {' then
1476- pt = pt + 1
1477- goto CONTINUE
1478- end
1479- if token == ' (' then
1480- pp = pp + 1
1481- goto CONTINUE
1482- end
1483- if token == ' >' then
1484- if pl <= 0 then
1485- break
1486- end
1487- pl = pl - 1
1488- goto CONTINUE
1489- end
1490- if token == ' }' then
1491- if pt <= 0 then
1492- break
1493- end
1494- pt = pt - 1
1495- goto CONTINUE
1496- end
1497- if token == ' )' then
1498- if pp <= 0 then
1499- break
1500- end
1501- pp = pp - 1
1502- goto CONTINUE
1503- end
1504- :: CONTINUE::
1505- Index = Index + 2
1506- end
1507- end
1508-
15091447local function parseExpList (mini )
15101448 local list
15111449 local wantSep = false
@@ -1552,7 +1490,6 @@ local function parseExpList(mini)
15521490 if not exp then
15531491 break
15541492 end
1555- dropTail ()
15561493 if wantSep then
15571494 missSymbol (' ,' , list [# list ].finish , exp .start )
15581495 end
@@ -2379,6 +2316,27 @@ local function parseFunction(isLocal, isAction)
23792316 return func
23802317end
23812318
2319+ local function pushErrorNeedParen (source )
2320+ pushError {
2321+ type = ' NEED_PAREN' ,
2322+ start = source .start ,
2323+ finish = source .finish ,
2324+ fix = {
2325+ title = ' FIX_ADD_PAREN' ,
2326+ {
2327+ start = source .start ,
2328+ finish = source .start ,
2329+ text = ' (' ,
2330+ },
2331+ {
2332+ start = source .finish ,
2333+ finish = source .finish ,
2334+ text = ' )' ,
2335+ }
2336+ }
2337+ }
2338+ end
2339+
23822340local function parseExpUnit ()
23832341 local token = Tokens [Index + 1 ]
23842342 if token == ' (' then
@@ -2393,17 +2351,38 @@ local function parseExpUnit()
23932351
23942352 if token == ' {' then
23952353 local table = parseTable ()
2354+ if not table then
2355+ return nil
2356+ end
2357+ local exp = parseSimple (table , false )
2358+ if exp ~= table then
2359+ pushErrorNeedParen (table )
2360+ end
23962361 return table
23972362 end
23982363
23992364 if CharMapStrSH [token ] then
24002365 local string = parseShortString ()
2401- return string
2366+ if not string then
2367+ return nil
2368+ end
2369+ local exp = parseSimple (string , false )
2370+ if exp ~= string then
2371+ pushErrorNeedParen (string )
2372+ end
2373+ return exp
24022374 end
24032375
24042376 if CharMapStrLH [token ] then
24052377 local string = parseLongString ()
2406- return string
2378+ if not string then
2379+ return nil
2380+ end
2381+ local exp = parseSimple (string , false )
2382+ if exp ~= string then
2383+ pushErrorNeedParen (string )
2384+ end
2385+ return exp
24072386 end
24082387
24092388 local number = parseNumber ()
0 commit comments