summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-05 15:53:37 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-05 15:53:37 +0800
commit14f8d12a617e1a3ec0e3483cbae3447afa7a7aa8 (patch)
treed6665cdc8d48d7991d2200fd5326879d929beb0e /script
parentb0e388b65d0101bf7c2c309add06ce659c2309c9 (diff)
downloadlua-language-server-14f8d12a617e1a3ec0e3483cbae3447afa7a7aa8.zip
parse literaltable
Diffstat (limited to 'script')
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/parser/luadoc.lua80
2 files changed, 71 insertions, 11 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 780959a3..d88bd2d0 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -129,8 +129,10 @@ m.childMap = {
['doc.type.array'] = {'node'},
['doc.type.table'] = {'tkey', 'tvalue', 'comment'},
['doc.type.function'] = {'#args', '#returns', 'comment'},
+ ['doc.type.ltable'] = {'#fields'},
['doc.type.literal'] = {'node'},
['doc.type.arg'] = {'extends'},
+ ['doc.type.field'] = {'extends'},
['doc.overload'] = {'overload', 'comment'},
['doc.see'] = {'name', 'field'},
}
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 83f59366..7a0ae3d1 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -45,19 +45,9 @@ EChar <- 'a' -> ea
/ ([0-9] [0-9]? [0-9]?) -> Char10
/ ('u{' {Word*} '}') -> CharUtf8
Symbol <- ({} {
- ':'
- / '|'
- / ','
+ [:|,<>()?+#`{}]
/ '[]'
- / '<'
- / '>'
- / '('
- / ')'
- / '?'
/ '...'
- / '+'
- / '#'
- / '`'
} {})
-> Symbol
]], {
@@ -398,6 +388,64 @@ local function parseTypeUnitFunction()
return typeUnit
end
+local function parseTypeUnitLiteralTable(parent)
+ local typeUnit = {
+ type = 'doc.type.ltable',
+ parent = parent,
+ start = getStart(),
+ fields = {},
+ }
+
+ while true do
+ if checkToken('symbol', '}', 1) then
+ nextToken()
+ break
+ end
+ local field = {
+ type = 'doc.type.field',
+ parent = typeUnit,
+ }
+
+ do
+ field.name = parseName('doc.type.name', field)
+ if not field.name then
+ pushError {
+ type = 'LUADOC_MISS_FIELD_NAME',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ break
+ end
+ if not field.start then
+ field.start = field.name.start
+ end
+ if checkToken('symbol', '?', 1) then
+ nextToken()
+ field.optional = true
+ end
+ field.finish = getFinish()
+ if not nextSymbolOrError(':') then
+ break
+ end
+ field.extends = parseType(field)
+ if not field.extends then
+ break
+ end
+ field.finish = getFinish()
+ end
+
+ typeUnit.fields[#typeUnit.fields+1] = field
+ if checkToken('symbol', ',', 1) then
+ nextToken()
+ else
+ nextSymbolOrError(')')
+ break
+ end
+ end
+ typeUnit.finish = getFinish()
+ return typeUnit
+end
+
local function parseTypeUnit(parent, content)
local result
if content == 'fun' then
@@ -515,6 +563,16 @@ function parseType(parent)
if not result.start then
result.start = typeEnum.start
end
+ elseif tp == 'symbol' and content == '{' then
+ nextToken()
+ local typeUnit = parseTypeUnitLiteralTable(result)
+ if not typeUnit then
+ break
+ end
+ result.types[#result.types+1] = typeUnit
+ if not result.start then
+ result.start = typeUnit.start
+ end
elseif tp == 'symbol' and content == '...' then
nextToken()
local vararg = {