【发布时间】:2017-05-02 15:39:04
【问题描述】:
我有一个表结构如下:
[1] = {
[1] = {
category = "WORD",
cursor = <filtered>,
ptype = "STATEMENT",
ttype = "SERVICE",
value = "service",
<metatable> = <filtered>
},
[2] = {
category = "VARIABLE",
cursor = <filtered>,
ptype = "STATEMENT",
ttype = "IDENTIFIER",
value = "TestService",
<metatable> = <filtered>
},
[3] = {
ttype = "BRACE_BLOCK",
value = {
[1] = { ...
...
[2] = {
[1] = {
category = "WORD",
cursor = <filtered>,
ptype = "STATEMENT",
ttype = "SERVICE",
value = "service",
<metatable> = <filtered>
},
[2] = {
category = "VARIABLE",
cursor = <filtered>,
ptype = "STATEMENT",
ttype = "IDENTIFIER",
value = "HelloWorld",
<metatable> = <filtered>
},
我编写了一个简单的循环,它查找具有 ttype 的第一个表,过滤掉该信息,并希望分配其余的令牌,直到下一个服务开始对应的服务。我的想法是这样的:
local found_service = 0
if found_service == 0 then
for k1, v1 in pairs (parse_tree) do
for i=1,#v1 do
if v1[i].ttype == "SERVICE" then
--Store wanted data in an object
found_service = 1
end
if (found_service == 1 and v1[i].ttype ~= "SERVICE") then
-- ->assign the rest to last found service
end
if found_service == 1 and v1[i].ttype == "SERVICE" then
-- ->Found the next service -->starting over
found_service = 0
end
end
end
end
问题是我停留在索引 i,而 v1[i] 是一个“SERVICE”,所以他也直接进入了最后一个 if 子句。如何结束一个循环迭代(在第一个 if 子句之后)。或者有没有更好的方法来做到这一点?
感谢您的建议。 西奥
【问题讨论】:
-
对一些
::label::使用goto