diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-15 17:56:23 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-15 17:56:23 +0800 |
commit | d80a3db90e27f1c4598bb2bf316891857fe71bb9 (patch) | |
tree | 5ede35d02896ab41d6353095d032cd8c66006129 /script | |
parent | be19b8b2e6246bd53e08df3fabaa8442b3422dc6 (diff) | |
download | lua-language-server-d80a3db90e27f1c4598bb2bf316891857fe71bb9.zip |
#589 first supports integer field
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/luadoc.lua | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 3a3a0984..10a0b4d7 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -12,7 +12,7 @@ Main <- (Token / Sp)* Sp <- %s+ X16 <- [a-fA-F0-9] Word <- [a-zA-Z0-9_] -Token <- Name / String / Symbol +Token <- Name / String / Symbol / Index Name <- ({} {[a-zA-Z0-9_] [a-zA-Z0-9_.*-]*} {}) -> Name String <- ({} StringDef {}) @@ -50,6 +50,8 @@ Symbol <- ({} { / '...' } {}) -> Symbol +Index <- ({} '[' Sp? {[0-9]+} Sp? ']' {}) + -> Index ]], { s = m.S' \t', ea = '\a', @@ -103,6 +105,13 @@ Symbol <- ({} { TokenFinishs[Ci] = finish - 1 TokenContents[Ci] = content end, + Index = function (start, content, finish) + Ci = Ci + 1 + TokenTypes[Ci] = 'index' + TokenStarts[Ci] = start + TokenFinishs[Ci] = finish - 1 + TokenContents[Ci] = content + end, }) local function trim(str) @@ -180,6 +189,32 @@ local function parseName(tp, parent) return class end +local function parseIndexField(tp, parent) + local indexTp, indexText = peekToken() + if indexTp ~= 'index' then + return nil + end + nextToken() + local int = math.tointeger(indexText) + if not int then + int = 1 + -- TODO: translate + pushError { + type = 'LUADOC_INDEX_MUST_INT', + start = getStart(), + finish = getFinish(), + } + end + local class = { + type = tp, + start = getStart(), + finish = getFinish(), + parent = parent, + [1] = int, + } + return class +end + local function parseClass(parent) local result = { type = 'doc.class', @@ -407,6 +442,7 @@ local function parseTypeUnitLiteralTable() do field.name = parseName('doc.field.name', field) + or parseIndexField('doc.field.name', field) if not field.name then pushError { type = 'LUADOC_MISS_FIELD_NAME', @@ -777,6 +813,7 @@ local function parseField() return false end) result.field = parseName('doc.field.name', result) + or parseIndexField('doc.field.name', result) if not result.field then pushError { type = 'LUADOC_MISS_FIELD_NAME', |