diff options
author | lqdev <liquidekgaming@gmail.com> | 2020-12-06 16:57:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-06 16:57:30 +0100 |
commit | ac84d33ab234f1419b85028c735e1f970924abdb (patch) | |
tree | 600aa8c62c1b73e8dc5a143485dd8ea08a3c3db8 /plugins | |
parent | de4227d55a5c821e3450554c952dfb3b1b192266 (diff) | |
parent | eae34e5b7863bf5fa0db3bf133fb9b2b667266fd (diff) | |
download | lite-xl-plugins-ac84d33ab234f1419b85028c735e1f970924abdb.tar.gz lite-xl-plugins-ac84d33ab234f1419b85028c735e1f970924abdb.zip |
Merge pull request #1 from rxi/master
Update from upstream
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/language_go.lua | 95 | ||||
-rw-r--r-- | plugins/language_nim.lua | 120 | ||||
-rw-r--r-- | plugins/language_rust.lua | 2 | ||||
-rw-r--r-- | plugins/lastproject.lua | 7 | ||||
-rw-r--r-- | plugins/rainbowparen.lua | 58 |
5 files changed, 233 insertions, 49 deletions
diff --git a/plugins/language_go.lua b/plugins/language_go.lua index 488725f..dffbaf9 100644 --- a/plugins/language_go.lua +++ b/plugins/language_go.lua @@ -19,53 +19,54 @@ syntax.add { { pattern = "[%a_][%w_]*", type = "symbol" }, }, symbols = { - ["if"] = "keyword", - ["else"] = "keyword", - ["elseif"] = "keyword", - ["for"] = "keyword", - ["continue"] = "keyword", - ["return"] = "keyword", - ["struct"] = "keyword", - ["switch"] = "keyword", - ["case"] = "keyword", - ["default"] = "keyword", - ["const"] = "keyword", - ["package"] = "keyword", - ["import"] = "keyword", - ["func"] = "keyword", - ["var"] = "keyword", - ["type"] = "keyword", - ["interface"] = "keyword", - ["select"] = "keyword", - ["break"] = "keyword", - ["range"] = "keyword", - ["chan"] = "keyword", - ["defer"] = "keyword", - ["go"] = "keyword", - ["int"] = "keyword2", - ["int64"] = "keyword2", - ["int32"] = "keyword2", - ["int16"] = "keyword2", - ["int8"] = "keyword2", - ["uint"] = "keyword2", - ["uint64"] = "keyword2", - ["uint32"] = "keyword2", - ["uint16"] = "keyword2", - ["uint8"] = "keyword2", - ["uintptr"] = "keyword2", - ["float64"] = "keyword2", - ["float32"] = "keyword2", - ["map"] = "keyword2", - ["string"] = "keyword2", - ["rune"] = "keyword2", - ["bool"] = "keyword2", - ["byte"] = "keyword2", - ["error"] = "keyword2", - ["complex64"] = "keyword2", - ["complex128"] = "keyword2", - ["true"] = "literal", - ["false"] = "literal", - ["nil"] = "literal", + ["if"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["for"] = "keyword", + ["continue"] = "keyword", + ["return"] = "keyword", + ["struct"] = "keyword", + ["switch"] = "keyword", + ["case"] = "keyword", + ["default"] = "keyword", + ["const"] = "keyword", + ["package"] = "keyword", + ["import"] = "keyword", + ["func"] = "keyword", + ["var"] = "keyword", + ["type"] = "keyword", + ["interface"] = "keyword", + ["select"] = "keyword", + ["break"] = "keyword", + ["range"] = "keyword", + ["chan"] = "keyword", + ["defer"] = "keyword", + ["go"] = "keyword", + ["fallthrough"] = "keyword", + ["int"] = "keyword2", + ["int64"] = "keyword2", + ["int32"] = "keyword2", + ["int16"] = "keyword2", + ["int8"] = "keyword2", + ["uint"] = "keyword2", + ["uint64"] = "keyword2", + ["uint32"] = "keyword2", + ["uint16"] = "keyword2", + ["uint8"] = "keyword2", + ["uintptr"] = "keyword2", + ["float64"] = "keyword2", + ["float32"] = "keyword2", + ["map"] = "keyword2", + ["string"] = "keyword2", + ["rune"] = "keyword2", + ["bool"] = "keyword2", + ["byte"] = "keyword2", + ["error"] = "keyword2", + ["complex64"] = "keyword2", + ["complex128"] = "keyword2", + ["true"] = "literal", + ["false"] = "literal", + ["nil"] = "literal", }, } diff --git a/plugins/language_nim.lua b/plugins/language_nim.lua new file mode 100644 index 0000000..af230e4 --- /dev/null +++ b/plugins/language_nim.lua @@ -0,0 +1,120 @@ +local syntax = require "core.syntax" + +local patterns = {} + +local symbols = { + ["nil"] = "literal", + ["true"] = "literal", + ["false"] = "literal", +} + +local number_patterns = { + "0[bB][01][01_]*", + "0o[0-7][0-7_]*", + "0[xX]%x[%x_]*", + "%d[%d_]*%.%d[%d_]*[eE][-+]?%d[%d_]*", + "%d[%d_]*%.%d[%d_]*", + "%d[%d_]*", +} + +local type_suffix_patterns = {} + +for _, size in ipairs({"", "8", "16", "32", "64"}) do + table.insert(type_suffix_patterns, "'?[fuiFUI]"..size) +end + +for _, pattern in ipairs(number_patterns) do + for _, suffix in ipairs(type_suffix_patterns) do + table.insert(patterns, { pattern = pattern..suffix, type = "literal" }) + end + table.insert(patterns, { pattern = pattern, type = "literal" }) +end + +local keywords = { + "addr", "and", "as", "asm", + "bind", "block", "break", + "case", "cast", "concept", "const", "continue", "converter", + "defer", "discard", "distinct", "div", "do", + "elif", "else", "end", "enum", "except", "export", + "finally", "for", "from", "func", + "if", "import", "in", "include", "interface", "is", "isnot", "iterator", + "let", + "macro", "method", "mixin", "mod", + "not", "notin", + "object", "of", "or", "out", + "proc", "ptr", + "raise", "ref", "return", + "shl", "shr", "static", + "template", "try", "tuple", "type", + "using", + "var", + "when", "while", + "xor", + "yield", +} + +for _, keyword in ipairs(keywords) do + symbols[keyword] = "keyword" +end + +local standard_types = { + "bool", "byte", + "int", "int8", "int16", "int32", "int64", + "uint", "uint8", "uint16", "uint32", "uint64", + "float", "float32", "float64", + "char", "string", "cstring", + "pointer", + "typedesc", + "void", "auto", "any", + "untyped", "typed", + "clong", "culong", "cchar", "cschar", "cshort", "cint", "csize", "csize_t", + "clonglong", "cfloat", "cdouble", "clongdouble", "cuchar", "cushort", + "cuint", "culonglong", "cstringArray", +} + +for _, type in ipairs(standard_types) do + symbols[type] = "keyword2" +end + +local standard_generic_types = { + "range", + "array", "open[aA]rray", "varargs", "seq", "set", + "sink", "lent", "owned", +} + +for _, type in ipairs(standard_generic_types) do + table.insert(patterns, { pattern = type.."%f[%[]", type = "keyword2" }) + table.insert(patterns, { pattern = type.." +%f[%w]", type = "keyword2" }) +end + +local user_patterns = { + -- comments + { pattern = { "##?%[", "]##?" }, type = "comment" }, + { pattern = "##?.-\n", type = "comment" }, + -- strings and chars + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { '"""', '"""[^"]' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "literal" }, + -- function calls + { pattern = "[a-zA-Z][a-zA-Z0-9_]*%f[(]", type = "function" }, + -- identifiers + { pattern = "[A-Z][a-zA-Z0-9_]*", type = "keyword2" }, + { pattern = "[a-zA-Z][a-zA-Z0-9_]*", type = "symbol" }, + -- operators + { pattern = "%.%f[^.]", type = "normal" }, + { pattern = ":%f[ ]", type = "normal" }, + { pattern = "[=+%-*/<>@$~&%%|!?%^&.:\\]+", type = "operator" }, +} + +for _, pattern in ipairs(user_patterns) do + table.insert(patterns, pattern) +end + +local nim = { + files = { "%.nim$", "%.nims$", "%.nimble$" }, + comment = "#", + patterns = patterns, + symbols = symbols, +} + +syntax.add(nim) diff --git a/plugins/language_rust.lua b/plugins/language_rust.lua index 321efc2..37ba81f 100644 --- a/plugins/language_rust.lua +++ b/plugins/language_rust.lua @@ -61,6 +61,7 @@ syntax.add { ["i128"] = "keyword2", ["i16"] = "keyword2", ["i8"] = "keyword2", + ["u8"] = "keyword2", ["u16"] = "keyword2", ["u32"] = "keyword2", ["u64"] = "keyword2", @@ -70,6 +71,7 @@ syntax.add { ["f64"] = "keyword2", ["f128"] = "keyword2", ["String"] = "keyword2", + ["char"] = "keyword2", ["&str"] = "keyword2", ["bool"] = "keyword2", ["true"] = "literal", diff --git a/plugins/lastproject.lua b/plugins/lastproject.lua index 09ca507..5fb23bd 100644 --- a/plugins/lastproject.lua +++ b/plugins/lastproject.lua @@ -14,8 +14,10 @@ end -- save current project path local fp = io.open(last_project_filename, "w") -fp:write(system.absolute_path ".") -fp:close() +if nil ~= fp then + fp:write(system.absolute_path ".") + fp:close() +end -- restart using last project path if we had no commandline arguments and could @@ -24,3 +26,4 @@ if #ARGS == 1 and project_path then system.exec(string.format("%s %q", EXEFILE, project_path)) core.quit(true) end + diff --git a/plugins/rainbowparen.lua b/plugins/rainbowparen.lua new file mode 100644 index 0000000..b2689f0 --- /dev/null +++ b/plugins/rainbowparen.lua @@ -0,0 +1,58 @@ +local tokenizer = require "core.tokenizer" +local style = require "core.style" +local common = require "core.common" + +local tokenize = tokenizer.tokenize +local closers = { + ["("] = ")", + ["["] = "]", + ["{"] = "}" +} +local function parenstyle(parenstack) + return "paren" .. ((#parenstack % 5) + 1) +end +function tokenizer.tokenize(syntax, text, state) + state = state or {} + local res, istate = tokenize(syntax, text, state.istate) + local parenstack = state.parenstack or "" + local newres = {} + -- split parens out + -- the stock tokenizer can't do this because it merges identical adjacent tokens + for i, type, text in tokenizer.each_token(res) do + if type == "normal" or type == "symbol" then + for normtext1, paren, normtext2 in text:gmatch("([^%(%[{}%]%)]*)([%(%[{}%]%)]?)([^%(%[{}%]%)]*)") do + if #normtext1 > 0 then + table.insert(newres, type) + table.insert(newres, normtext1) + end + if #paren > 0 then + if paren == parenstack:sub(-1) then -- expected closer + parenstack = parenstack:sub(1, -2) + table.insert(newres, parenstyle(parenstack)) + elseif closers[paren] then -- opener + table.insert(newres, parenstyle(parenstack)) + parenstack = parenstack .. closers[paren] + else -- unexpected closer + table.insert(newres, "paren_unbalanced") + end + table.insert(newres, paren) + end + if #normtext2 > 0 then + table.insert(newres, type) + table.insert(newres, normtext2) + end + end + else + table.insert(newres, type) + table.insert(newres, text) + end + end + return newres, { parenstack = parenstack, istate = istate } +end + +style.syntax.paren_unbalanced = style.syntax.paren_unbalanced or { common.color "#DC0408" } +style.syntax.paren1 = style.syntax.paren1 or { common.color "#FC6F71"} +style.syntax.paren2 = style.syntax.paren2 or { common.color "#fcb053"} +style.syntax.paren3 = style.syntax.paren3 or { common.color "#fcd476"} +style.syntax.paren4 = style.syntax.paren4 or { common.color "#52dab2"} +style.syntax.paren5 = style.syntax.paren5 or { common.color "#5a98cf"} |