diff options
-rw-r--r-- | .vscode/settings.json | 2 | ||||
-rw-r--r-- | server/locale/en-US/script.lni | 4 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 4 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 5 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 35 |
5 files changed, 41 insertions, 9 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index f9c90fc6..081defe1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,6 @@ ], "Lua.diagnostics.disable": [ ], - "Lua.runtime.version": "Lua 5.4", + "Lua.runtime.version": "Lua 5.2", "Lua.workspace.maxPreload": 400 } diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index a35729db..1021c58c 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -11,7 +11,7 @@ DIAG_AMBIGUITY_1 = 'Compute `0 {op} {num}` first. You may need to add bra DIAG_LOWERCASE_GLOBAL = 'Global variable in lowercase initial' DIAG_DIAGNOSTICS = 'Diagnostics' DIAG_SYNTAX_CHECK = 'Syntax Check' -DIAG_NEED_VERSION = 'Supported in {}, current is {}' +DIAG_NEED_VERSION = 'Supported in {}' DIAG_DEFINED_VERSION = 'Defined in {}, current is {}' MWS_NOT_SUPPORT = '{} dose not support multi workspace for now, I may need to restart to support the new workspace ...' @@ -42,7 +42,7 @@ PARSER_MALFORMED_NUMBER = 'Malformed number.' PARSER_ACTION_AFTER_RETURN = '<eof> expected.' PARSER_NO_VISIBLE_LABEL = 'No visible label `{label}` .' PARSER_REDEFINE_LABEL = 'Label `{label}` already defined.' -PARSER_TOCLOSE = '{version} does not support this grammar.' +PARSER_UNSUPPORT_SYMBOL = '{version} does not support this grammar.' SYMBOL_ANONYMOUS = '<Anonymous>' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index 960aa5a8..5d090d06 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -11,7 +11,7 @@ DIAG_AMBIGUITY_1 = '会优先运算 `0 {op} {num}`,你可能需要加 DIAG_LOWERCASE_GLOBAL = '首字母小写的全局变量' DIAG_DIAGNOSTICS = '诊断' DIAG_SYNTAX_CHECK = '语法检查' -DIAG_NEED_VERSION = '在 {} 中是合法的,当前为 {}' +DIAG_NEED_VERSION = '在 {} 中是合法的' DIAG_DEFINED_VERSION = '在 {} 中有定义,当前为 {}' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' @@ -42,7 +42,7 @@ PARSER_MALFORMED_NUMBER = '无法构成有效数字。' PARSER_ACTION_AFTER_RETURN = '`return`之后不能再执行代码。' PARSER_NO_VISIBLE_LABEL = '标签`{label}`不可见。' PARSER_REDEFINE_LABEL = '标签`{label}`重复定义。' -PARSER_TOCLOSE = '{version} 不支持该语法。' +PARSER_UNSUPPORT_SYMBOL = '{version} 不支持该符号。' SYMBOL_ANONYMOUS = '<匿名函数>' diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua index f2e1a593..fbe65bb3 100644 --- a/server/src/method/textDocument/publishDiagnostics.lua +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -1,6 +1,5 @@ local core = require 'core' local lang = require 'language' -local config = require 'config' local DiagnosticSeverity = { Error = 1, @@ -85,9 +84,9 @@ local function buildError(err, lines, uri) } if err.version then if type(err.version) == 'table' then - diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', table.concat(err.version, '/'), config.config.runtime.version)) + diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', table.concat(err.version, '/'))) else - diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', err.version, config.config.runtime.version)) + diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', err.version)) end end if err.level == 'error' then diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 1d4d6a23..57d88b0c 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -44,6 +44,36 @@ local RESERVED = { ['while'] = true, } +local VersionOp = { + ['&'] = {'Lua 5.3', 'Lua 5.4'}, + ['~'] = {'Lua 5.3', 'Lua 5.4'}, + ['|'] = {'Lua 5.3', 'Lua 5.4'}, + ['<<'] = {'Lua 5.3', 'Lua 5.4'}, + ['>>'] = {'Lua 5.3', 'Lua 5.4'}, + ['//'] = {'Lua 5.3', 'Lua 5.4'}, +} + +local function checkOpVersion(op, start) + local versions = VersionOp[op] + if not versions then + return + end + for i = 1, #versions do + if versions[i] == State.Version then + return + end + end + pushError { + type = 'UNSUPPORT_SYMBOL', + start = start, + finish = start + #op - 1, + version = versions, + info = { + version = State.Version, + } + } +end + local Exp local function expSplit(list, start, finish, level) @@ -71,6 +101,7 @@ local function binaryForward(list, start, finish, level) if not e2 then goto CONTINUE end + checkOpVersion(op, list[i-1]) return { type = 'binary', op = op, @@ -98,6 +129,7 @@ local function binaryBackward(list, start, finish, level) if not e2 then goto CONTINUE end + checkOpVersion(op, list[i-1]) return { type = 'binary', op = op, @@ -118,6 +150,7 @@ local function unary(list, start, finish, level) if info[op] then local e1 = expSplit(list, start+2, finish, level) if e1 then + checkOpVersion(op, list[start]) return { type = 'unary', op = op, @@ -1210,7 +1243,7 @@ local Defs = { return end pushError { - type = 'TOCLOSE', + type = 'UNSUPPORT_SYMBOL', start = start, finish = start + #'*toclose' - 1, version = 'Lua 5.4', |