diff options
-rw-r--r-- | server/src/utility.lua | 28 | ||||
-rw-r--r-- | syntaxes/lua.tmLanguage.json | 40 |
2 files changed, 39 insertions, 29 deletions
diff --git a/server/src/utility.lua b/server/src/utility.lua index a56a78ad..5ff02b8b 100644 --- a/server/src/utility.lua +++ b/server/src/utility.lua @@ -13,12 +13,17 @@ local setmetatable = setmetatable local tableSort = table.sort local mathType = math.type +local function formatNumber(n) + local str = ('%.10f'):format(n) + str = str:gsub('%.?0*$', '') + return str +end + local TAB = setmetatable({}, { __index = function (self, n) self[n] = string_rep('\t', n) return self[n] end}) -local KEY = {} local RESERVED = { ['and'] = true, ['break'] = true, @@ -58,6 +63,7 @@ function table.dump(tbl) end mark[tbl] = true local keys = {} + local keymap = {} local integerFormat = '[%d]' if #tbl >= 10 then local width = math.log(#tbl, 10) @@ -69,35 +75,37 @@ function table.dump(tbl) or #key >= 32 or RESERVED[key] then - KEY[key] = ('[%q]'):format(key) + keymap[key] = ('[%q]'):format(key) else - KEY[key] = key + keymap[key] = key end elseif mathType(key) == 'integer' then - KEY[key] = integerFormat:format(key) + keymap[key] = integerFormat:format(key) else - KEY[key] = ('["<%s>"]'):format(key) + keymap[key] = ('["<%s>"]'):format(key) end keys[#keys+1] = key end local mt = getmetatable(tbl) if not mt or not mt.__pairs then tableSort(keys, function (a, b) - return KEY[a] < KEY[b] + return keymap[a] < keymap[b] end) end for _, key in ipairs(keys) do local value = tbl[key] local tp = type(value) if tp == 'table' then - lines[#lines+1] = ('%s%s = {'):format(TAB[tab+1], KEY[key]) + lines[#lines+1] = ('%s%s = {'):format(TAB[tab+1], keymap[key]) unpack(value, tab+1) lines[#lines+1] = ('%s},'):format(TAB[tab+1]) - elseif tp == 'string' or tp == 'number' or tp == 'boolean' then - lines[#lines+1] = ('%s%s = %q,'):format(TAB[tab+1], KEY[key], value) + elseif tp == 'string' or tp == 'boolean' then + lines[#lines+1] = ('%s%s = %q,'):format(TAB[tab+1], keymap[key], value) + elseif tp == 'number' then + lines[#lines+1] = ('%s%s = %s,'):format(TAB[tab+1], keymap[key], formatNumber(value)) elseif tp == 'nil' then else - lines[#lines+1] = ('%s%s = %s,'):format(TAB[tab+1], KEY[key], tostring(value)) + lines[#lines+1] = ('%s%s = %s,'):format(TAB[tab+1], keymap[key], tostring(value)) end end end diff --git a/syntaxes/lua.tmLanguage.json b/syntaxes/lua.tmLanguage.json index a8d9eabf..7f5c7024 100644 --- a/syntaxes/lua.tmLanguage.json +++ b/syntaxes/lua.tmLanguage.json @@ -3,39 +3,33 @@ "scopeName": "source.lua", "patterns": [ { - "begin": "\\b(?:(local)\\s+)?(function)\\s*(?:\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:([\\.:])[a-zA-Z_][a-zA-Z0-9_]*)?)\\s*)?(\\()", + "begin": "\\b(?:(local)\\s+)?(function)\\b", "beginCaptures": { "1": { "name": "storage.modifier.local.lua" }, "2": { - "name": "keyword.control.lua" - }, - "3": { - "name": "entity.name.function.lua" - }, - "4": { - "name": "punctuation.separator.parameter.lua" - }, - "5": { - "name": "punctuation.definition.parameters.begin.lua" + "name": "storage.modifier.function.lua" } }, - "end": "\\)", + "end": "(?=(\\()(?:[^\\)]*)(\\)))", "endCaptures": { - "0": { - "name": "punctuation.definition.parameters.end.lua" + "1": { + "name": "punctuation.definition.parameters.begin.lua" + }, + "2": { + "name": "punctuation.definition.parameters.finish.lua" } }, "name": "meta.function.lua", "patterns": [ { - "match": "[a-zA-Z_][a-zA-Z0-9_]*", - "name": "variable.parameter.function.lua" + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?=\\s*:)", + "name": "entity.name.class.lua" }, { - "match": ",", - "name": "punctuation.separator.arguments.lua" + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "variable.other.lua" } ] }, @@ -210,10 +204,18 @@ "name": "string.tag.lua" }, { - "match": "\\b(break|do|else|for|if|elseif|goto|return|then|repeat|while|until|end|function|local(\\s*\\*toclose)?|in)\\b", + "match": "\\b(break|do|else|for|if|elseif|goto|return|then|repeat|while|until|end|in)\\b", "name": "keyword.control.lua" }, { + "match": "\\b(local(\\s*\\*toclose)?)\\b", + "name": "storage.modifier.local" + }, + { + "match": "\\b(function)\\b", + "name": "storage.modifier.function" + }, + { "match": "(?<![^.]\\.|:)\\b(false|nil|true|_G|_VERSION|math\\.(pi|huge)|utf8\\.charpattern|io\\.(stdin|stdout|stderr)|package\\.(cpath|loaded|path|preload|searchers))\\b|(?<![.])\\.{3}(?!\\.)", "name": "constant.language.lua" }, |