@@ -816,6 +816,7 @@ local function resolveLable(label, obj)
816
816
end
817
817
end
818
818
819
+ --- @param gotos parser.object.goto[]
819
820
local function resolveGoTo (gotos )
820
821
for i = 1 , # gotos do
821
822
local action = gotos [i ]
@@ -848,6 +849,7 @@ local function popChunk()
848
849
Chunk [# Chunk ] = nil
849
850
end
850
851
852
+ --- @return parser.object.nil ?
851
853
local function parseNil ()
852
854
if Tokens [Index + 1 ] ~= ' nil' then
853
855
return nil
@@ -861,6 +863,7 @@ local function parseNil()
861
863
}
862
864
end
863
865
866
+ --- @return parser.object.boolean ?
864
867
local function parseBoolean ()
865
868
local word = Tokens [Index + 1 ]
866
869
if word ~= ' true'
@@ -1342,6 +1345,7 @@ local function dropNumberTail(offset, integer)
1342
1345
return finish + 1
1343
1346
end
1344
1347
1348
+ --- @return (parser.object.number | parser.object.integer )?
1345
1349
local function parseNumber ()
1346
1350
local offset = Tokens [Index ]
1347
1351
if not offset then
@@ -1379,6 +1383,7 @@ local function parseNumber()
1379
1383
if neg then
1380
1384
number = - number
1381
1385
end
1386
+ --- @type parser.object.number | parser.object.integer
1382
1387
local result = {
1383
1388
type = integer and ' integer' or ' number' ,
1384
1389
start = startPos ,
@@ -1412,6 +1417,7 @@ local function isKeyWord(word, nextToken)
1412
1417
return false
1413
1418
end
1414
1419
1420
+ --- @return parser.object.name ?
1415
1421
local function parseName (asAction )
1416
1422
local word = peekWord ()
1417
1423
if not word then
@@ -1552,11 +1558,13 @@ local function parseExpList(mini)
1552
1558
return list
1553
1559
end
1554
1560
1561
+ --- @return parser.object.index
1555
1562
local function parseIndex ()
1556
1563
local start = getPosition (Tokens [Index ], ' left' )
1557
1564
Index = Index + 2
1558
1565
skipSpace ()
1559
1566
local exp = parseExp ()
1567
+ --- @type parser.object.index
1560
1568
local index = {
1561
1569
type = ' index' ,
1562
1570
start = start ,
@@ -1578,13 +1586,18 @@ local function parseIndex()
1578
1586
return index
1579
1587
end
1580
1588
1589
+ --- @return parser.object.table
1581
1590
local function parseTable ()
1591
+ local start = getPosition (Tokens [Index ], ' left' )
1592
+ local finish = getPosition (Tokens [Index ], ' right' )
1593
+ --- @type parser.object.table
1582
1594
local tbl = {
1583
1595
type = ' table' ,
1584
- start = getPosition (Tokens [Index ], ' left' ),
1585
- finish = getPosition (Tokens [Index ], ' right' ),
1596
+ start = start ,
1597
+ finish = finish ,
1598
+ bstart = finish ,
1599
+ bfinish = finish ,
1586
1600
}
1587
- tbl .bstart = tbl .finish
1588
1601
Index = Index + 2
1589
1602
local index = 0
1590
1603
local tindex = 0
@@ -1624,6 +1637,7 @@ local function parseTable()
1624
1637
wantSep = true
1625
1638
skipSpace ()
1626
1639
local fvalue = parseExp ()
1640
+ --- @type parser.object.tablefield
1627
1641
local tfield = {
1628
1642
type = ' tablefield' ,
1629
1643
start = name .start ,
@@ -1634,8 +1648,9 @@ local function parseTable()
1634
1648
field = name ,
1635
1649
value = fvalue ,
1636
1650
}
1637
- name .type = ' field'
1638
- name .parent = tfield
1651
+ local field = name --[[ @as parser.object.field]]
1652
+ field .type = ' field'
1653
+ field .parent = tfield
1639
1654
if fvalue then
1640
1655
fvalue .parent = tfield
1641
1656
else
@@ -1667,6 +1682,7 @@ local function parseTable()
1667
1682
end
1668
1683
index = index + 1
1669
1684
tindex = tindex + 1
1685
+ --- @type parser.object.tableexp
1670
1686
local texp = {
1671
1687
type = ' tableexp' ,
1672
1688
start = exp .start ,
@@ -1689,7 +1705,7 @@ local function parseTable()
1689
1705
}
1690
1706
end
1691
1707
wantSep = true
1692
- local tindex = parseIndex ()
1708
+ local tindex = parseIndex () --[[ @as parser.object.tableindex ]]
1693
1709
skipSpace ()
1694
1710
tindex .type = ' tableindex'
1695
1711
tindex .node = tbl
@@ -1803,7 +1819,12 @@ local function parseSimple(node, funcName)
1803
1819
}
1804
1820
Index = Index + 2
1805
1821
skipSpace ()
1806
- local field = parseName (true )
1822
+ local field = parseName (true ) --[[ @as parser.object.field?]]
1823
+ if field then
1824
+ field .type = ' field'
1825
+ end
1826
+
1827
+ --- @type parser.object.getfield
1807
1828
local getfield = {
1808
1829
type = ' getfield' ,
1809
1830
start = node .start ,
@@ -1814,7 +1835,6 @@ local function parseSimple(node, funcName)
1814
1835
}
1815
1836
if field then
1816
1837
field .parent = getfield
1817
- field .type = ' field'
1818
1838
if currentName then
1819
1839
if node .type == ' getlocal'
1820
1840
or node .type == ' getglobal'
@@ -1843,7 +1863,8 @@ local function parseSimple(node, funcName)
1843
1863
}
1844
1864
Index = Index + 2
1845
1865
skipSpace ()
1846
- local method = parseName (true )
1866
+ local method = parseName (true ) --[[ @as parser.object.method?]]
1867
+ --- @type parser.object.getmethod
1847
1868
local getmethod = {
1848
1869
type = ' getmethod' ,
1849
1870
start = node .start ,
@@ -1904,12 +1925,14 @@ local function parseSimple(node, funcName)
1904
1925
break
1905
1926
end
1906
1927
local tbl = parseTable ()
1928
+ --- @type parser.object.call
1907
1929
local call = {
1908
1930
type = ' call' ,
1909
1931
start = node .start ,
1910
1932
finish = tbl .finish ,
1911
1933
node = node ,
1912
1934
}
1935
+ --- @type parser.object.callargs
1913
1936
local args = {
1914
1937
type = ' callargs' ,
1915
1938
start = tbl .start ,
@@ -1970,7 +1993,7 @@ local function parseSimple(node, funcName)
1970
1993
node .parent = call
1971
1994
node = call
1972
1995
else
1973
- local index = parseIndex ()
1996
+ local index = parseIndex () --[[ @as parser.object.getindex ]]
1974
1997
local bstart = index .start
1975
1998
index .type = ' getindex'
1976
1999
index .start = node .start
@@ -2279,6 +2302,7 @@ local function parseParams(params, isLambda)
2279
2302
return params
2280
2303
end
2281
2304
2305
+ --- @return parser.object.function
2282
2306
local function parseFunction (isLocal , isAction )
2283
2307
local funcLeft = getPosition (Tokens [Index ], ' left' )
2284
2308
local funcRight = getPosition (Tokens [Index ] + 7 , ' right' )
@@ -2292,6 +2316,7 @@ local function parseFunction(isLocal, isAction)
2292
2316
[2 ] = funcRight ,
2293
2317
},
2294
2318
}
2319
+ --- @cast func parser.object.function
2295
2320
Index = Index + 2
2296
2321
skipSpace (true )
2297
2322
local hasLeftParen = Tokens [Index + 1 ] == ' ('
@@ -2463,6 +2488,7 @@ local function parseLambda(isDoublePipe)
2463
2488
2464
2489
if child then
2465
2490
-- create dummy return
2491
+ --- @type parser.object.return
2466
2492
local rtn = {
2467
2493
type = ' return' ,
2468
2494
start = child .start ,
@@ -2741,6 +2767,7 @@ function parseExp(asAction, level)
2741
2767
missExp ()
2742
2768
end
2743
2769
end
2770
+ --- @type parser.object.binary
2744
2771
local bin = {
2745
2772
type = ' binary' ,
2746
2773
start = exp .start ,
@@ -3199,7 +3226,11 @@ local function parseLabel()
3199
3226
local left = getPosition (Tokens [Index ], ' left' )
3200
3227
Index = Index + 2
3201
3228
skipSpace ()
3202
- local label = parseName ()
3229
+ local label = parseName () --[[ @as parser.object.label]]
3230
+ if label then
3231
+ label .type = ' label'
3232
+ end
3233
+
3203
3234
skipSpace ()
3204
3235
3205
3236
if not label then
@@ -3218,7 +3249,6 @@ local function parseLabel()
3218
3249
return nil
3219
3250
end
3220
3251
3221
- label .type = ' label'
3222
3252
pushActionIntoCurrentChunk (label )
3223
3253
3224
3254
local block = guide .getBlock (label )
@@ -3262,20 +3292,23 @@ local function parseLabel()
3262
3292
return label
3263
3293
end
3264
3294
3295
+ --- @return parser.object.goto ?
3265
3296
local function parseGoTo ()
3266
3297
local start = getPosition (Tokens [Index ], ' left' )
3267
3298
Index = Index + 2
3268
3299
skipSpace ()
3269
3300
3270
- local action = parseName ()
3301
+ local action = parseName () --[[ @as parser.object.goto]]
3302
+ if action then
3303
+ action .type = ' goto'
3304
+ action .keyStart = start
3305
+ end
3306
+
3271
3307
if not action then
3272
3308
missName ()
3273
3309
return nil
3274
3310
end
3275
3311
3276
- action .type = ' goto'
3277
- action .keyStart = start
3278
-
3279
3312
for i = # Chunk , 1 , - 1 do
3280
3313
local chunk = Chunk [i ]
3281
3314
if chunk .type == ' function'
@@ -3305,6 +3338,7 @@ local function parseIfBlock(parent)
3305
3338
local ifLeft = getPosition (Tokens [Index ], ' left' )
3306
3339
local ifRight = getPosition (Tokens [Index ] + 1 , ' right' )
3307
3340
Index = Index + 2
3341
+ --- @type parser.object.ifblock
3308
3342
local ifblock = {
3309
3343
type = ' ifblock' ,
3310
3344
parent = parent ,
@@ -3712,6 +3746,7 @@ local function parseFor()
3712
3746
end
3713
3747
3714
3748
local function parseWhile ()
3749
+ --- @type parser.object.while
3715
3750
local action = {
3716
3751
type = ' while' ,
3717
3752
start = getPosition (Tokens [Index ], ' left' ),
@@ -3840,6 +3875,7 @@ local function parseRepeat()
3840
3875
return action
3841
3876
end
3842
3877
3878
+ --- @return parser.object.break
3843
3879
local function parseBreak ()
3844
3880
local returnLeft = getPosition (Tokens [Index ], ' left' )
3845
3881
local returnRight = getPosition (Tokens [Index ] + # Tokens [Index + 1 ] - 1 , ' right' )
@@ -3952,7 +3988,7 @@ function parseAction()
3952
3988
exp .parent = name
3953
3989
if name .type == ' setlocal' then
3954
3990
local loc = name .node
3955
- if loc .attrs then
3991
+ if loc and loc .attrs then
3956
3992
pushError {
3957
3993
type = ' SET_CONST' ,
3958
3994
start = name .start ,
0 commit comments