summaryrefslogtreecommitdiff
path: root/src/matcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-10-10 22:53:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-10-10 22:53:18 +0800
commitf156994cb041cc9022e5af5cf9628a3a97119347 (patch)
tree69384e8af68ad4aa6e345ac36a0fb4b388217871 /src/matcher
parent046b6785bc62ad8f8b0b95f18cf9cf39fa3bd346 (diff)
downloadlua-language-server-f156994cb041cc9022e5af5cf9628a3a97119347.zip
支持函数定义
Diffstat (limited to 'src/matcher')
-rw-r--r--src/matcher/definition.lua38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/matcher/definition.lua b/src/matcher/definition.lua
index fe92ae50..c449f7ad 100644
--- a/src/matcher/definition.lua
+++ b/src/matcher/definition.lua
@@ -7,9 +7,6 @@ local result
local function getResult(name, p)
result = {name, p}
- for k in pairs(defs) do
- defs[k] = nil
- end
end
local function scopeInit()
@@ -22,8 +19,14 @@ local function scopeSet(name, p)
end
local function scopeGet(name)
- local scope = scopes[#scopes]
- return scope[name]
+ for i = #scopes, 1, -1 do
+ local scope = scopes[#scopes]
+ local p = scope[name]
+ if p then
+ return p
+ end
+ end
+ return nil
end
local function checkDifinition(name, p)
@@ -33,18 +36,33 @@ local function checkDifinition(name, p)
getResult(name, scopeGet(name))
end
-function defs.Name(p, name)
- checkDifinition(name, p)
- return name
+function defs.Name(p, str)
+ checkDifinition(str, p)
+ return {str, p}
+end
+
+function defs.LocalVar(name)
+ scopeSet(name[1], name[2])
end
-function defs.LocalVar(p, name)
- scopeSet(name, p)
+function defs.LocalSet(name)
+ scopeSet(name[1], name[2])
+end
+
+function defs.Function(func)
+ local names = func.name
+ if names and #names == 1 then
+ local name = names[1]
+ scopeSet(name[1], name[2])
+ end
+ return func
end
return function (buf, pos_)
pos = pos_
+ result = nil
scopeInit()
+
parser.grammar(buf, 'Lua', defs)
if not result then