summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/guide.lua5
-rw-r--r--script/core/linker.lua31
2 files changed, 36 insertions, 0 deletions
diff --git a/script/core/guide.lua b/script/core/guide.lua
index b80a3628..64192297 100644
--- a/script/core/guide.lua
+++ b/script/core/guide.lua
@@ -290,8 +290,13 @@ end
---@param obj parser.guide.object
---@return parser.guide.object
function m.getRoot(obj)
+ local source = obj
+ if source._root then
+ return source._root
+ end
for _ = 1, 1000 do
if obj.type == 'main' then
+ source._root = obj
return obj
end
local parent = obj.parent
diff --git a/script/core/linker.lua b/script/core/linker.lua
new file mode 100644
index 00000000..6c475e70
--- /dev/null
+++ b/script/core/linker.lua
@@ -0,0 +1,31 @@
+local guide = require 'parser.guide'
+
+local function getKey(source)
+ if source.type == 'local' then
+ return ('l%d%s'):format(source.start, source[1])
+ end
+end
+
+---创建source的链接信息
+local function createLink(source)
+ local idList = {}
+ if getKey then
+ idList[#idList+1] = getKey(source)
+ end
+ local id = table.concat(idList, '|')
+ return {
+ id = id,
+ }
+end
+
+local m = {}
+
+---获取source的链接信息
+function m.getLink(source)
+ if not source._link then
+ source._link = createLink(source)
+ end
+ return source._link
+end
+
+return m