Skip to content

Commit

Permalink
red: go syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeping committed Nov 8, 2023
1 parent 7c82792 commit 2ed0af5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 5 deletions.
3 changes: 2 additions & 1 deletion data/lib/red/presets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ return {
{"%.go$",
{ ts = 8,
spaces_tab = false,
trim_spaces = true
trim_spaces = true,
syntax = "go",
}
},
{"%.py$",
Expand Down
2 changes: 1 addition & 1 deletion data/lib/red/syntax/c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local function number(ctx, txt, i)
end

local col = {
col = 0,
col = scheme.default,
keywords = {
{ "!", "%%", "&&", "&", "(", ")", "*", "+",
",", "-", "/", ":", ";", "<", "=", ">", "?", "[",
Expand Down
86 changes: 86 additions & 0 deletions data/lib/red/syntax/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
local scheme = require "red/syntax/scheme"

local function number(ctx, txt, i)
local n = ''
local start = i
while txt[i] and txt[i]:find("[0-9]") do
n = n .. txt[i]
i = i + 1
end
if n ~= '' then return i - start end
return false
end

local col = {
col = scheme.default,
keywords = {
{ "<-", "+", "&", "(", ")", "-", "|", "<", "[", "]", "*", "^",
">", "{", "}", "/", "=", ",", ";", "%", "!", ".", ":",
col = scheme.operator },
{
"break", "case", "chan", "const", "continue", "default",
"defer", "else", "fallthrough", "for", "func", "go",
"goto", "if", "import", "interface", "map", "package",
"range", "return", "select", "struct", "switch", "type",
"var",
col = scheme.keyword, word = true
},
{
"uint8", "uint16", "uint32", "uint64", "int8",
"int16", "int32", "int64", "float32", "float64",
"byte", "uint", "int", "float", "uintptr",
"string", "bool",

"nil", "true", "false", "iota", "cap", "close",
"closed", "len", "make", "new", "panic",
"panicln", "print",
col = scheme.lib, word = true,
},
{
"tar", "zip", "bufio", "bytes", "cmd", "compress",
"container", "crypto", "database", "debug", "encoding",
"errors", "expvar", "flag", "fmt", "hash", "html",
"image", "suffixarray", "race", "singleflight",
"syscall", "testenv", "trace", "io", "log", "math",
"mime", "net", "os", "path", "reflect", "regexp",
"runtime", "sort", "strconv", "strings", "sync",
"testing", "text", "time", "unicode", "unsafe",
"vendor", "unicode", "functions", "init",
col = scheme.lib, word = true,
},
{ number, col = scheme.number },
},
{ -- string
start = "`",
stop = "`",
col = scheme.string,
},
{ -- string
start = '"',
stop = '"',
keywords = {
{ '\\"', '\\\\' },
},
col = scheme.string,
},
{ -- string
start = "'",
stop = "'",
keywords = {
{ "\\'", "\\\\" },
},
col = scheme.string,
},
{ -- comment
start = "/*";
stop = '*/';
col = scheme.comment,
},
{ -- comment
start = "//";
stop = '\n';
col = scheme.comment,
},
}

return col
2 changes: 1 addition & 1 deletion data/lib/red/syntax/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local function number(ctx, txt, i)
end

local col = {
col = 0,
col = scheme.default,
keywords = {
{ "(", ")", "{", "}", "[", "]", ".", ",", ";", ":",
"..", "...", "==", "~=", "<=", "=>", ">", "<", "+", "-",
Expand Down
2 changes: 1 addition & 1 deletion data/lib/red/syntax/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local function numbersect(ctx, txt, pos, epos)
end

local col = {
col = 0,
col = scheme.default,
keywords = {
{ '\\*', '\\#', '\\-', '\\\\' },
},
Expand Down
2 changes: 1 addition & 1 deletion data/lib/red/syntax/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local function number(ctx, txt, i)
end

local col = {
col = 0,
col = scheme.default,
keywords = {
{ ":", ".", ">", "<", "+", "-", "*", "/", "%", "=",
"!=", "==", "{", "}", "(", ")", "[", "]", ",", ";",
Expand Down

0 comments on commit 2ed0af5

Please sign in to comment.