diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-04-29 20:38:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-04-29 20:38:00 +0800 |
commit | 6c4f440d86783deda607e147824285ecd88de4b6 (patch) | |
tree | 6f1c6ed008ca32b650360323eda5018f97ce16b2 /script/parser | |
parent | 2ffcab3c7d5dc4b1d1455cd9d2bbcef988708e3a (diff) | |
download | lua-language-server-6c4f440d86783deda607e147824285ecd88de4b6.zip |
update parser
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/ast.lua | 70 | ||||
-rw-r--r-- | script/parser/grammar.lua | 43 |
2 files changed, 56 insertions, 57 deletions
diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 45801cf6..38c4e51b 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -983,19 +983,7 @@ local Defs = { finish = start, } end, - Function = function (functionStart, functionFinish, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = functionStart - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(functionStart) - return actions - end, - NamedFunction = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) + Function = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) actions.type = 'function' actions.start = functionStart actions.finish = endFinish - 1 @@ -1006,7 +994,7 @@ local Defs = { } checkMissEnd(functionStart) if not name then - return + return actions end if name.type == 'getname' then name.type = 'setname' @@ -1030,35 +1018,49 @@ local Defs = { name.vstart = functionStart return name end, - LocalFunction = function (start, functionStart, functionFinish, name, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = start - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(start) - - if not name then - return + LocalFunction = function (start, name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + return name end - - if name.type ~= 'getname' then + if name.type ~= 'setname' then PushError { type = 'UNEXPECT_LFUNC_NAME', start = name.start, finish = name.finish, } - return + return name end - local loc = createLocal(name, name.start, actions) + local loc = createLocal(name, name.start, name.value) loc.localfunction = true - loc.vstart = functionStart - - return loc + loc.vstart = name.value.start + return name + end, + NamedFunction = function (name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + end + return name + end, + ExpFunction = function (func) + if func.type ~= 'function' then + PushError { + type = 'UNEXPECT_EFUNC_NAME', + start = func.start, + finish = func.finish, + } + return func.value + end + return func end, Table = function (start, tbl, finish) tbl.type = 'table' diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua index 53d174f3..ea9a25e0 100644 --- a/script/parser/grammar.lua +++ b/script/parser/grammar.lua @@ -319,7 +319,7 @@ ExpUnit <- Nil / Number / Dots / Table - / Function + / ExpFunction / Simple Simple <- {| Prefix (Sp Suffix)* |} @@ -327,7 +327,7 @@ Simple <- {| Prefix (Sp Suffix)* |} Prefix <- Sp ({} PL DirtyExp DirtyPR {}) -> Paren / Single -Single <- Name +Single <- !FUNCTION Name -> Single Suffix <- SuffixWithoutCall / ({} PL SuffixCall DirtyPR {}) @@ -377,8 +377,21 @@ NewIndex <- Sp ({} Index NeedAssign DirtyExp {}) NewField <- Sp ({} MustName ASSIGN DirtyExp {}) -> NewField +ExpFunction <- Function + -> ExpFunction Function <- FunctionBody -> Function +FunctionBody + <- FUNCTION FuncName FuncArgs + {| (!END Action)* |} + NeedEnd + / FUNCTION FuncName FuncArgsMiss + {| %nil |} + NeedEnd +FuncName <- !END {| Single (Sp SuffixWithoutCall)* |} + -> Simple + / %nil + FuncArgs <- Sp ({} PL {| FuncArg+ |} DirtyPR {}) -> FuncArgs / PL DirtyPR %nil @@ -386,12 +399,6 @@ FuncArgsMiss<- {} -> MissPL DirtyPR %nil FuncArg <- DOTS / Name / COMMA -FunctionBody<- FUNCTION FuncArgs - {| (!END Action)* |} - NeedEnd - / FUNCTION FuncArgsMiss - {| %nil |} - NeedEnd -- 纯占位,修改了 `relabel.lua` 使重复定义不抛错 Action <- !END . @@ -515,26 +522,16 @@ LocalNameList LocalName <- (MustName LocalAttr?) -> LocalName +NamedFunction + <- Function + -> NamedFunction + Call <- Simple -> SimpleCall LocalFunction - <- Sp ({} LOCAL FunctionNamedBody) + <- Sp ({} LOCAL Function) -> LocalFunction - -NamedFunction - <- FunctionNamedBody - -> NamedFunction -FunctionNamedBody - <- FUNCTION FuncName FuncArgs - {| (!END Action)* |} - NeedEnd - / FUNCTION FuncName FuncArgsMiss - {| %nil |} - NeedEnd -FuncName <- {| Single (Sp SuffixWithoutCall)* |} - -> Simple - / {} -> MissName %nil ]] grammar 'Lua' [[ |