summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/locale/en-US/script.lni4
-rw-r--r--server/locale/zh-CN/script.lni2
-rw-r--r--server/src/parser/ast.lua9
-rw-r--r--server/src/service.lua12
4 files changed, 22 insertions, 5 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni
index ba95660d..2b14012f 100644
--- a/server/locale/en-US/script.lni
+++ b/server/locale/en-US/script.lni
@@ -11,4 +11,6 @@ DIAG_OVER_MAX_ARGS = 'The function takes only {:d} parameters, but you passed
MWS_NOT_SUPPORT = '{} dose not support multi workspace for now, I may need to restart to support the new workspace ...'
MWS_RESTART = 'Restart'
MWS_NOT_COMPLETE = 'Workspace is not complete yet. You may try again later...'
-MWS_COMPLETE = 'Workspace is complete now. You may try again...'
+MWS_COMPLETE = 'Workspace is complete now. You may try again...'
+
+PARSER_CRASH = 'Parser crashed! Last words:{}'
diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni
index 233c7afe..17b0948d 100644
--- a/server/locale/zh-CN/script.lni
+++ b/server/locale/zh-CN/script.lni
@@ -12,3 +12,5 @@ MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要
MWS_RESTART = '重启'
MWS_NOT_COMPLETE = '工作目录还没有准备好,你可以稍后再试一下...'
MWS_COMPLETE = '工作目录准备好了,你可以再试一下了...'
+
+PARSER_CRASH = '语法解析崩溃了!遗言:{}'
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 45a0cbee..0cef46a1 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -414,9 +414,12 @@ local defs = {
}
return function (self, lua, mode)
- local gram, err = self.grammar(lua, mode, defs)
- if not gram then
+ local suc, res, err = pcall(self.grammar, lua, mode, defs)
+ if not suc then
+ return nil, res
+ end
+ if not res then
return nil, err
end
- return gram
+ return res
end
diff --git a/server/src/service.lua b/server/src/service.lua
index aed5bb9b..e98667fb 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -275,7 +275,17 @@ function mt:compileVM(uri)
break
end
end
- local ast = parser:ast(obj.text)
+ local ast, err = parser:ast(obj.text)
+ if not ast then
+ if type(err) == 'string' then
+ local message = lang.script('PARSER_CRASH', err)
+ log.debug(message)
+ rpc:notify('window/showMessage', {
+ type = 3,
+ message = lang.script('PARSER_CRASH', err:match 'grammar%.lua%:%d+%:(.+)'),
+ })
+ end
+ end
-- 编译前清除节点信息
if obj.parent then