summaryrefslogtreecommitdiff
path: root/script/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-14 21:02:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-14 21:02:33 +0800
commit834d5e70092d38c884b23fe2bc176ed06f362c69 (patch)
treeefd70348303f4d21249ffcb6e6b10779566b011c /script/parser
parentad89a32126617db2e139edb90a4dac96bc0e0496 (diff)
downloadlua-language-server-834d5e70092d38c884b23fe2bc176ed06f362c69.zip
resolve #588
Diffstat (limited to 'script/parser')
-rw-r--r--script/parser/ast.lua17
-rw-r--r--script/parser/compile.lua3
-rw-r--r--script/parser/grammar.lua5
-rw-r--r--script/parser/guide.lua13
4 files changed, 34 insertions, 4 deletions
diff --git a/script/parser/ast.lua b/script/parser/ast.lua
index aa02ae3d..18bff05c 100644
--- a/script/parser/ast.lua
+++ b/script/parser/ast.lua
@@ -1095,6 +1095,7 @@ local Defs = {
local wantField = true
local lastStart = start + 1
local fieldCount = 0
+ local n = 0
for i = 1, #tbl do
local field = tbl[i]
if field.type == ',' or field.type == ';' then
@@ -1119,6 +1120,10 @@ local Defs = {
lastStart = field.finish + 1
fieldCount = fieldCount + 1
tbl[fieldCount] = field
+ if field.type == 'tableexp' then
+ n = n + 1
+ field.tindex = n
+ end
end
end
for i = fieldCount + 1, #tbl do
@@ -1153,6 +1158,18 @@ local Defs = {
end
return obj
end,
+ TableExp = function (start, value, finish)
+ if not value then
+ return
+ end
+ local obj = {
+ type = 'tableexp',
+ start = start,
+ finish = finish-1,
+ value = value,
+ }
+ return obj
+ end,
FuncArgs = function (start, args, finish)
args.type = 'funcargs'
args.start = start
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index e1e07c54..207664cc 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -198,6 +198,9 @@ local vmMap = {
Compile(obj.index, obj)
Compile(obj.value, obj)
end,
+ ['tableexp'] = function (obj)
+ Compile(obj.value, obj)
+ end,
['index'] = function (obj)
Compile(obj.index, obj)
end,
diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua
index 5120df20..1a3913e0 100644
--- a/script/parser/grammar.lua
+++ b/script/parser/grammar.lua
@@ -381,14 +381,17 @@ Table <- Sp ({} TL {| TableField* |} DirtyTR {})
-> Table
TableField <- COMMA
/ SEMICOLON
+ / Dots
/ NewIndex
/ NewField
- / Exp->NoNil
+ / TableExp
Index <- BL DirtyExp DirtyBR
NewIndex <- Sp ({} Index NeedAssign DirtyExp {})
-> NewIndex
NewField <- Sp ({} MustName ASSIGN DirtyExp {})
-> NewField
+TableExp <- Sp ({} Exp {})
+ -> TableExp
ExpFunction <- Function
-> ExpFunction
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 2508b801..59794e5f 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -33,6 +33,7 @@ local type = type
---@field typeGeneric table<integer, parser.guide.object[]>
---@field tkey parser.guide.object
---@field tvalue parser.guide.object
+---@field tindex integer
---@field op parser.guide.object
---@field next parser.guide.object
---@field docParam parser.guide.object
@@ -102,6 +103,7 @@ m.childMap = {
['table'] = {'#'},
['tableindex'] = {'index', 'value'},
['tablefield'] = {'field', 'value'},
+ ['tableexp'] = {'value'},
['function'] = {'args', '#'},
['funcargs'] = {'#'},
['setmethod'] = {'node', 'method', 'value'},
@@ -770,7 +772,8 @@ function m.isSet(source)
or tp == 'setmethod'
or tp == 'setindex'
or tp == 'tablefield'
- or tp == 'tableindex' then
+ or tp == 'tableindex'
+ or tp == 'tableexp' then
return true
end
if tp == 'call' then
@@ -823,12 +826,12 @@ function m.getKeyNameOfLiteral(obj)
elseif tp == 'number' then
local n = obj[1]
if n then
- return ('%s'):format(formatNumber(obj[1]))
+ return formatNumber(obj[1])
end
elseif tp == 'integer' then
local n = obj[1]
if n then
- return ('%s'):format(formatNumber(obj[1]))
+ return formatNumber(obj[1])
end
elseif tp == 'boolean' then
local b = obj[1]
@@ -865,6 +868,8 @@ function m.getKeyName(obj)
or tp == 'setindex'
or tp == 'tableindex' then
return m.getKeyNameOfLiteral(obj.index)
+ elseif tp == 'tableexp' then
+ return tostring(obj.tindex)
elseif tp == 'field'
or tp == 'method'
or tp == 'doc.see.field' then
@@ -927,6 +932,8 @@ function m.getKeyType(obj)
or tp == 'setindex'
or tp == 'tableindex' then
return m.getKeyTypeOfLiteral(obj.index)
+ elseif tp == 'tableexp' then
+ return 'integer'
elseif tp == 'field'
or tp == 'method'
or tp == 'doc.see.field' then