summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/parser/ast.lua22
-rw-r--r--script/parser/grammar.lua7
3 files changed, 27 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index 4ffb00c5..2e3eb6a6 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,7 @@
* `FIX` `debug.getuservalue` and `debug.setuservalue` should not exist in `Lua 5.1`
* `FIX` infer of `---@type class[][]`
* `FIX` infer of `---@type {}[]`
+* `FIX` [#596](https://github.com/sumneko/lua-language-server/issues/596)
* `FIX` [#597](https://github.com/sumneko/lua-language-server/issues/597)
## 2.2.3
diff --git a/script/parser/ast.lua b/script/parser/ast.lua
index e92e3e16..aa02ae3d 100644
--- a/script/parser/ast.lua
+++ b/script/parser/ast.lua
@@ -4,9 +4,9 @@ local utf8Char = utf8.char
local tableUnpack = table.unpack
local mathType = math.type
local tableRemove = table.remove
-local pairs = pairs
local tableSort = table.sort
local print = print
+local tostring = tostring
_ENV = nil
@@ -613,6 +613,26 @@ local Defs = {
end
lastNumber[1] = 0
end,
+ Integer2 = function (start, word)
+ if State.version ~= 'LuaJIT' then
+ PushError {
+ type = 'UNSUPPORT_SYMBOL',
+ start = start,
+ finish = start + 1,
+ version = 'LuaJIT',
+ info = {
+ version = State.version,
+ }
+ }
+ end
+ local num = 0
+ for i = 1, #word do
+ if word:sub(i, i) == '1' then
+ num = num | (1 << (i - 1))
+ end
+ end
+ return tostring(num)
+ end,
Name = function (start, str, finish)
local isKeyWord
if RESERVED[str] then
diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua
index 2c046f0e..5120df20 100644
--- a/script/parser/grammar.lua
+++ b/script/parser/grammar.lua
@@ -270,10 +270,10 @@ StringClose <- ']' =eq ']'
]]
grammar 'Number' [[
-Number <- Sp ({} {'-'? NumberDef} {}) -> Number
+Number <- Sp ({} {~ '-'? NumberDef ~} {}) -> Number
NumberSuffix?
ErrNumber?
-NumberDef <- Number16 / Number10
+NumberDef <- Number16 / Integer2 / Number10
NumberSuffix<- ({} {[uU]? [lL] [lL]}) -> FFINumber
/ ({} {[iI]}) -> ImaginaryNumber
ErrNumber <- ({} {([0-9a-zA-Z] / '.')+}) -> UnknownSymbol
@@ -293,6 +293,9 @@ Float16 <- '.' X16+
/ '.' ({} {Word*}) -> MustX16
Float16Exp <- [pP] [+-]? [0-9]+
/ ({} [pP] [+-]? {}) -> MissExponent
+
+Integer2 <- ({} '0' [bB] {[01]+})
+ -> Integer2
]]
grammar 'Name' [[