-
Notifications
You must be signed in to change notification settings - Fork 19
/
syntax.go
120 lines (98 loc) · 2.52 KB
/
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
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
109
110
111
112
113
114
115
116
117
118
119
120
package cfg
type LanguageSyntaxConfig struct {
Syntax map[string]*SyntaxCriteria `toml:"syntax"`
}
type DefaultSyntax map[string]string
var DefaultSyntaxSet = DefaultSyntax{}
func RegisterSyntax(name string, s string) {
DefaultSyntaxSet[name] = s
}
func init() {
// TOML
RegisterSyntax("toml", `[syntax.toml]
[syntax.declaration]
colouring = 0xf8f273
pattern = '(\[)(.*)(\])'
[syntax.identifier]
colouring = 0xf0a400
pattern = '\b([a-z]|[A-Z])+(_|([a-z]|[A-Z])+)*\b'
[syntax.symbol]
match = ["="]
colouring = 0xf8f273
`)
// C LANGUAGE SYNTAX HIGHLIGHTING
RegisterSyntax("c", `[syntax.c]
[syntax.type]
colouring = 0xf8f273
match = [
"int", "char", "bool", "float", "double", "void",
"uint8_t", "uint16_t", "uint32_t", "uint64_t",
"int8_t", "int16_t", "int32_t", "int64_t", "const"
]
[syntax.keyword]
colouring = 0xf0a400
match = [
"for", "break", "if", "else", "continue", "return",
"goto", "extern", "const", "typedef",
"struct", "union", "register", "enum",
"do", "static", "sizeof", "volatile", "unsigned",
"switch", "case", "default"
]
[syntax.string_literal]
colouring = 0x4b79fc
pattern = "\"([^\\\"]|\\.)*\""
[syntax.directive]
colouring = 0xf0a400
pattern = "^\\s*#\\s*include\\s+(?:<[^>]*>|\"[^\"]*\")\\s*"
[syntax.symbol]
colouring = 0xf0a400
match = [
"+=", "-=", "*=", "/=", ">>", "<<", "==", "!=",
">=", "<=", "||", "&&",
"=", ":", ";", "*", "&", "+", "-", "/", "%",
"^", "#", "!", "@", "<", ">", ".", ","
]
[syntax.comment]
colouring = 0x4b79fc
pattern = '//.*'`)
// GO LANGUAGE SYNTAX HIGHLIGHTING
RegisterSyntax("go", `[syntax.go]
[syntax.keyword]
colouring = 0xf0a400
match = [
"break", "default", "func", "interface", "select",
"case", "defer", "go", "map", "struct",
"chan", "else", "goto", "package", "switch",
"const", "fallthrough", "if", "range", "type",
"continue", "for", "import", "return", "var",
]
[syntax.type]
colouring = 0xf8f273
match = [
"int", "string", "uint", "rune",
"int8", "int16", "int32", "int64",
"uint8", "uint16", "uint32", "uint64",
"byte", "float32", "float64", "complex64",
"complex128", "uintptr",
]
[syntax.comment]
colouring = 0x4b79fc
pattern = '//.*'
[syntax.string_literal]
colouring = 0x4b79fc
pattern = "\"([^\\\"]|\\.)*\""
[syntax.symbol]
colouring = 0xf0a400
match = [
"+=", "-=", "*=", "/=", ">>", "<<", "==", "!=", ":=",
">=", "<=", "||", "&&",
"=", ":", ";", "*", "&", "+", "-", "/", "%",
"^", "#", "!", "@", "<", ">", ".", ","
]`)
RegisterSyntax("md", `[syntax.md]
[syntax.header]
colouring = 0xff00ff
pattern = '(?m)^#{1,6}.*'
`)
// your syntax here!
}