From f9ca6b8dc707189dabd11f84940340d68527d99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 3 Jul 2019 21:40:44 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=AD=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/parser/ast.lua | 68 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-) (limited to 'server/src/parser/ast.lua') diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 9903dca2..e307f8b8 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -2,6 +2,7 @@ local tonumber = tonumber local string_char = string.char local utf8_char = utf8.char local type = type +local table = table local Errs local State @@ -625,6 +626,15 @@ local Defs = { if obj.argFinish > obj.finish then obj.argFinish = obj.finish end + + if name.type ~= 'name' then + pushError { + type = 'UNEXPECT_LFUNC_NAME', + start = name.start, + finish = name.finish, + } + end + return obj end, Table = function (start, ...) @@ -696,10 +706,10 @@ local Defs = { local last = list[#list] list.finish = last.finish return list - elseif first == '' then - return nil - else + elseif type(first) == 'table' then return first + else + return nil end end, ArgList = function (...) @@ -1213,16 +1223,22 @@ local Defs = { [2] = valueType, } end, - EmmyFunctionType = function (start, ...) + EmmyFunctionType = function (start, args, returns, finish) local result = { start = start, + finish = finish - 1, type = 'emmyFunctionType', - ... + args = args, + returns = returns, } - result.finish = result[#result] - 1 - result[#result] = nil return result end, + EmmyFunctionRtns = function (...) + return {...} + end, + EmmyFunctionArgs = function (...) + return {...} + end, EmmyAlias = function (name, emmyName, ...) return { type = 'emmyAlias', @@ -1233,9 +1249,10 @@ local Defs = { ... } end, - EmmyParam = function (argName, emmyName, ...) + EmmyParam = function (argName, emmyName, option, ...) local emmy = { type = 'emmyParam', + option = option, argName, emmyName, ... @@ -1244,13 +1261,14 @@ local Defs = { emmy.finish = emmy[#emmy].finish return emmy end, - EmmyReturn = function (...) + EmmyReturn = function (start, type, finish, option) local emmy = { type = 'emmyReturn', - ... + option = option, + start = start, + finish = finish - 1, + [1] = type, } - emmy.start = emmy[1].start - emmy.finish = emmy[#emmy].finish return emmy end, EmmyField = function (access, fieldName, ...) @@ -1315,9 +1333,33 @@ local Defs = { EmmyComment = function (...) return { type = 'emmyComment', - [1] = table.concat({...}, ' '), + [1] = table.concat({...}), } end, + EmmyOption = function (options) + if not options or options == '' then + return nil + end + local option = {} + for _, pair in ipairs(options) do + if pair.type == 'pair' then + local key = pair[1] + local value = pair[2] + if key.type == 'name' then + option[key[1]] = value[1] + end + end + end + return option + end, + EmmyTypeEnum = function (default, enum, comment) + enum.type = 'emmyEnum' + if default ~= '' then + enum.default = true + end + enum.comment = comment + return enum + end, -- 捕获错误 UnknownSymbol = function (start, symbol) -- cgit v1.2.3