summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/brave/work.lua4
-rw-r--r--script/core/completion.lua2
-rw-r--r--script/files.lua11
-rw-r--r--script/parser/newparser.lua46
4 files changed, 35 insertions, 28 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 907f78cf..ee7b4acd 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -26,12 +26,12 @@ brave.on('timer', function (time)
end)
brave.on('compile', function (text)
- local state, err = parser:compile(text, 'lua', 'Lua 5.4')
+ local state, err = parser.compile(text, 'lua', 'Lua 5.4')
if not state then
log.error(err)
return
end
- local lines = parser:lines(text)
+ local lines = parser.lines(text)
return {
root = state.root,
value = state.value,
diff --git a/script/core/completion.lua b/script/core/completion.lua
index fb7b2eb4..f81f8179 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1049,7 +1049,7 @@ local function tryLabelInString(label, source)
if not source or source.type ~= 'string' then
return label
end
- local str = parser:grammar(label, 'String')
+ local str = parser.grammar(label, 'String')
if not str then
return label
end
diff --git a/script/files.lua b/script/files.lua
index fa5474ef..ecaaa5a5 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -446,14 +446,13 @@ function m.compileState(uri, text)
local prog <close> = progress.create(lang.script.WINDOW_COMPILING, 0.5)
prog:setMessage(ws.getRelativePath(uri))
local clock = os.clock()
- local state, err = parser:compile(text
- , 'lua'
+ local state, err = parser.compile(text
+ , 'Lua'
, config.get 'Lua.runtime.version'
, {
special = config.get 'Lua.runtime.special',
unicodeName = config.get 'Lua.runtime.unicodeName',
nonstandardSymbol = config.get 'Lua.runtime.nonstandardSymbol',
- delay = await.delay,
}
)
local passed = os.clock() - clock
@@ -465,7 +464,7 @@ function m.compileState(uri, text)
state.uri = uri
state.ast.uri = uri
local clock = os.clock()
- parser:luadoc(state)
+ parser.luadoc(state)
local passed = os.clock() - clock
if passed > 0.1 then
log.warn(('Parse LuaDoc of [%s] takes [%.3f] sec, size [%.3f] kb.'):format(uri, passed, #text / 1000))
@@ -548,7 +547,7 @@ function m.getLines(uri)
end
local lines = m.linesMap[uri]
if not lines then
- lines = parser:lines(file.text)
+ lines = parser.lines(file.text)
m.linesMap[uri] = lines
end
return lines
@@ -561,7 +560,7 @@ function m.getOriginLines(uri)
end
local lines = m.originLinesMap[uri]
if not lines then
- lines = parser:lines(file.originText)
+ lines = parser.lines(file.originText)
m.originLinesMap[uri] = lines
end
return lines
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index 7fd0ec31..e1d98d87 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -1598,8 +1598,9 @@ local function parseSimple(node, funcName)
finish = lastRightPosition(),
}
end
- node.next = getfield
- node = getfield
+ node.parent = getfield
+ node.next = getfield
+ node = getfield
elseif token == ':' then
local colon = {
type = token,
@@ -1627,8 +1628,9 @@ local function parseSimple(node, funcName)
finish = lastRightPosition(),
}
end
- node.next = getmethod
- node = getmethod
+ node.parent = getmethod
+ node.next = getmethod
+ node = getmethod
if lastMethod then
missSymbol('(', node.node.finish, node.node.finish)
end
@@ -1678,28 +1680,30 @@ local function parseSimple(node, funcName)
call.node.node.mirror = newNode
tinsert(call.args, 1, newNode)
end
+ node.parent = call
node = call
elseif token == '{' then
if funcName then
break
end
- local str = parseTable()
+ local tbl = parseTable()
local call = {
type = 'call',
start = node.start,
- finish = str.finish,
+ finish = tbl.finish,
node = node,
}
local args = {
type = 'callargs',
- start = str.start,
- finish = str.finish,
+ start = tbl.start,
+ finish = tbl.finish,
parent = call,
- [1] = str,
+ [1] = tbl,
}
- call.args = args
- str.parent = args
- return call
+ call.args = args
+ tbl.parent = args
+ node.parent = call
+ node = call
elseif CharMapStrSH[token] then
if funcName then
break
@@ -1718,9 +1722,10 @@ local function parseSimple(node, funcName)
parent = call,
[1] = str,
}
- call.args = args
- str.parent = args
- return call
+ call.args = args
+ str.parent = args
+ node.parent = args
+ node = call
elseif CharMapStrLH[token] then
local str = parseLongString()
if str then
@@ -1740,9 +1745,10 @@ local function parseSimple(node, funcName)
parent = call,
[1] = str,
}
- call.args = args
- str.parent = args
- return call
+ call.args = args
+ str.parent = args
+ node.parent = call
+ node = call
else
local index = parseIndex()
index.type = 'getindex'
@@ -1750,7 +1756,8 @@ local function parseSimple(node, funcName)
index.start = node.start
index.node = node
node.next = index
- node = index
+ node.parent = index
+ node = index
if funcName then
pushError {
type = 'INDEX_IN_FUNC_NAME',
@@ -3458,6 +3465,7 @@ local function parseLua()
start = 0,
finish = 0,
effect = 0,
+ parent = main,
tag = '_ENV',
special= '_G',
[1] = State.ENVMode,