-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguages.go
108 lines (84 loc) · 2.17 KB
/
languages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package codeview
import (
"strings"
)
func Language(lang string) func(string) []TextEntry {
switch lang {
case "lua":
return Lua
case "python":
return Python
case "go", "golang":
return Golang
default:
return PlainText
}
}
func PlainText(line string) []TextEntry {
return []TextEntry{
{
Text: line,
Color: ColorDefault,
},
}
}
func Lua(line string) []TextEntry {
tokens := strings.Split(line, " ")
entries := make([]TextEntry, 0)
for i, token := range tokens {
entry := TextEntry{
Text: token,
}
switch token {
case "local", "function", "end", "if", "then", "else", "elseif", "for", "in", "do", "repeat", "until", "while", "return", "break", "goto", "not", "and", "or":
entry.Color = ColorToken
case "true", "false", "nil", "self":
entry.Color = ColorValue
}
if i != 0 {
entry.Text = " " + entry.Text
}
entries = append(entries, entry)
}
return entries
}
func Python(line string) []TextEntry {
tokens := strings.Split(line, " ")
entries := make([]TextEntry, 0)
for i, token := range tokens {
entry := TextEntry{
Text: token,
}
switch token {
case "def", "class", "return", "if", "elif", "else", "for", "while", "in", "not", "and", "or", "is", "try", "except", "finally", "raise", "assert", "yield", "import", "from", "as", "with", "global", "nonlocal", "del", "pass", "break", "continue", "lambda":
entry.Color = ColorToken
case "True", "False", "None":
entry.Color = ColorValue
}
if i != 0 {
entry.Text = " " + entry.Text
}
entries = append(entries, entry)
}
return entries
}
func Golang(line string) []TextEntry {
tokens := strings.Split(line, " ")
entries := make([]TextEntry, 0)
for i, token := range tokens {
entry := TextEntry{
Text: token,
}
switch token {
case "package", "import", "func", "return", "if", "else", "for", "range", "switch", "case", "default", "type", "var", "const", "struct", "interface", "map", "chan", "go", "select", "break", "continue", "fallthrough", "defer":
entry.Color = ColorToken
case "true", "false", "nil":
entry.Color = ColorValue
}
if i != 0 {
entry.Text = " " + entry.Text
}
entries = append(entries, entry)
}
return entries
}