diff options
author | lizho <lizho@msn.com> | 2024-01-30 09:36:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 09:36:41 +0800 |
commit | 7f95e6f71862967bcdc9ca1d78a1947dd177ca3e (patch) | |
tree | bf5a0a138c70b084d1dbacb6a8bcad3da19bbc64 /script/parser | |
parent | 9185dfad1286942b4914657e4c0e9ad28cb2aaa8 (diff) | |
download | lua-language-server-7f95e6f71862967bcdc9ca1d78a1947dd177ca3e.zip |
support tuple type
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/luadoc.lua | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 227808a0..1a777be1 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -369,6 +369,75 @@ local function parseTable(parent) return typeUnit end +local function parseTuple(parent) + if not checkToken('symbol', '[', 1) then + return nil + end + nextToken() + local typeUnit = { + type = 'doc.type.table', + start = getStart(), + parent = parent, + fields = {}, + isTuple = true, + } + + local index = 1 + while true do + if checkToken('symbol', ']', 1) then + nextToken() + break + end + local field = { + type = 'doc.type.field', + parent = typeUnit, + } + + do + local needCloseParen + if checkToken('symbol', '(', 1) then + nextToken() + needCloseParen = true + end + field.name = { + type = 'doc.type', + start = getFinish(), + firstFinish = getFinish(), + finish = getFinish(), + parent = field, + } + field.name.types = { + [1] = { + type = 'doc.type.integer', + start = getFinish(), + finish = getFinish(), + parent = field.name, + [1] = index, + } + } + index = index + 1 + field.extends = parseType(field) + field.optional = field.extends.optional + field.start = field.extends.start + field.finish = field.extends.finish + if needCloseParen then + nextSymbolOrError ')' + end + end + + typeUnit.fields[#typeUnit.fields+1] = field + if checkToken('symbol', ',', 1) + or checkToken('symbol', ';', 1) then + nextToken() + else + nextSymbolOrError(']') + break + end + end + typeUnit.finish = getFinish() + return typeUnit +end + local function parseSigns(parent) if not checkToken('symbol', '<', 1) then return nil @@ -682,6 +751,7 @@ end function parseTypeUnit(parent) local result = parseFunction(parent) or parseTable(parent) + or parseTuple(parent) or parseString(parent) or parseCode(parent) or parseInteger(parent) @@ -864,6 +934,7 @@ local docSwitch = util.switch() while true do local extend = parseName('doc.extends.name', result) or parseTable(result) + or parseTuple(result) if not extend then pushWarning { type = 'LUADOC_MISS_CLASS_EXTENDS_NAME', |