diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-12-17 11:40:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-12-17 11:40:13 +0800 |
commit | f88826b4b752fcaa06c6a9242211659f86b6034d (patch) | |
tree | 92e63049a338463a1b7f661b1555780e00fc6d52 /script/parser | |
parent | d871a27c0ddfa01b11e0dc2ef0270699217af14a (diff) | |
download | lua-language-server-f88826b4b752fcaa06c6a9242211659f86b6034d.zip |
update parser
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/ast.lua | 4 | ||||
-rw-r--r-- | script/parser/grammar.lua | 18 |
2 files changed, 14 insertions, 8 deletions
diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 2fdb99ef..9f5d853f 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -1197,7 +1197,7 @@ local Defs = { return end if not name then - return nil + return end name.type = 'label' return name @@ -1216,7 +1216,7 @@ local Defs = { return end if not name then - return nil + return end name.type = 'goto' return name diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua index ad107ef5..fb68d5b9 100644 --- a/script/parser/grammar.lua +++ b/script/parser/grammar.lua @@ -58,6 +58,12 @@ end defs.None = function () end defs.np = m.Cp() / function (n) return n+1 end defs.NameBody = m.R('az', 'AZ', '__', '\x80\xff') * m.R('09', 'az', 'AZ', '__', '\x80\xff')^0 +defs.NoNil = function (o) + if o == nil then + return + end + return o +end m.setmaxstack(1000) @@ -321,7 +327,7 @@ Single <- FreeName Suffix <- SuffixWithoutCall / ({} PL SuffixCall DirtyPR {}) -> Call -SuffixCall <- Sp ({} {| (COMMA / Exp)+ |} {}) +SuffixCall <- Sp ({} {| (COMMA / Exp->NoNil)+ |} {}) -> PackExpList / %nil SuffixWithoutCall @@ -359,7 +365,7 @@ TableField <- COMMA / SEMICOLON / NewIndex / NewField - / Exp + / Exp->NoNil Index <- BL DirtyExp DirtyBR NewIndex <- Sp ({} Index NeedAssign DirtyExp {}) -> NewIndex @@ -428,7 +434,7 @@ Break <- Sp ({} BREAK {}) Return <- Sp ({} RETURN ReturnExpList {}) -> Return ReturnExpList - <- Sp {| Exp (Sp ',' MaybeExp)* |} + <- Sp {| Exp->NoNil (Sp ',' MaybeExp)* |} / Sp {| !Exp !',' |} / ExpList @@ -461,7 +467,7 @@ LoopBody <- FOR LoopArgs NeedDo {} {| (!END Action)* |} NeedEnd LoopArgs <- MustName AssignOrEQ - ({} {| (COMMA / !DO !END Exp)* |} {}) + ({} {| (COMMA / !DO !END Exp->NoNil)* |} {}) -> PackLoopArgs In <- InBody @@ -469,9 +475,9 @@ In <- InBody InBody <- FOR InNameList NeedIn InExpList NeedDo {} {| (!END Action)* |} NeedEnd -InNameList <- ({} {| (COMMA / !IN !DO !END Name)* |} {}) +InNameList <- ({} {| (COMMA / !IN !DO !END Name->NoNil)* |} {}) -> PackInNameList -InExpList <- ({} {| (COMMA / !DO !DO !END Exp)* |} {}) +InExpList <- ({} {| (COMMA / !DO !DO !END Exp->NoNil)* |} {}) -> PackInExpList While <- WhileBody |