Skip to content

Commit bfb1ce2

Browse files
authored
Merge pull request #28 from Steffan153/powershell
Add powershell syntax highlighting, example code, ...
2 parents a2f6206 + 6ea3ead commit bfb1ce2

File tree

6 files changed

+311
-35
lines changed

6 files changed

+311
-35
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
node_modules
3+
.vscode
4+
DS_Store
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export const conf = {
7+
// the default separators except `$-`
8+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
9+
comments: {
10+
lineComment: '#',
11+
blockComment: ['<#', '#>']
12+
},
13+
brackets: [
14+
['{', '}'],
15+
['[', ']'],
16+
['(', ')']
17+
],
18+
autoClosingPairs: [
19+
{ open: '{', close: '}' },
20+
{ open: '[', close: ']' },
21+
{ open: '(', close: ')' },
22+
{ open: '"', close: '"', notIn: ['string'] },
23+
{ open: "'", close: "'", notIn: ['string', 'comment'] }
24+
],
25+
surroundingPairs: [
26+
{ open: '{', close: '}' },
27+
{ open: '[', close: ']' },
28+
{ open: '(', close: ')' },
29+
{ open: '"', close: '"' },
30+
{ open: "'", close: "'" }
31+
],
32+
folding: {
33+
markers: {
34+
start: new RegExp('^\\s*#region\\b'),
35+
end: new RegExp('^\\s*#endregion\\b')
36+
}
37+
}
38+
};
39+
40+
export const language = {
41+
defaultToken: '',
42+
ignoreCase: true,
43+
tokenPostfix: '.ps1',
44+
45+
brackets: [
46+
{ token: 'delimiter.curly', open: '{', close: '}' },
47+
{ token: 'delimiter.square', open: '[', close: ']' },
48+
{ token: 'delimiter.parenthesis', open: '(', close: ')' }
49+
],
50+
51+
keywords: [
52+
'begin',
53+
'break',
54+
'catch',
55+
'class',
56+
'continue',
57+
'data',
58+
'define',
59+
'do',
60+
'dynamicparam',
61+
'else',
62+
'elseif',
63+
'end',
64+
'exit',
65+
'filter',
66+
'finally',
67+
'for',
68+
'foreach',
69+
'from',
70+
'function',
71+
'if',
72+
'in',
73+
'param',
74+
'process',
75+
'return',
76+
'switch',
77+
'throw',
78+
'trap',
79+
'try',
80+
'until',
81+
'using',
82+
'var',
83+
'while',
84+
'workflow',
85+
'parallel',
86+
'sequence',
87+
'inlinescript',
88+
'configuration'
89+
],
90+
91+
helpKeywords:
92+
/SYNOPSIS|DESCRIPTION|PARAMETER|EXAMPLE|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|ROLE|FUNCTIONALITY|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP/,
93+
94+
// we include these common regular expressions
95+
symbols: /[=><!~?&%|+\-*\/\^;\.,]+/,
96+
escapes: /`(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
97+
98+
// The main tokenizer for our languages
99+
tokenizer: {
100+
root: [
101+
// commands and keywords
102+
[
103+
/[a-zA-Z_][\w-]*/,
104+
{
105+
cases: {
106+
'@keywords': { token: 'keyword.$0' },
107+
'@default': ''
108+
}
109+
}
110+
],
111+
112+
// whitespace
113+
[/[ \t\r\n]+/, ''],
114+
115+
// labels
116+
[/^:\w*/, 'metatag'],
117+
118+
// variables
119+
[
120+
/\$(\{((global|local|private|script|using):)?[\w]+\}|((global|local|private|script|using):)?[\w]+)/,
121+
'variable'
122+
],
123+
124+
// Comments
125+
[/<#/, 'comment', '@comment'],
126+
[/#.*$/, 'comment'],
127+
128+
// delimiters
129+
[/[{}()\[\]]/, '@brackets'],
130+
[/@symbols/, 'delimiter'],
131+
132+
// numbers
133+
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
134+
[/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/, 'number.hex'],
135+
[/\d+?/, 'number'],
136+
137+
// delimiter: after number because of .\d floats
138+
[/[;,.]/, 'delimiter'],
139+
140+
// strings:
141+
[/\@"/, 'string', '@herestring."'],
142+
[/\@'/, 'string', "@herestring.'"],
143+
[
144+
/"/,
145+
{
146+
cases: {
147+
'@eos': 'string',
148+
'@default': { token: 'string', next: '@string."' }
149+
}
150+
}
151+
],
152+
[
153+
/'/,
154+
{
155+
cases: {
156+
'@eos': 'string',
157+
'@default': { token: 'string', next: "@string.'" }
158+
}
159+
}
160+
]
161+
],
162+
163+
string: [
164+
[
165+
/[^"'\$`]+/,
166+
{
167+
cases: {
168+
'@eos': { token: 'string', next: '@popall' },
169+
'@default': 'string'
170+
}
171+
}
172+
],
173+
[
174+
/@escapes/,
175+
{
176+
cases: {
177+
'@eos': { token: 'string.escape', next: '@popall' },
178+
'@default': 'string.escape'
179+
}
180+
}
181+
],
182+
[
183+
/`./,
184+
{
185+
cases: {
186+
'@eos': {
187+
token: 'string.escape.invalid',
188+
next: '@popall'
189+
},
190+
'@default': 'string.escape.invalid'
191+
}
192+
}
193+
],
194+
195+
[
196+
/\$[\w]+$/,
197+
{
198+
cases: {
199+
'$S2=="': { token: 'variable', next: '@popall' },
200+
'@default': { token: 'string', next: '@popall' }
201+
}
202+
}
203+
],
204+
[
205+
/\$[\w]+/,
206+
{
207+
cases: {
208+
'$S2=="': 'variable',
209+
'@default': 'string'
210+
}
211+
}
212+
],
213+
214+
[
215+
/["']/,
216+
{
217+
cases: {
218+
'$#==$S2': { token: 'string', next: '@pop' },
219+
'@default': {
220+
cases: {
221+
'@eos': { token: 'string', next: '@popall' },
222+
'@default': 'string'
223+
}
224+
}
225+
}
226+
}
227+
]
228+
],
229+
230+
herestring: [
231+
[
232+
/^\s*(["'])@/,
233+
{
234+
cases: {
235+
'$1==$S2': { token: 'string', next: '@pop' },
236+
'@default': 'string'
237+
}
238+
}
239+
],
240+
[/[^\$`]+/, 'string'],
241+
[/@escapes/, 'string.escape'],
242+
[/`./, 'string.escape.invalid'],
243+
[
244+
/\$[\w]+/,
245+
{
246+
cases: {
247+
'$S2=="': 'variable',
248+
'@default': 'string'
249+
}
250+
}
251+
]
252+
],
253+
254+
comment: [
255+
[/[^#\.]+/, 'comment'],
256+
[/#>/, 'comment', '@pop'],
257+
[/(\.)(@helpKeywords)(?!\w)/, { token: 'comment.keyword.$2' }],
258+
[/[\.#]/, 'comment']
259+
]
260+
}
261+
};

Client/src/utils/defaultCode.ts

+9
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ $s = fgets(STDIN);
231231
echo "Hello WeekGolf!";`,
232232

233233

234+
// PowerShell
235+
//////////////////////////////
236+
"powershell" : `# Get STDIN
237+
$s = $input;
238+
239+
# Write an answer (implicit output)
240+
"Hello WeekGolf!"`,
241+
242+
234243
// Prolog
235244
//////////////////////////////
236245
"prolog": `% :- Will be executed

Server/src/config/initDB.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ console.log({
1919
const conn = mysql.createConnection({
2020
host: "127.0.0.1",
2121
user: "root",
22-
password: "root",
23-
database: "weekgolf",
22+
password: "testtest",
23+
database: "weekgolfdev",
2424
multipleStatements: true
2525
});
2626

Server/src/db/DEV.sql

+22-21
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ CREATE TABLE UserLanguages (
122122
ocaml_score INT UNSIGNED NOT NULL DEFAULT 0,
123123
perl_score INT UNSIGNED NOT NULL DEFAULT 0,
124124
php_score INT UNSIGNED NOT NULL DEFAULT 0,
125+
powershell_score INT UNSIGNED NOT NULL DEFAULT 0,
125126
prolog_score INT UNSIGNED NOT NULL DEFAULT 0,
126127
python_score INT UNSIGNED NOT NULL DEFAULT 0,
127128
r_score INT UNSIGNED NOT NULL DEFAULT 0,
@@ -153,6 +154,27 @@ CREATE TABLE Friends (
153154

154155

155156

157+
-----------------
158+
---- PROBLEM ----
159+
-----------------
160+
-- Description:
161+
-- This table is also of great importance since it is the table that contains the problems (for once the name is explicit...)
162+
CREATE TABLE Problems (
163+
id INT PRIMARY KEY AUTO_INCREMENT UNIQUE, -- ID of Problem (you can see them on https://week.golf/problems.html)
164+
title VARCHAR(64), -- Title of the problem
165+
descript TEXT, -- Description of the problem
166+
date_enable DATETIME, -- Date where the problem start
167+
date_end DATETIME, -- Date where the problem ends
168+
update_state TINYINT DEFAULT 0, -- 0 is not updated and 1 is updated
169+
show_case INT DEFAULT 7, -- Number of test case that are shown
170+
random_case INT DEFAULT 6, -- Number of "random"/hidden test case
171+
sum_votes INT DEFAULT 0, -- Sum of votes
172+
voters INT DEFAULT 0, -- Number of people who voted
173+
lotw VARCHAR(16) DEFAULT NULL -- Language Of The Week
174+
);
175+
176+
177+
156178
--------------
157179
---- Solutions ----
158180
--------------
@@ -227,27 +249,6 @@ CREATE TABLE UpvoteLang (
227249

228250

229251

230-
-----------------
231-
---- PROBLEM ----
232-
-----------------
233-
-- Description:
234-
-- This table is also of great importance since it is the table that contains the problems (for once the name is explicit...)
235-
CREATE TABLE Problems (
236-
id INT PRIMARY KEY AUTO_INCREMENT UNIQUE, -- ID of Problem (you can see them on https://week.golf/problems.html)
237-
title VARCHAR(64), -- Title of the problem
238-
descript TEXT, -- Description of the problem
239-
date_enable DATETIME, -- Date where the problem start
240-
date_end DATETIME, -- Date where the problem ends
241-
update_state TINYINT DEFAULT 0, -- 0 is not updated and 1 is updated
242-
show_case INT DEFAULT 7, -- Number of test case that are shown
243-
random_case INT DEFAULT 6, -- Number of "random"/hidden test case
244-
sum_votes INT DEFAULT 0, -- Sum of votes
245-
voters INT DEFAULT 0, -- Number of people who voted
246-
lotw VARCHAR(16) DEFAULT NULL -- Language Of The Week
247-
);
248-
249-
250-
251252
----------------------
252253
---- NOTE PROBLEM ----
253254
----------------------

0 commit comments

Comments
 (0)