From 88b58826a4e84d5bc4c0cf99e544c5b4073cb198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 4 Dec 2020 18:04:08 +0800 Subject: [PATCH] fix #279 parser native supports negative number --- changelog.md | 1 + script/parser/compile.lua | 4 +++- script/parser/grammar.lua | 5 ++++- script/parser/parse.lua | 2 +- test/hover/init.lua | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 1f6e31952..0a5a7215f 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ * `NEW` setting `runtime.unicodeName` * `NEW` fully supports `---@generic T` * `FIX` [#274](https://github.com/sumneko/lua-language-server/issues/274) +* `FIX` [#279](https://github.com/sumneko/lua-language-server/issues/279) ## 1.4.0 `2020-12-3` diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 56ce24897..1ba111ed4 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -548,7 +548,9 @@ return function (self, lua, mode, version, options) LocalCount = 0 Version = version Root = state.ast - Root.state = state + if Root then + Root.state = state + end Options = options state.ENVMode = ENVMode if type(state.ast) == 'table' then diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua index d0a0b252a..ad107ef50 100644 --- a/script/parser/grammar.lua +++ b/script/parser/grammar.lua @@ -258,7 +258,7 @@ StringClose <- ']' =eq ']' ]] grammar 'Number' [[ -Number <- Sp ({} {NumberDef} {}) -> Number +Number <- Sp ({} {'-'? NumberDef} {}) -> Number NumberSuffix? ErrNumber? NumberDef <- Number16 / Number10 @@ -534,6 +534,9 @@ return function (self, lua, mode) local err = errorpos(pos) return nil, err end + if type(r) ~= 'table' then + return nil + end return r end diff --git a/script/parser/parse.lua b/script/parser/parse.lua index e4935e7a5..909ce315b 100644 --- a/script/parser/parse.lua +++ b/script/parser/parse.lua @@ -42,7 +42,7 @@ return function (self, lua, mode, version, options) if not suc then return nil, res end - if not res then + if not res and err then state.pushError(err) end state.ast = res diff --git a/test/hover/init.lua b/test/hover/init.lua index b24e29509..ff94524de 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -890,6 +890,21 @@ local t: { } ]] +TEST [[ +local = { + [-1] = -1, + [0] = 0, + [1] = 1, +} +]] +[[ +local t: { + [-1]: integer = -1, + [0]: integer = 0, + [1]: integer = 1, +} +]] + TEST[[ ---@class Class local = class()