gettc 1.10 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/gettc +60 -69
- data/dist/config.yml +1 -1
- data/dist/include/cpp/engine.rb +78 -86
- data/dist/include/cpp/topcoder +236 -236
- data/dist/include/go/engine.rb +53 -61
- data/dist/include/haskell/engine.rb +112 -122
- data/dist/include/java/engine.rb +187 -184
- data/dist/include/javascript/engine.rb +26 -30
- data/dist/include/javascript/topcoder.js +3 -3
- data/dist/include/javascript/topcoder/errors.js +5 -5
- data/dist/include/javascript/topcoder/reader.js +188 -165
- data/dist/include/javascript/topcoder/writer.js +37 -33
- data/dist/include/python/engine.rb +43 -52
- data/dist/include/python/topcoder/__init__.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/__init__.cpython-34.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/errors.cpython-34.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/reader.cpython-34.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/writer.cpython-34.pyc +0 -0
- data/dist/include/python/topcoder/errors.pyc +0 -0
- data/dist/include/python/topcoder/reader.pyc +0 -0
- data/dist/include/python/topcoder/writer.pyc +0 -0
- data/dist/include/ruby/engine.rb +47 -52
- data/dist/include/ruby/topcoder/reader.rb +205 -193
- data/dist/include/ruby/topcoder/writer.rb +39 -37
- data/dist/template/bin/runner.rb +146 -151
- data/dist/template/bin/runner.sh +96 -96
- data/dist/template/prob/{name}.html +1 -1
- data/dist/template/solve/cpp/{name}.cpp +3 -4
- data/dist/template/solve/cpp/{name}Solver.cpp +14 -14
- data/dist/template/solve/go/{name}/{name}.go +3 -3
- data/dist/template/solve/go/{name}Solver.go +2 -2
- data/dist/template/solve/haskell/{name}.hs +6 -6
- data/dist/template/solve/haskell/{name}Solver.hs +10 -10
- data/dist/template/solve/java/{name}.java +4 -4
- data/dist/template/solve/java/{name}Solver.java +4 -4
- data/dist/template/solve/javascript/{name}.js +4 -6
- data/dist/template/solve/javascript/{name}Solver.js +11 -9
- data/dist/template/solve/python/{name}.py +1 -1
- data/dist/template/solve/python/{name}Solver.py +2 -2
- data/dist/template/solve/ruby/{name}.rb +4 -4
- data/dist/template/solve/ruby/{name}Solver.rb +14 -17
- data/dist/template/util/check/check.cpp +19 -19
- data/{core/lib → lib}/gettc.rb +0 -0
- data/lib/gettc/account.rb +14 -0
- data/lib/gettc/download.rb +211 -0
- data/lib/gettc/generate.rb +156 -0
- data/lib/gettc/parse.rb +237 -0
- data/lib/gettc/print.rb +54 -0
- data/lib/gettc/problem.rb +39 -0
- data/lib/gettc/signature.rb +63 -0
- data/lib/gettc/types.rb +93 -0
- data/lib/version.rb +3 -0
- data/test/gettc/download_test.rb +61 -0
- data/test/gettc/generate_test.rb +70 -0
- data/test/gettc/parse_test.rb +78 -0
- data/test/gettc/signature_test.rb +71 -0
- data/test/gettc/types_test.rb +31 -0
- metadata +28 -23
- data/core/lib/gettc/download.rb +0 -130
- data/core/lib/gettc/generate.rb +0 -145
- data/core/lib/gettc/parse.rb +0 -233
- data/core/lib/gettc/print.rb +0 -56
- data/core/lib/gettc/problem.rb +0 -33
- data/core/lib/gettc/signature.rb +0 -55
- data/core/lib/gettc/types.rb +0 -83
- data/core/lib/version.rb +0 -3
- data/core/test/gettc/download_test.rb +0 -29
- data/core/test/gettc/generate_test.rb +0 -31
- data/core/test/gettc/parse_test.rb +0 -104
- data/core/test/gettc/signature_test.rb +0 -54
- data/core/test/gettc/types_test.rb +0 -28
@@ -1,38 +1,34 @@
|
|
1
1
|
require "gettc/types"
|
2
2
|
|
3
3
|
module Gettc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
return "[]"
|
8
|
-
end
|
4
|
+
class Type
|
5
|
+
def dumb_javascript
|
6
|
+
return "[]" if self.is_a?(TArray)
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
8
|
+
case self
|
9
|
+
when TInt, TLong, TFloat, TDouble
|
10
|
+
"0"
|
11
|
+
when TChar
|
12
|
+
"'$'"
|
13
|
+
when TString
|
14
|
+
'"$"'
|
15
|
+
when TBoolean
|
16
|
+
"true"
|
17
|
+
else
|
18
|
+
"null"
|
19
|
+
end
|
23
20
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
class JavascriptEngine
|
24
|
+
attr_reader :arglist, :input
|
25
|
+
|
26
|
+
def initialize func, vars
|
27
|
+
@arglist = vars.map(&:name).join(", ")
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@input = temp.join " reader.next();\n"
|
36
|
-
end
|
29
|
+
@input = vars.map do |var|
|
30
|
+
"var #{var.name} = reader.next('#{var.type}');"
|
31
|
+
end.join(" reader.next();\n")
|
37
32
|
end
|
33
|
+
end
|
38
34
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
var errors = require("./topcoder/errors");
|
2
2
|
|
3
3
|
module.exports = {
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
Reader : require("./topcoder/reader"),
|
5
|
+
Writer : require("./topcoder/writer"),
|
6
|
+
UnsupportedType : errors.UnsupportedType
|
7
7
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
exports.UnsupportedType = function(type) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
this.type = type;
|
3
|
+
|
4
|
+
this.toString = function() {
|
5
|
+
return "UnsupportedType: " + type.toString() + " is not a valid TopCoder type";
|
6
|
+
};
|
7
7
|
}
|
@@ -1,239 +1,262 @@
|
|
1
1
|
var tc = require("./errors");
|
2
2
|
|
3
3
|
function ParseError(text, pos, info) {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
this.message = "<" + text + ">";
|
10
|
-
if (typeof(info) === "string") {
|
11
|
-
this.message += " (" + info + ")";
|
12
|
-
}
|
4
|
+
if (pos < text.length && pos >= 0) {
|
5
|
+
text = text.substr(0, pos) + "|" +
|
6
|
+
text.substr(pos, 1) + "|" +
|
7
|
+
text.substr(pos + 1);
|
8
|
+
}
|
13
9
|
|
14
|
-
|
15
|
-
return "ParseError: " + this.message;
|
16
|
-
};
|
17
|
-
}
|
10
|
+
this.message = "<" + text + ">";
|
18
11
|
|
12
|
+
if (typeof(info) === "string") {
|
13
|
+
this.message += " (" + info + ")";
|
14
|
+
}
|
15
|
+
|
16
|
+
this.toString = function() {
|
17
|
+
return "ParseError: " + this.message;
|
18
|
+
};
|
19
|
+
}
|
19
20
|
|
20
21
|
function Reader(text) {
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
this.text = text;
|
23
|
+
this.pos = 0;
|
24
|
+
this.len = text.length;
|
24
25
|
}
|
25
26
|
|
26
27
|
Reader.prototype.next = function(type) {
|
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
|
-
|
28
|
+
if (typeof(type) === "undefined") {
|
29
|
+
spaces.call(this);
|
30
|
+
expect.call(this, ',');
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
if (type.substr(type.length - 2, 2) === "[]") {
|
35
|
+
return nextArray.call(this, type.substr(0, type.length - 2));
|
36
|
+
}
|
37
|
+
|
38
|
+
switch (type) {
|
39
|
+
case "boolean":
|
40
|
+
return nextBoolean.call(this);
|
41
|
+
case "int":
|
42
|
+
return nextInt32.call(this);
|
43
|
+
case "long":
|
44
|
+
return nextInt64.call(this);
|
45
|
+
case "float":
|
46
|
+
case "double":
|
47
|
+
return nextFloat.call(this);
|
48
|
+
case "char":
|
49
|
+
return nextChar.call(this);
|
50
|
+
case "String":
|
51
|
+
return nextString.call(this);
|
52
|
+
default:
|
53
|
+
throw new tc.UnsupportedType(type);
|
54
|
+
}
|
52
55
|
};
|
53
56
|
|
54
|
-
|
55
57
|
function isWhiteSpace() {
|
56
|
-
|
57
|
-
|
58
|
+
var c = this.text.charAt(this.pos);
|
59
|
+
return c === ' ' || c === '\t' || c === '\n';
|
58
60
|
}
|
59
61
|
|
60
62
|
function isDigit(c) {
|
61
|
-
|
62
|
-
|
63
|
+
var c = this.text.charAt(this.pos);
|
64
|
+
return c >= '0' && c <= '9';
|
63
65
|
}
|
64
66
|
|
65
|
-
|
66
67
|
function raiseHere(message) {
|
67
|
-
|
68
|
+
throw new ParseError(this.text, this.pos, message);
|
68
69
|
}
|
69
70
|
|
70
71
|
function checkPos() {
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
if (this.pos >= this.len) {
|
73
|
+
raiseHere.call(this, "unexpected end of input");
|
74
|
+
}
|
74
75
|
}
|
75
76
|
|
76
|
-
|
77
77
|
function token() {
|
78
|
-
|
79
|
-
|
78
|
+
checkPos.call(this);
|
79
|
+
return this.text.charAt(this.pos);
|
80
80
|
}
|
81
81
|
|
82
82
|
function spaces() {
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
while (this.pos < this.len && isWhiteSpace.call(this)) {
|
84
|
+
this.pos += 1;
|
85
|
+
}
|
86
86
|
}
|
87
87
|
|
88
88
|
function expect(character) {
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
if (token.call(this) === character) {
|
90
|
+
this.pos += 1;
|
91
|
+
} else {
|
92
|
+
raiseHere(this, "expecting <" + character + ">");
|
93
|
+
}
|
94
94
|
}
|
95
95
|
|
96
|
-
|
97
96
|
function nextBoolean() {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
97
|
+
spaces.call(this);
|
98
|
+
|
99
|
+
if (this.text.substr(this.pos, 4).toUpperCase() === "TRUE") {
|
100
|
+
this.pos += 4;
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
|
104
|
+
else if (this.text.substr(this.pos, 5).toUpperCase() === "FALSE") {
|
105
|
+
this.pos += 5;
|
106
|
+
return false;
|
107
|
+
}
|
108
108
|
|
109
|
+
raiseHere.call(this, "expecting either true or false");
|
110
|
+
}
|
109
111
|
|
110
112
|
function nextDigits() {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
113
|
+
checkPos.call(this);
|
114
|
+
if (!isDigit.call(this)) {
|
115
|
+
|
116
|
+
raiseHere.call(this, "expecting a digit");
|
117
|
+
}
|
118
|
+
|
119
|
+
var start = this.pos;
|
120
|
+
|
121
|
+
while (true) {
|
122
|
+
this.pos += 1;
|
123
|
+
if (this.pos === this.len || !isDigit.call(this)) {
|
124
|
+
break;
|
121
125
|
}
|
122
|
-
|
123
|
-
}
|
126
|
+
}
|
124
127
|
|
128
|
+
return this.text.substr(start, this.pos - start);
|
129
|
+
}
|
125
130
|
|
126
131
|
function nextNaturalNumber(parser) {
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
spaces.call(this);
|
133
|
+
|
134
|
+
if (token.call(this) === "-") {
|
135
|
+
this.pos += 1;
|
136
|
+
return -parser(nextDigits.call(this));
|
137
|
+
}
|
138
|
+
|
139
|
+
return parser(nextDigits.call(this));
|
133
140
|
}
|
134
141
|
|
135
142
|
function nextInt32() {
|
136
|
-
|
137
|
-
|
138
|
-
|
143
|
+
return nextNaturalNumber.call(this, function (str) {
|
144
|
+
return parseInt(str, 10);
|
145
|
+
});
|
139
146
|
}
|
140
147
|
|
141
148
|
function nextInt64() {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
149
|
+
var Int64 = require("long");
|
150
|
+
return nextNaturalNumber.call(this, function (str) {
|
151
|
+
return Int64.fromString(str);
|
152
|
+
});
|
146
153
|
}
|
147
154
|
|
148
|
-
|
149
155
|
function nextPositiveFloat() {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
+
var str = nextDigits.call(this);
|
157
|
+
|
158
|
+
if (this.pos < this.len) {
|
159
|
+
if (this.text.charAt(this.pos) === '.') {
|
160
|
+
this.pos += 1;
|
161
|
+
str += "." + nextDigits.call(this);
|
156
162
|
}
|
157
|
-
|
163
|
+
}
|
164
|
+
|
165
|
+
return parseFloat(str);
|
158
166
|
}
|
159
167
|
|
160
168
|
function nextFloat() {
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
}
|
169
|
+
spaces.call(this);
|
170
|
+
|
171
|
+
if (token.call(this) === '-') {
|
172
|
+
this.pos += 1;
|
173
|
+
return -nextPositiveFloat.call(this);
|
174
|
+
}
|
168
175
|
|
176
|
+
return nextPositiveFloat.call(this);
|
177
|
+
}
|
169
178
|
|
170
179
|
function nextChar() {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
var ret = token.call(this);
|
176
|
-
this.pos += 1;
|
177
|
-
expect.call(this, '\'');
|
178
|
-
return ret;
|
179
|
-
}
|
180
|
+
spaces.call(this);
|
181
|
+
var c = token.call(this);
|
182
|
+
|
183
|
+
if (c === '\'') {
|
180
184
|
this.pos += 1;
|
181
|
-
|
185
|
+
var ret = token.call(this);
|
186
|
+
this.pos += 1;
|
187
|
+
expect.call(this, '\'');
|
188
|
+
return ret;
|
189
|
+
}
|
190
|
+
|
191
|
+
this.pos += 1;
|
192
|
+
return c;
|
182
193
|
}
|
183
194
|
|
184
195
|
|
185
196
|
function nextString() {
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
this.pos += 1;
|
195
|
-
var saved = this.pos;
|
196
|
-
spaces.call(this);
|
197
|
-
if (this.pos === this.len ||
|
198
|
-
this.text.charAt(this.pos) === ',' ||
|
199
|
-
this.text.charAt(this.pos) === ']') {
|
200
|
-
this.pos = saved;
|
201
|
-
return this.text.substr(start, this.pos - 1 - start);
|
202
|
-
}
|
203
|
-
} else {
|
204
|
-
this.pos += 1;
|
205
|
-
}
|
197
|
+
spaces.call(this);
|
198
|
+
expect.call(this, '"');
|
199
|
+
|
200
|
+
var start = this.pos;
|
201
|
+
|
202
|
+
while (true) {
|
203
|
+
if (this.pos >= this.len) {
|
204
|
+
raiseHere.call(this, "expecting a closing quote");
|
206
205
|
}
|
207
|
-
}
|
208
206
|
|
207
|
+
if (token.call(this) === '"') {
|
208
|
+
this.pos += 1;
|
209
|
+
var saved = this.pos;
|
210
|
+
spaces.call(this);
|
209
211
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
return ;
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
nextElems.call(this, elemType, arr);
|
220
|
-
return ;
|
212
|
+
if (this.pos === this.len ||
|
213
|
+
this.text.charAt(this.pos) === ',' ||
|
214
|
+
this.text.charAt(this.pos) === ']') {
|
215
|
+
this.pos = saved;
|
216
|
+
|
217
|
+
return this.text.substr(start, this.pos - 1 - start);
|
218
|
+
}
|
219
|
+
} else {
|
220
|
+
this.pos += 1;
|
221
221
|
}
|
222
|
-
|
222
|
+
}
|
223
223
|
}
|
224
224
|
|
225
|
-
function
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
225
|
+
function nextElems(elemType, arr) {
|
226
|
+
spaces.call(this);
|
227
|
+
var c = token.call(this);
|
228
|
+
|
229
|
+
if (c === ']') {
|
230
|
+
this.pos += 1;
|
231
|
+
return ;
|
232
|
+
}
|
233
|
+
|
234
|
+
if (c === ',') {
|
235
|
+
this.pos += 1;
|
234
236
|
arr.push(this.next(elemType));
|
235
237
|
nextElems.call(this, elemType, arr);
|
238
|
+
return ;
|
239
|
+
}
|
240
|
+
|
241
|
+
raiseHere("expecting either <,> or <]>");
|
242
|
+
}
|
243
|
+
|
244
|
+
function nextArray(elemType) {
|
245
|
+
var arr = [];
|
246
|
+
|
247
|
+
spaces.call(this);
|
248
|
+
expect.call(this, '[');
|
249
|
+
spaces.call(this);
|
250
|
+
|
251
|
+
if (token.call(this) === ']') {
|
252
|
+
this.pos += 1;
|
236
253
|
return arr;
|
254
|
+
}
|
255
|
+
|
256
|
+
arr.push(this.next(elemType));
|
257
|
+
nextElems.call(this, elemType, arr);
|
258
|
+
|
259
|
+
return arr;
|
237
260
|
}
|
238
261
|
|
239
262
|
module.exports = Reader;
|