Skip to content

Commit

Permalink
fix #279 parser native supports negative number
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 4, 2020
1 parent 536c614 commit 88b5882
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 3 additions & 1 deletion script/parser/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion script/parser/grammar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ StringClose <- ']' =eq ']'
]]

grammar 'Number' [[
Number <- Sp ({} {NumberDef} {}) -> Number
Number <- Sp ({} {'-'? NumberDef} {}) -> Number
NumberSuffix?
ErrNumber?
NumberDef <- Number16 / Number10
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion script/parser/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,21 @@ local t: {
}
]]

TEST [[
local <?t?> = {
[-1] = -1,
[0] = 0,
[1] = 1,
}
]]
[[
local t: {
[-1]: integer = -1,
[0]: integer = 0,
[1]: integer = 1,
}
]]

TEST[[
---@class Class
local <?x?> = class()
Expand Down

0 comments on commit 88b5882

Please sign in to comment.