summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-09 18:34:26 +0800
committersumneko <sumneko@hotmail.com>2019-04-09 18:34:26 +0800
commit62b4089bb90d06dfdfe54bea33b8c9c8baaf01f9 (patch)
tree240050151e542c42443d1ec23bc81157bac4504a
parent55b572b1b6d7c44f23c656eecfa8498b4c1e55b9 (diff)
downloadlua-language-server-62b4089bb90d06dfdfe54bea33b8c9c8baaf01f9.zip
支持 LuaJIT 的语法
-rw-r--r--server/src/parser/ast.lua46
-rw-r--r--server/src/parser/grammar.lua7
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?