aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_go.lua
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-11-01 20:57:07 -0400
committerjgmdev <jgmdev@gmail.com>2022-11-01 20:57:07 -0400
commit49139e03398c9d0ecb347267a4882a4eb3f7ee23 (patch)
tree6ac890a209172a29e09ad47ccd0156e7f7114382 /plugins/language_go.lua
parent380f6ef5fe9f8af19cd1f6b4c043eede51cbfcae (diff)
parent0971a7a686a4e18ee31b576c460966a5ec20ff01 (diff)
downloadlite-xl-plugins-49139e03398c9d0ecb347267a4882a4eb3f7ee23.tar.gz
lite-xl-plugins-49139e03398c9d0ecb347267a4882a4eb3f7ee23.zip
Merge branch '2.1'
Diffstat (limited to 'plugins/language_go.lua')
-rw-r--r--plugins/language_go.lua150
1 files changed, 134 insertions, 16 deletions
diff --git a/plugins/language_go.lua b/plugins/language_go.lua
index 58c38c2..93db0e4 100644
--- a/plugins/language_go.lua
+++ b/plugins/language_go.lua
@@ -1,26 +1,143 @@
--- mod-version:2 -- lite-xl 2.0
+-- mod-version:3
local syntax = require "core.syntax"
syntax.add {
name = "Go",
files = { "%.go$" },
comment = "//",
+ block_comment = {"/*", "*/"},
patterns = {
- { pattern = "//.-\n", type = "comment" },
- { pattern = { "/%*", "%*/" }, type = "comment" },
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "`", "`", '\\' }, type = "string" },
- { pattern = { "'", "'", '\\' }, type = "string" },
- { pattern = "0[oO_][0-7]+", type = "number" },
- { pattern = "-?0x[%x_]+", type = "number" },
- { pattern = "-?%d+_%d", type = "number" },
- { pattern = "-?%d+[%d%.eE]*f?", type = "number" },
- { pattern = "-?%.?%d+f?", type = "number" },
- { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
- { pattern = ":=", type = "operator" },
- { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- function call
- { pattern = "func()%s*[%a_][%w_]*()%f[%[(]", type = {"keyword", "function", "normal"} }, -- function statement
- { pattern = "[%a_][%w_]*", type = "symbol" },
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "`", "`", '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = "0[oO_][0-7]+i?", type = "number" },
+ { pattern = "-?0x[%x_]+i?", type = "number" },
+ { pattern = "-?%d+_%di?", type = "number" },
+ { pattern = "-?%d+[%d%.eE]*f?i?", type = "number" },
+ { pattern = "-?%.?%d+f?i?", type = "number" },
+ -- goto label
+ { pattern = "^%s+()[%a_][%w%_]*()%s*:%s$", -- this is to fix `default:`
+ type = { "normal", "function", "normal" }
+ },
+ { pattern = "^%s*[%a_][%w%_]*()%s*:%s$",
+ type = { "function", "normal" }
+ },
+ -- pointer, generic and reference type
+ { pattern = "[%*~&]()[%a_][%w%_]*",
+ type = { "operator", "keyword2" }
+ },
+ -- slice type
+ { pattern = "%[%]()[%a_][%w%_]*",
+ type = { "operator", "keyword2" }
+ },
+ -- type coerce
+ {
+ pattern = "%.%(()[%a_][%w_]*()%)",
+ type = { "normal", "keyword2", "normal" }
+ },
+ -- struct literal
+ { pattern = "[%a_][%w%_]*()%s*{%s*",
+ type = { "keyword2", "normal" }
+ },
+ -- operators
+ { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
+ { pattern = ":=", type = "operator" },
+ -- function calls
+ { pattern = "func()%s*[%a_][%w_]*()%f[%[(]", -- function statement
+ type = {"keyword", "function", "normal"}
+ },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "%.()[%a_][%w_]*%f[(]",
+ type = { "normal", "function" }
+ },
+ -- type declaration
+ { pattern = "type()%s+()[%a_][%w%_]*",
+ type = { "keyword", "normal", "keyword2" }
+ },
+ -- variable declaration
+ { pattern = "var()%s+()[%a_][%w%_]*",
+ type = { "keyword", "normal", "symbol" }
+ },
+ -- goto
+ { pattern = "goto()%s+()[%a_][%w%_]*",
+ type = { "keyword", "normal", "function" }
+ },
+ -- if fix
+ { pattern = "if()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- for fix
+ { pattern = "for()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- return fix
+ { pattern = "return()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- range fix
+ { pattern = "range()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- func fix
+ { pattern = "func()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- switch fix
+ { pattern = "switch()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- case fix
+ { pattern = "case()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- break fix
+ { pattern = "break()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- continue fix
+ { pattern = "continue()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- package fix
+ { pattern = "package()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- go fix
+ { pattern = "go()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- chan fix
+ { pattern = "chan()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- defer fix
+ { pattern = "defer()%s+%f[%a_]",
+ type = { "keyword", "normal" }
+ },
+ -- field declaration
+ { pattern = "[%a_][%w%_]*()%s*():%s*%f[%w%p]",
+ type = { "function", "normal", "operator" }
+ },
+ -- parameters or declarations
+ { pattern = "[%a_][%w%_]*()%s+()[%*~&]?()[%a_][%w%_]*",
+ type = { "literal", "normal", "operator", "keyword2" }
+ },
+ { pattern = "[%a_][%w_]*()%s+()%[%]()[%a_][%w%_]*",
+ type = { "literal", "normal", "normal", "keyword2" }
+ },
+ -- single return type
+ {
+ pattern = "%)%s+%(?()[%a_][%w%_]*()%)?%s+%{",
+ type = { "normal", "keyword2", "normal" }
+ },
+ -- sub fields
+ { pattern = "%.()[%a_][%w_]*",
+ type = { "normal", "literal" }
+ },
+ -- every other symbol
+ { pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["if"] = "keyword",
@@ -48,6 +165,7 @@ syntax.add {
["go"] = "keyword",
["fallthrough"] = "keyword",
["goto"] = "keyword",
+ ["iota"] = "keyword2",
["int"] = "keyword2",
["int64"] = "keyword2",
["int32"] = "keyword2",