summaryrefslogtreecommitdiff
path: root/server-beta/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r--server-beta/src/parser/compile.lua6
-rw-r--r--server-beta/src/parser/guide.lua51
2 files changed, 56 insertions, 1 deletions
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 90b3f269..fe4198f0 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -43,7 +43,11 @@ local function getValue(obj)
if vref then
return vref
end
- addValue(obj, {})
+ if guide.isLiteral(obj) then
+ addValue(obj, obj)
+ else
+ addValue(obj, {})
+ end
return obj.vref
end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index 69b49f85..fdd29be7 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -1,5 +1,6 @@
local error = error
local type = type
+local next = next
_ENV = nil
@@ -58,6 +59,16 @@ m.childMap = {
['list'] = {'#'},
}
+--- 是否是字面量
+function m.isLiteral(obj)
+ local tp = obj.type
+ return tp == 'nil'
+ or tp == 'boolean'
+ or tp == 'string'
+ or tp == 'number'
+ or tp == 'table'
+end
+
--- 寻找所在函数
function m.getParentFunction(obj)
for _ = 1, 1000 do
@@ -338,6 +349,7 @@ function m.lineRange(lines, row)
return line.start + 1, line.finish
end
+--- 获取对象作为key时的名字
function m.getKeyName(obj)
if obj.type == 'getglobal' or obj.type == 'setglobal' then
return 'string|' .. obj[1]
@@ -346,4 +358,43 @@ function m.getKeyName(obj)
end
end
+--- 获取对象所有field的key与valueObj
+function m.eachField(obj, callback)
+ local vref = obj.vref
+ if not vref then
+ return
+ end
+ for i = 1, #vref do
+ local v = vref[i]
+ local child = v.child
+ if child then
+ for fieldName, cvref in next, child do
+ for j = 1, #cvref do
+ callback(fieldName, cvref[j])
+ end
+ end
+ end
+ end
+end
+
+--- 获取对象所有指定field的key与valueObj
+function m.eachFieldOf(obj, field, callback)
+ local vref = obj.vref
+ if not vref then
+ return
+ end
+ for i = 1, #vref do
+ local v = vref[i]
+ local child = v.child
+ if child then
+ local cvref = child[field]
+ if cvref then
+ for j = 1, #cvref do
+ callback(cvref[j])
+ end
+ end
+ end
+ end
+end
+
return m