-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathcpp.lua
More file actions
280 lines (263 loc) · 7.41 KB
/
cpp.lua
File metadata and controls
280 lines (263 loc) · 7.41 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
--#region keywords
highlight("when", "reserved")
highlight("nameof", "reserved")
highlight("unsafe", "reserved")
highlight("stackalloc", "reserved")
highlight("sizeof", "reserved")
highlight("fixed", "reserved")
highlight("await", "reserved")
highlight("async", "reserved")
highlight("null", "reserved")
highlight("enum", "reserved")
highlight("interface", "reserved")
highlight("explicit", "reserved")
highlight("implicit", "reserved")
highlight("false", "reserved")
highlight("true", "reserved")
highlight("operator", "reserved")
highlight("remove", "reserved")
highlight("add", "reserved")
highlight("set", "reserved")
highlight("get", "reserved")
highlight("params", "reserved")
highlight("override", "reserved")
highlight("virtual", "reserved")
highlight("volatile", "reserved")
highlight("readonly", "reserved")
highlight("struct", "reserved")
highlight("static", "reserved")
highlight("sealed", "reserved")
highlight("abstract", "reserved")
highlight("private", "reserved")
highlight("internal", "reserved")
highlight("protected", "reserved")
highlight("public", "reserved")
highlight("param", "reserved")
highlight("method", "reserved")
highlight("event", "reserved")
highlight("field", "reserved")
highlight("class", "reserved")
highlight("partial", "reserved")
highlight("namespace", "reserved")
highlight("by", "reserved")
highlight("group", "reserved")
highlight("select", "reserved")
highlight("descending", "reserved")
highlight("ascending", "reserved")
highlight("orderby", "reserved")
highlight("into", "reserved")
highlight("equals", "reserved")
highlight("on", "reserved")
highlight("join", "reserved")
highlight("where", "reserved")
highlight("let", "reserved")
highlight("from", "reserved")
highlight("yield", "reserved")
highlight("lock", "reserved")
highlight("finally", "reserved")
highlight("catch", "reserved")
highlight("try", "reserved")
highlight("throw", "reserved")
highlight("return", "reserved")
highlight("goto", "reserved")
highlight("continue", "reserved")
highlight("break", "reserved")
highlight("in", "reserved")
highlight("foreach", "reserved")
highlight("for", "reserved")
highlight("do", "reserved")
highlight("while", "reserved")
highlight("case", "reserved")
highlight("switch", "reserved")
highlight("else", "reserved")
highlight("if", "reserved")
highlight("const", "reserved")
highlight("var", "reserved")
highlight("delegate", "reserved")
highlight("default", "reserved")
highlight("unchecked", "reserved")
highlight("checked", "reserved")
highlight("void", "reserved")
highlight("typeof", "reserved")
highlight("new", "reserved")
highlight("base", "reserved")
highlight("this", "reserved")
highlight("out", "reserved")
highlight("ref", "reserved")
highlight("as", "reserved")
highlight("is", "reserved")
highlight("assembly", "reserved")
highlight("string", "reserved")
highlight("dynamic", "reserved")
highlight("object", "reserved")
highlight("double", "reserved")
highlight("float", "reserved")
highlight("char", "reserved")
highlight("ulong", "reserved")
highlight("long", "reserved")
highlight("uint", "reserved")
highlight("int", "reserved")
highlight("ushort", "reserved")
highlight("short", "reserved")
highlight("byte", "reserved")
highlight("sbyte", "reserved")
highlight("decimal", "reserved")
highlight("bool", "reserved")
highlight("using", "reserved")
highlight("alias", "reserved")
highlight("extern", "reserved")
--#endregion
--#region comments
highlight_region("/*", "*/", "comments", false)
highlight_region("//", "", "comments", true)
--#endregion
--#region IDE comments (for CTRL+L)
add_comment("C# Andy detected!")
add_comment("Holy this C# looks like Java")
add_comment("Make your C# roleplay Java, turn that i-- to i++")
add_comment(
"I thought I'd never see a Microsoft product be open source or source available."
.. " If only Windows was the same way."
)
add_comment("Avid Windows user")
add_comment(
"Let's lock you into the Microsoft walled garden even more! " .. "Install Windows and use WPF, UWP, and WinForms."
)
add_comment("Probably using Windows making garbage WinForms or UWP tutorials.")
add_comment("Get locked into the walled garden of Windows with UWP, WinForms, or WPF!")
add_comment(
"UWP? Deprecated. WinForms? Deprecated. WPF? Not deprecated (some people think it's dead). "
.. "Microsoft deprecates everything they start except WPF."
)
add_comment("C#? More like C-hashtag-please-stop-coding!") -- AI generated
add_comment("!!! JAVA CLONE !!!")
add_comment("rewrite in Rust")
add_comment("NoGet")
add_comment(
"I swear if you're writing a WPF, UWP, "
.. "or WinForms app then stop "
.. "and think about why you're making the microsoft walled garden bigger."
)
--#endregion
---@param s string
---@return string
local function trim(s)
return s:gsub("%s+", "")
end
if _VERSION ~= "Luau" then
-- Written by Bing Chat, I am using Lua 5.4 against my will...
string.split = function(input, sep)
if sep == nil then
sep = "," -- Default separator is whitespace
end
local t = {}
for str in string.gmatch(input, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
end
---Detects variables for auto complete
---@param content string
---@return string[]
function detect_variables(content)
local variables = {
"bool",
"byte",
"sbyte",
"short",
"ushort",
"int",
"uint",
"long",
"ulong",
"float",
"double",
"char",
"string",
"object",
"dynamic",
"var"}
-- example match: int x =
-- (or: int x;)
-- the reason why there's a 2nd word match
-- is because we only want declarations of variables,
-- we want to match `int x =`,
-- not `x =`, because `x =` is only re-assigning `x`.
local re = "[a-zA-ZA-z0-9]+%s+@?[a-zA-ZA-z0-9]+%s*[=;]"
---@param match string
for match in content:gmatch(re) do
print(match)
local name = match:split(" ")[2]
if name:sub(-1) == ";" then
name = name:sub(1, -2)
end
table.insert(variables, name)
end
return variables
end
---Detects functions for auto complete
---@param content string
---@return string[]
function detect_functions(content)
-- example match: typeHere something(
local re = "[a-zA-ZA-z0-9]+%s+[a-zA-ZA-z0-9]+%s*%("
local functions = {
local methodsList = {
"Console.WriteLine()",
"Console.ReadLine()",
"Console.Read()",
"Console.Clear()",
"Math.Abs()",
"Math.Pow()",
"Math.Sqrt()",
"Math.Max()",
"Math.Min()",
"String.Length",
"String.ToUpper()",
"String.ToLower()",
"String.Substring()",
"String.Replace()",
"List<T>.Add()",
"List<T>.Remove()",
"List<T>.Contains()",
"List<T>.Sort()",
"List<T>.Clear()",
"Enumerable.Where()",
"Enumerable.Select()",
"Enumerable.ToList()",
"Enumerable.Aggregate()",
"Enumerable.OrderBy()",
"File.ReadAllText()",
"File.WriteAllText()",
"File.Exists()",
"File.Delete()",
"Directory.GetFiles()",
"Directory.GetDirectories()",
"Directory.CreateDirectory()",
"Directory.Delete()",
"Task.Run()",
"Task.Wait()",
"Task.WhenAll()",
"Task.Delay()",
"Thread.Sleep()",
"Thread.Start()",
"Thread.Abort()",
"Thread.Join()",
"HttpClient.GetAsync()",
"HttpClient.PostAsync()",
"HttpClient.SendAsync()",
"HttpClient.PutAsync()"
}
}
---@param match string
for match in content:gmatch(re) do
print("match=", '"' .. match .. '"')
local a = trim(match:split(" ")[2])
print("a=", '"' .. a .. '"')
local name = a:split("(")[1]
print("name=", '"' .. name .. '"')
table.insert(functions, name)
end
return functions
end