diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-09 18:34:26 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-09 18:34:26 +0800 |
commit | 62b4089bb90d06dfdfe54bea33b8c9c8baaf01f9 (patch) | |
tree | 240050151e542c42443d1ec23bc81157bac4504a | |
parent | 55b572b1b6d7c44f23c656eecfa8498b4c1e55b9 (diff) | |
download | lua-language-server-62b4089bb90d06dfdfe54bea33b8c9c8baaf01f9.zip |
支持 LuaJIT 的语法
-rw-r--r-- | server/src/parser/ast.lua | 46 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 7 |
2 files changed, 48 insertions, 5 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 3e8bc22a..508252ae 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -366,24 +366,66 @@ local Defs = { Number = function (start, number, finish) local n = tonumber(number) if n then - return { + State.LastNumber = { type = 'number', start = start, finish = finish - 1, [1] = n, } + return State.LastNumber else pushError { type = 'MALFORMED_NUMBER', start = start, finish = finish - 1, } - return { + State.LastNumber = { type = 'number', start = start, finish = finish - 1, [1] = 0, } + return State.LastNumber + end + end, + FFINumber = function (start, symbol) + if math.type(State.LastNumber[1]) == 'float' then + pushError { + type = 'UNKNOWN_SYMBOL', + start = start, + finish = start + #symbol - 1, + info = { + symbol = symbol, + } + } + State.LastNumber[1] = 0 + return + end + if State.Version ~= 'LuaJIT' then + pushError { + type = 'UNSUPPORT_SYMBOL', + start = start, + finish = start + #symbol - 1, + version = 'LuaJIT', + info = { + version = State.Version, + } + } + State.LastNumber[1] = 0 + end + end, + ImaginaryNumber = function (start, symbol) + if State.Version ~= 'LuaJIT' then + pushError { + type = 'UNSUPPORT_SYMBOL', + start = start, + finish = start + #symbol - 1, + version = 'LuaJIT', + info = { + version = State.Version, + } + } + State.LastNumber[1] = 0 end end, Name = function (start, str, finish) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 9185b5b6..656f98da 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -254,10 +254,11 @@ StringClose <- ']' =eq ']' grammar 'Number' [[ Number <- Sp ({} {NumberDef} {}) -> Number - ErrNumber? + NumberSuffix? NumberDef <- Number16 / Number10 -ErrNumber <- ({} {([0-9a-zA-Z] / '.')+}) - -> UnknownSymbol +NumberSuffix<- ({} {[uU]? [lL] [lL]}) -> FFINumber + / ({} {[iI]}) -> ImaginaryNumber + / ({} {([0-9a-zA-Z] / '.')+}) -> UnknownSymbol Number10 <- Float10 Float10Exp? / Integer10 Float10? Float10Exp? |