-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.go
More file actions
49 lines (41 loc) · 1.12 KB
/
common.go
File metadata and controls
49 lines (41 loc) · 1.12 KB
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
package lexer
import (
"github.com/Southern/scanner"
"regexp"
"strings"
)
var regex = map[string]map[string]scanner.Definition{
"numbers": {
"hex": {regexp.MustCompile("^(?i)0x[a-f0-9]+\\b"), "HEX"},
},
"comments": {
// Hash comments
"hash": {regexp.MustCompile("^#(.+)"), "COMMENT"},
// Single line comments
"oneline": {regexp.MustCompile("^\\/{2,}\\s*(.+)"), "COMMENT"},
// Multi-line comments
"multiline": {regexp.MustCompile("^/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/"), "COMMENT"},
},
"strings": {
// Double quote strings
"double": {regexp.MustCompile("^\"([^\"\\n]|\\\")*\""), "STRING"},
// Single quote strings
"single": {regexp.MustCompile("^'([^'\\n]|\\')*'"), "STRING"},
},
"operators": {
// Common operators found in almost all languages
"common": {regexp.MustCompile(strings.Join([]string{
"^(",
strings.Join([]string{
// &, |, ^
"([&|\\^])",
// ++, --, &&, ||
"([+\\-&|]{2})",
// !, !=, <, <<, <=, <<=, >, >>, >>>, >=, >>=, >>>=, ^, ^=, +, +=, -,
// -=, %, %=, *, *=
"((<{2}|>{2,3}|[!|&<>^+\\-=%/*])=?)",
}, "|"),
")",
}, "")), "OPERATOR"},
},
}