-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.go
67 lines (62 loc) · 964 Bytes
/
syntax.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
package main
import (
"fmt"
"strings"
)
var goReserved = []string{
"break",
"case",
"chan",
"const",
"continue",
"default",
"defer",
"else",
"fallthrough",
"for",
"func",
"go",
"if",
"import",
"interface",
"map",
"goto",
"package",
"range",
"return",
"type",
"select",
"struct",
"switch",
"var",
}
func containsToken(elems []string, v string) bool {
for _, s := range elems {
if v == s {
return true
}
}
return false
}
func Tokenize(rowData string) []string {
return strings.Split(rowData, " ")
}
func Highlighter(token []string, lang string, focus bool) string {
var concat string
switch lang {
case ".go":
for _, ch := range token {
if containsToken(goReserved, ch) {
if focus == false {
concat += fmt.Sprintf("\033[38;5;3m%s\033[m ", ch)
} else {
concat += fmt.Sprintf("\033[38;5;3m%s\033[m\033[48;5;235m ", ch)
}
} else {
concat += ch + " "
}
}
default:
}
return concat
}