diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-14 17:59:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-14 17:59:18 +0800 |
commit | ad89a32126617db2e139edb90a4dac96bc0e0496 (patch) | |
tree | 5197500a32a925a14589765662b90dc373cdce36 /script | |
parent | 5bb66bb4edf816367caa39d40ea194c4abf1e7e6 (diff) | |
download | lua-language-server-ad89a32126617db2e139edb90a4dac96bc0e0496.zip |
fix #596
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/ast.lua | 22 | ||||
-rw-r--r-- | script/parser/grammar.lua | 7 |
2 files changed, 26 insertions, 3 deletions
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' [[ |