forked from xalanq/cf-tool
-
Notifications
You must be signed in to change notification settings - Fork 7
/
langs.go
156 lines (146 loc) · 3.85 KB
/
langs.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package client
import (
"errors"
"io/ioutil"
"net/http"
"regexp"
"github.com/fatih/color"
)
func findLangBlock(body []byte) ([]byte, error) {
reg := regexp.MustCompile(`name="programTypeId".+?</select>`)
tmp := reg.Find(body)
if tmp == nil {
return nil, errors.New("Cannot find language selection")
}
return tmp, nil
}
func findLang(body []byte) (map[string]string, error) {
reg := regexp.MustCompile(`value="(.+?)"[\s\S]*?>([\s\S]+?)<`)
tmp := reg.FindAllSubmatch(body, -1)
if tmp == nil {
return nil, errors.New("Cannot find any language")
}
ret := make(map[string]string)
for i := 0; i < len(tmp); i++ {
ret[string(tmp[i][1])] = string(tmp[i][2])
}
return ret, nil
}
// GetLangList get language list from url (require login)
func (c *Client) GetLangList(url string) (langs map[string]string, err error) {
color.Cyan("Getting language list...")
resp, err := http.Get(url)
if err != nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
block, err := findLangBlock(body)
if err != nil {
return
}
return findLang(block)
}
// Langs generated by
// ^[\s\S]*?value="(.+?)"[\s\S]*?>([\s\S]+?)<[\s\S]*?$
// "\1": "\2",
var Langs = map[string]string{
"43": "GNU GCC C11 5.1.0",
"52": "Clang++17 Diagnostics",
"42": "GNU G++11 5.1.0",
"50": "GNU G++14 6.4.0",
"54": "GNU G++17 7.3.0",
"2": "Microsoft Visual C++ 2010",
"59": "Microsoft Visual C++ 2017",
"9": "C# Mono 5.18",
"28": "D DMD32 v2.086.0",
"32": "Go 1.12.6",
"12": "Haskell GHC 8.6.3",
"60": "Java 11.0.5",
"36": "Java 1.8.0_162",
"48": "Kotlin 1.3.10",
"19": "OCaml 4.02.1",
"3": "Delphi 7",
"4": "Free Pascal 3.0.2",
"51": "PascalABC.NET 3.4.2",
"13": "Perl 5.20.1",
"6": "PHP 7.2.13",
"7": "Python 2.7.15",
"31": "Python 3.7.2",
"40": "PyPy 2.7 (7.2.0)",
"41": "PyPy 3.6 (7.2.0)",
"8": "Ruby 2.0.0p645",
"49": "Rust 1.35.0",
"20": "Scala 2.12.8",
"34": "JavaScript V8 4.8.0",
"55": "Node.js 9.4.0",
"14": "ActiveTcl 8.5",
"15": "Io-2008-01-07 (Win32)",
"17": "Pike 7.8",
"18": "Befunge",
"22": "OpenCobol 1.0",
"25": "Factor",
"26": "Secret_171",
"27": "Roco",
"33": "Ada GNAT 4",
"38": "Mysterious Language",
"39": "FALSE",
"44": "Picat 0.9",
"45": "GNU C++11 5 ZIP",
"46": "Java 8 ZIP",
"47": "J",
"56": "Microsoft Q#",
}
// LangsExt language's ext
var LangsExt = map[string]string{
"GNU C11": "c",
"Clang++17 Diagnostics": "cpp",
"GNU C++0x": "cpp",
"GNU C++": "cpp",
"GNU C++11": "cpp",
"GNU C++14": "cpp",
"GNU C++17": "cpp",
"MS C++": "cpp",
"MS C++ 2017": "cpp",
"Mono C#": "cs",
"D": "d",
"Go": "go",
"Haskell": "hs",
"Kotlin": "kt",
"Ocaml": "ml",
"Delphi": "pas",
"FPC": "pas",
"PascalABC.NET": "pas",
"Perl": "pl",
"PHP": "php",
"Python 2": "py",
"Python 3": "py",
"PyPy 2": "py",
"PyPy 3": "py",
"Ruby": "rb",
"Rust": "rs",
"JavaScript": "js",
"Node.js": "js",
"Q#": "qs",
"Java": "java",
"Java 6": "java",
"Java 7": "java",
"Java 8": "java",
"Java 9": "java",
"Java 10": "java",
"Java 11": "java",
"Tcl": "tcl",
"F#": "fs",
"Befunge": "bf",
"Pike": "pike",
"Io": "io",
"Factor": "factor",
"Cobol": "cbl",
"Secret_171": "secret_171",
"Ada": "adb",
"FALSE": "f",
"": "txt",
}