diff options
Diffstat (limited to 'server-beta/src/parser/guide.lua')
-rw-r--r-- | server-beta/src/parser/guide.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index d3ae7100..bd7f9150 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -1,6 +1,7 @@ local error = error local utf8Len = utf8.len local utf8Offset = utf8.offset +local type = type _ENV = nil @@ -195,6 +196,25 @@ function m.eachSource(root, offset, callback) end end +--- 遍历所有某种类型的source +function m.eachSourceOf(root, types, callback) + if type(types) == 'string' then + types = {[types] = true} + elseif type(types) == 'table' then + for i = 1, #types do + types[types[i]] = true + end + else + return + end + for i = 1, #root do + local source = root[i] + if types[source.type] then + callback(source) + end + end +end + --- 获取偏移对应的坐标(row从0开始,col为光标位置) ---@param lines table ---@return integer {name = 'row'} |