summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-11-19 17:11:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-11-19 17:11:20 +0800
commit2687363810809f350038acfab2f52f27a3dc51a2 (patch)
treeed90b24e07e5ce2ec3a096f3b2b459c1d677fb19 /src
parentc28a101f62fe7a118baa3eeccf13839249cae760 (diff)
downloadlua-language-server-2687363810809f350038acfab2f52f27a3dc51a2.zip
支持参数
Diffstat (limited to 'src')
-rw-r--r--src/matcher/definition.lua14
-rw-r--r--src/parser/grammar.lua10
2 files changed, 19 insertions, 5 deletions
diff --git a/src/matcher/definition.lua b/src/matcher/definition.lua
index bf7457e7..b18e1a01 100644
--- a/src/matcher/definition.lua
+++ b/src/matcher/definition.lua
@@ -54,6 +54,15 @@ function defs.Name(str)
return {str, namePos}
end
+function defs.DOTSPos(p)
+ namePos = p
+end
+
+function defs.DOTS(str)
+ checkDifinition(str, namePos)
+ return {str, namePos}
+end
+
function defs.LocalVar(names)
for _, name in ipairs(names) do
scopeSet(name)
@@ -66,10 +75,13 @@ function defs.LocalSet(names)
end
end
-function defs.FunctionDef(names)
+function defs.FunctionDef(names, args)
if #names == 1 then
scopeSet(names[1])
end
+ for _, arg in ipairs(args) do
+ scopeSet(arg)
+ end
scopePush()
end
diff --git a/src/parser/grammar.lua b/src/parser/grammar.lua
index 1e3a37c1..cb14fe6d 100644
--- a/src/parser/grammar.lua
+++ b/src/parser/grammar.lua
@@ -147,7 +147,8 @@ TL <- Sp '{'
TR <- Sp '}'
COMMA <- Sp ','
SEMICOLON <- Sp ';'
-DOTS <- Sp '...'
+DOTS <- Sp {} -> DOTSPos
+ '...' -> DOTS
DOT <- Sp '.'
COLON <- Sp ':'
LABEL <- Sp '::'
@@ -185,7 +186,8 @@ Float16 <- ('.' X16*)? ([pP] [+-]? [1-9]? [0-9]*)?
]]
grammar 'Name' [[
-Name <- Sp {} -> NamePos {[a-zA-Z_] [a-zA-Z0-9_]*} -> Name
+Name <- Sp {} -> NamePos
+ {[a-zA-Z_] [a-zA-Z0-9_]*} -> Name
]]
grammar 'Exp' [[
@@ -222,7 +224,7 @@ Suffix <- DOT Name
/ BL Exp BR
/ PL ArgList? PR
-ArgList <- Arg (COMMA Arg)*
+ArgList <- (Arg (COMMA Arg)*)
Arg <- DOTS
/ Exp
@@ -233,7 +235,7 @@ TableField <- NewIndex / NewField / Exp
NewIndex <- BL Exp BR ASSIGN Exp
NewField <- Name ASSIGN Exp
-Function <- (FUNCTION {| FuncName? |} PL ArgList? PR) -> FunctionDef
+Function <- (FUNCTION {| FuncName? |} PL {| ArgList? |} PR) -> FunctionDef
(!END Action)* -> Function
END
FuncName <- Name (FuncSuffix)*