diff options
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/guide.lua | 4 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 42 | ||||
-rw-r--r-- | script/parser/newparser.lua | 7 |
3 files changed, 27 insertions, 26 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 941fc7b1..14e19094 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -743,7 +743,7 @@ end ---@param position integer ---@return integer row ---@return integer col -function m.positionOf(position) +function m.rowColOf(position) return position // 10000, position % 10000 end @@ -753,7 +753,7 @@ end ---@param row integer ---@param col integer ---@return integer -function m.offsetOf(row, col) +function m.positionOf(row, col) return row * 10000 + col end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 533aa9db..548539a9 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1,11 +1,10 @@ local m = require 'lpeglabel' local re = require 'parser.relabel' -local lines = require 'parser.lines' local guide = require 'parser.guide' local grammar = require 'parser.grammar' local TokenTypes, TokenStarts, TokenFinishs, TokenContents -local Ci, Offset, pushError, Ct, NextComment, Lines +local Ci, Offset, pushError, NextComment local parseType local Parser = re.compile([[ Main <- (Token / Sp)* @@ -635,7 +634,7 @@ function parseType(parent) result.finish = getFinish() result.firstFinish = result.finish - local row = guide.positionOf(result.finish) + local row = guide.rowColOf(result.finish) local function pushResume() local comments @@ -644,8 +643,9 @@ function parseType(parent) if not nextComm then return false end - local line = Lines[row + i + 1] - if not line or line.finish < nextComm.start then + local nextCommRow = guide.rowColOf(nextComm.start) + local currentRow = row + i + 1 + if currentRow > nextCommRow then return false end if nextComm.text:sub(1, 2) == '-@' then @@ -1176,9 +1176,9 @@ local function haveCodeBeforeDocInCurLine(text, lineData, docStart) return text:sub(lineData.start + 1, docStart - 1):find '[%w_]' end -local function isTailComment(lns, text, binded, doc) +local function isTailComment(text, binded) local lastDoc = binded[#binded] - local lastDocStartRow = guide.positionOf(lastDoc.originalComment.start) + local lastDocStartRow = guide.rowColOf(lastDoc.originalComment.start) local lastDocStartLineData = guide.lineData(lastDocStartRow) if haveCodeBeforeDocInCurLine(text, lastDocStartLineData, lastDoc.originalComment.start) then return true @@ -1186,13 +1186,13 @@ local function isTailComment(lns, text, binded, doc) return false end -local function isNextLine(lns, text, binded, doc) +local function isNextLine(binded, doc) if not binded then return false end local lastDoc = binded[#binded] - local lastRow = guide.positionOf(lastDoc.finish) - local newRow = guide.positionOf(doc.start) + local lastRow = guide.rowColOf(lastDoc.finish) + local newRow = guide.rowColOf(doc.start) return newRow - lastRow == 1 end @@ -1318,7 +1318,7 @@ local function bindClassAndFields(binded) end end -local function bindDoc(sources, lns, binded) +local function bindDoc(sources, binded) if not binded then return end @@ -1332,12 +1332,10 @@ local function bindDoc(sources, lns, binded) doc.bindSources = bindSources end bindGeneric(binded) - local row = guide.positionOf(lastDoc.finish) - local cstart, cfinish = guide.lineRange(lns, row) - local nstart, nfinish = guide.lineRange(lns, row + 1) - bindDocsBetween(sources, binded, bindSources, cstart, cfinish) + local row = guide.rowColOf(lastDoc.finish) + bindDocsBetween(sources, binded, bindSources, guide.positionOf(row, 0), lastDoc.start) if #bindSources == 0 then - bindDocsBetween(sources, binded, bindSources, nstart, nfinish) + bindDocsBetween(sources, binded, bindSources, guide.positionOf(row + 1, 0), guide.positionOf(row + 2, 0)) end bindParamAndReturnIndex(binded) bindClassAndFields(binded) @@ -1361,18 +1359,18 @@ local function bindDocs(state) end) local binded for _, doc in ipairs(state.ast.docs) do - if not isNextLine(Lines, text, binded, doc) then - bindDoc(sources, Lines, binded) + if not isNextLine(binded, doc) then + bindDoc(sources, binded) binded = {} state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc - if isTailComment(Lines, text, binded, doc) then - bindDoc(sources, Lines, binded) + if isTailComment(text, binded) then + bindDoc(sources, binded) binded = nil end end - bindDoc(sources, Lines, binded) + bindDoc(sources, binded) end return function (state) @@ -1389,8 +1387,6 @@ return function (state) pushError = state.pushError - Lines = lines(state.lua) - local ci = 1 NextComment = function (offset, peek) local comment = comments[ci + (offset or 0)] diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 16bcd6a0..0137397d 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -361,6 +361,7 @@ local function skipNL() Line = Line + 1 LineOffset = Tokens[Index] + #token Index = Index + 2 + State.lines[Line] = LineOffset return true end return false @@ -392,8 +393,11 @@ local function resolveLongString(finishMark) local result, count = stringResult : gsub('\r\n', '\n') : gsub('[\r\n]', '\n') - Line = Line + count LineOffset = lastLN + start + for i = Line + 1, Line + count do + State.lines[i] = LineOffset + end + Line = Line + count stringResult = result end fastForwardToken(finishOffset + #finishMark) @@ -3503,6 +3507,7 @@ local function initState(lua, version, options) errs = {}, diags = {}, comms = {}, + lines = {}, options = options or {}, } if version == 'Lua 5.1' or version == 'LuaJIT' then |