summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/parser/compile.lua27
-rw-r--r--script/parser/guide.lua3
-rw-r--r--script/vm/tracer.lua23
3 files changed, 30 insertions, 23 deletions
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index b8040382..17b9b051 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -2232,6 +2232,7 @@ local function parseFunction(isLocal, isAction)
type = 'function',
start = funcLeft,
finish = funcRight,
+ bstart = funcRight,
keyword = {
[1] = funcLeft,
[2] = funcRight,
@@ -2262,6 +2263,7 @@ local function parseFunction(isLocal, isAction)
end
func.name = simple
func.finish = simple.finish
+ func.bstart = simple.finish
if not isAction then
simple.parent = func
pushError {
@@ -2302,6 +2304,7 @@ local function parseFunction(isLocal, isAction)
if Tokens[Index + 1] == ')' then
local parenRight = getPosition(Tokens[Index], 'right')
func.finish = parenRight
+ func.bstart = parenRight
if params then
params.finish = parenRight
end
@@ -2309,6 +2312,7 @@ local function parseFunction(isLocal, isAction)
skipSpace(true)
else
func.finish = lastRightPosition()
+ func.bstart = func.finish
if params then
params.finish = func.finish
end
@@ -2963,6 +2967,7 @@ local function parseDo()
type = 'do',
start = doLeft,
finish = doRight,
+ bstart = doRight,
keyword = {
[1] = doLeft,
[2] = doRight,
@@ -3145,6 +3150,7 @@ local function parseIfBlock(parent)
parent = parent,
start = ifLeft,
finish = ifRight,
+ bstart = ifRight,
keyword = {
[1] = ifLeft,
[2] = ifRight,
@@ -3155,7 +3161,8 @@ local function parseIfBlock(parent)
if filter then
ifblock.filter = filter
ifblock.finish = filter.finish
- filter.parent = ifblock
+ ifblock.bstart = ifblock.finish
+ filter.parent = ifblock
else
missExp()
end
@@ -3164,6 +3171,7 @@ local function parseIfBlock(parent)
if thenToken == 'then'
or thenToken == 'do' then
ifblock.finish = getPosition(Tokens[Index] + #thenToken - 1, 'right')
+ ifblock.bstart = ifblock.finish
ifblock.keyword[3] = getPosition(Tokens[Index], 'left')
ifblock.keyword[4] = ifblock.finish
if thenToken == 'do' then
@@ -3203,6 +3211,7 @@ local function parseElseIfBlock(parent)
parent = parent,
start = ifLeft,
finish = ifRight,
+ bstart = ifRight,
keyword = {
[1] = ifLeft,
[2] = ifRight,
@@ -3214,6 +3223,7 @@ local function parseElseIfBlock(parent)
if filter then
elseifblock.filter = filter
elseifblock.finish = filter.finish
+ elseifblock.bstart = elseifblock.finish
filter.parent = elseifblock
else
missExp()
@@ -3223,6 +3233,7 @@ local function parseElseIfBlock(parent)
if thenToken == 'then'
or thenToken == 'do' then
elseifblock.finish = getPosition(Tokens[Index] + #thenToken - 1, 'right')
+ elseifblock.bstart = elseifblock.finish
elseifblock.keyword[3] = getPosition(Tokens[Index], 'left')
elseifblock.keyword[4] = elseifblock.finish
if thenToken == 'do' then
@@ -3262,6 +3273,7 @@ local function parseElseBlock(parent)
parent = parent,
start = ifLeft,
finish = ifRight,
+ bstart = ifRight,
keyword = {
[1] = ifLeft,
[2] = ifRight,
@@ -3337,6 +3349,7 @@ local function parseFor()
finish = getPosition(Tokens[Index] + 2, 'right'),
keyword = {},
}
+ action.bstart = action.finish
action.keyword[1] = action.start
action.keyword[2] = action.finish
Index = Index + 2
@@ -3366,6 +3379,7 @@ local function parseFor()
local loc = createLocal(name)
loc.parent = action
action.finish = name.finish
+ action.bstart = action.finish
action.loc = loc
end
if expList then
@@ -3375,12 +3389,14 @@ local function parseFor()
value.parent = expList
action.init = value
action.finish = expList[#expList].finish
+ action.bstart = action.finish
end
local max = expList[2]
if max then
max.parent = expList
action.max = max
action.finish = max.finish
+ action.bstart = action.finish
else
pushError {
type = 'MISS_LOOP_MAX',
@@ -3393,6 +3409,7 @@ local function parseFor()
step.parent = expList
action.step = step
action.finish = step.finish
+ action.bstart = action.finish
end
else
pushError {
@@ -3414,7 +3431,8 @@ local function parseFor()
local exps = parseExpList()
- action.finish = inRight
+ action.finish = inRight
+ action.bstart = action.finish
action.keyword[3] = inLeft
action.keyword[4] = inRight
@@ -3435,6 +3453,7 @@ local function parseFor()
local lastExp = exps[#exps]
if lastExp then
action.finish = lastExp.finish
+ action.bstart = action.finish
end
action.exps = exps
@@ -3468,6 +3487,7 @@ local function parseFor()
local left = getPosition(Tokens[Index], 'left')
local right = getPosition(Tokens[Index] + #doToken - 1, 'right')
action.finish = left
+ action.bstart = action.finish
action.keyword[#action.keyword+1] = left
action.keyword[#action.keyword+1] = right
if doToken == 'then' then
@@ -3518,6 +3538,7 @@ local function parseWhile()
finish = getPosition(Tokens[Index] + 4, 'right'),
keyword = {},
}
+ action.bstart = action.finish
action.keyword[1] = action.start
action.keyword[2] = action.finish
Index = Index + 2
@@ -3542,6 +3563,7 @@ local function parseWhile()
local left = getPosition(Tokens[Index], 'left')
local right = getPosition(Tokens[Index] + #doToken - 1, 'right')
action.finish = left
+ action.bstart = action.finish
action.keyword[#action.keyword+1] = left
action.keyword[#action.keyword+1] = right
if doToken == 'then' then
@@ -3594,6 +3616,7 @@ local function parseRepeat()
finish = getPosition(Tokens[Index] + 5, 'right'),
keyword = {},
}
+ action.bstart = action.finish
action.keyword[1] = action.start
action.keyword[2] = action.finish
Index = Index + 2
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 147e6237..f27a2af7 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -21,6 +21,7 @@ local type = type
---@field finish integer
---@field range integer
---@field effect integer
+---@field bstart integer
---@field attrs string[]
---@field specials parser.object[]
---@field labels parser.object[]
@@ -139,7 +140,7 @@ local childMap = {
['getfield'] = {'node', 'field'},
['list'] = {'#'},
['binary'] = {1, 2},
- ['unary'] = {1},
+ ['unary'] = { 1 },
['doc'] = {'#'},
['doc.class'] = {'class', '#extends', '#signs', 'comment'},
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua
index b53fc33e..21a2619f 100644
--- a/script/vm/tracer.lua
+++ b/script/vm/tracer.lua
@@ -313,17 +313,7 @@ function mt:lookIntoChild(action, topNode, outNode)
or action.type == 'for'
or action.type == 'do' then
if action[1] then
- local actionStart
- if action.type == 'loop' then
- actionStart = action.keyword[4]
- elseif action.type == 'in' then
- actionStart = action.keyword[6]
- elseif action.type == 'repeat'
- or action.type == 'for'
- or action.type == 'do' then
- actionStart = action.keyword[2]
- end
- self:lookIntoBlock(action, actionStart, topNode:copy())
+ self:lookIntoBlock(action, action.bstart, topNode:copy())
local lastAssign = self:getLastAssign(action.start, action.finish)
if lastAssign then
self:getNode(lastAssign)
@@ -341,7 +331,7 @@ function mt:lookIntoChild(action, topNode, outNode)
mainNode = topNode:copy()
end
if action[1] then
- self:lookIntoBlock(action, action.keyword[4], blockNode:copy())
+ self:lookIntoBlock(action, action.bstart, blockNode:copy())
local lastAssign = self:getLastAssign(action.start, action.finish)
if lastAssign then
self:getNode(lastAssign)
@@ -372,14 +362,7 @@ function mt:lookIntoChild(action, topNode, outNode)
end
local mergedNode
if subBlock[1] then
- local actionStart
- if subBlock.type == 'ifblock'
- or subBlock.type == 'elseif' then
- actionStart = subBlock.keyword[4]
- else
- actionStart = subBlock.keyword[2]
- end
- self:lookIntoBlock(subBlock, actionStart, blockNode:copy())
+ self:lookIntoBlock(subBlock, subBlock.bstart, blockNode:copy())
local neverReturn = subBlock.hasReturn
or subBlock.hasGoTo
or subBlock.hasBreak