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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gettc +60 -69
  3. data/dist/config.yml +1 -1
  4. data/dist/include/cpp/engine.rb +78 -86
  5. data/dist/include/cpp/topcoder +236 -236
  6. data/dist/include/go/engine.rb +53 -61
  7. data/dist/include/haskell/engine.rb +112 -122
  8. data/dist/include/java/engine.rb +187 -184
  9. data/dist/include/javascript/engine.rb +26 -30
  10. data/dist/include/javascript/topcoder.js +3 -3
  11. data/dist/include/javascript/topcoder/errors.js +5 -5
  12. data/dist/include/javascript/topcoder/reader.js +188 -165
  13. data/dist/include/javascript/topcoder/writer.js +37 -33
  14. data/dist/include/python/engine.rb +43 -52
  15. data/dist/include/python/topcoder/__init__.pyc +0 -0
  16. data/dist/include/python/topcoder/__pycache__/__init__.cpython-34.pyc +0 -0
  17. data/dist/include/python/topcoder/__pycache__/errors.cpython-34.pyc +0 -0
  18. data/dist/include/python/topcoder/__pycache__/reader.cpython-34.pyc +0 -0
  19. data/dist/include/python/topcoder/__pycache__/writer.cpython-34.pyc +0 -0
  20. data/dist/include/python/topcoder/errors.pyc +0 -0
  21. data/dist/include/python/topcoder/reader.pyc +0 -0
  22. data/dist/include/python/topcoder/writer.pyc +0 -0
  23. data/dist/include/ruby/engine.rb +47 -52
  24. data/dist/include/ruby/topcoder/reader.rb +205 -193
  25. data/dist/include/ruby/topcoder/writer.rb +39 -37
  26. data/dist/template/bin/runner.rb +146 -151
  27. data/dist/template/bin/runner.sh +96 -96
  28. data/dist/template/prob/{name}.html +1 -1
  29. data/dist/template/solve/cpp/{name}.cpp +3 -4
  30. data/dist/template/solve/cpp/{name}Solver.cpp +14 -14
  31. data/dist/template/solve/go/{name}/{name}.go +3 -3
  32. data/dist/template/solve/go/{name}Solver.go +2 -2
  33. data/dist/template/solve/haskell/{name}.hs +6 -6
  34. data/dist/template/solve/haskell/{name}Solver.hs +10 -10
  35. data/dist/template/solve/java/{name}.java +4 -4
  36. data/dist/template/solve/java/{name}Solver.java +4 -4
  37. data/dist/template/solve/javascript/{name}.js +4 -6
  38. data/dist/template/solve/javascript/{name}Solver.js +11 -9
  39. data/dist/template/solve/python/{name}.py +1 -1
  40. data/dist/template/solve/python/{name}Solver.py +2 -2
  41. data/dist/template/solve/ruby/{name}.rb +4 -4
  42. data/dist/template/solve/ruby/{name}Solver.rb +14 -17
  43. data/dist/template/util/check/check.cpp +19 -19
  44. data/{core/lib → lib}/gettc.rb +0 -0
  45. data/lib/gettc/account.rb +14 -0
  46. data/lib/gettc/download.rb +211 -0
  47. data/lib/gettc/generate.rb +156 -0
  48. data/lib/gettc/parse.rb +237 -0
  49. data/lib/gettc/print.rb +54 -0
  50. data/lib/gettc/problem.rb +39 -0
  51. data/lib/gettc/signature.rb +63 -0
  52. data/lib/gettc/types.rb +93 -0
  53. data/lib/version.rb +3 -0
  54. data/test/gettc/download_test.rb +61 -0
  55. data/test/gettc/generate_test.rb +70 -0
  56. data/test/gettc/parse_test.rb +78 -0
  57. data/test/gettc/signature_test.rb +71 -0
  58. data/test/gettc/types_test.rb +31 -0
  59. metadata +28 -23
  60. data/core/lib/gettc/download.rb +0 -130
  61. data/core/lib/gettc/generate.rb +0 -145
  62. data/core/lib/gettc/parse.rb +0 -233
  63. data/core/lib/gettc/print.rb +0 -56
  64. data/core/lib/gettc/problem.rb +0 -33
  65. data/core/lib/gettc/signature.rb +0 -55
  66. data/core/lib/gettc/types.rb +0 -83
  67. data/core/lib/version.rb +0 -3
  68. data/core/test/gettc/download_test.rb +0 -29
  69. data/core/test/gettc/generate_test.rb +0 -31
  70. data/core/test/gettc/parse_test.rb +0 -104
  71. data/core/test/gettc/signature_test.rb +0 -54
  72. 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
- class Type
5
- def dumb_javascript
6
- if is_a? TArray then
7
- return "[]"
8
- end
4
+ class Type
5
+ def dumb_javascript
6
+ return "[]" if self.is_a?(TArray)
9
7
 
10
- case self
11
- when TInt, TLong, TFloat, TDouble
12
- return "0"
13
- when TChar
14
- return "'$'"
15
- when TString
16
- return '"$"'
17
- when TBoolean
18
- return "true"
19
- end
20
-
21
- return "null"
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
- class JavascriptEngine
25
- attr_reader :arglist, :input
26
- def initialize func, vars
27
- temp = vars.map do |var|
28
- var.name
29
- end
30
- @arglist = temp.join ", "
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
- temp = vars.map do |var|
33
- "var " + var.name + ' = reader.next("' + var.type.to_s + '");'
34
- end
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
- Reader : require("./topcoder/reader"),
5
- Writer : require("./topcoder/writer"),
6
- UnsupportedType : errors.UnsupportedType
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
- this.type = type;
3
- this.toString = function() {
4
- return "UnsupportedType: " +
5
- type.toString() + " is not a valid TopCoder type";
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
- if (pos < text.length && pos >= 0) {
5
- text = text.substr(0, pos) + "|" +
6
- text.substr(pos, 1) + "|" +
7
- text.substr(pos + 1);
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
- this.toString = function() {
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
- this.text = text;
22
- this.pos = 0;
23
- this.len = text.length;
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
- if (typeof(type) === "undefined") {
28
- spaces.call(this);
29
- expect.call(this, ',');
30
- return ;
31
- }
32
- if (type.substr(type.length - 2, 2) === "[]") {
33
- return nextArray.call(this, type.substr(0, type.length - 2));
34
- }
35
- switch (type) {
36
- case "boolean":
37
- return nextBoolean.call(this);
38
- case "int":
39
- return nextInt32.call(this);
40
- case "long":
41
- return nextInt64.call(this);
42
- case "float":
43
- case "double":
44
- return nextFloat.call(this);
45
- case "char":
46
- return nextChar.call(this);
47
- case "String":
48
- return nextString.call(this);
49
- default:
50
- throw new tc.UnsupportedType(type);
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
- var c = this.text.charAt(this.pos);
57
- return c === ' ' || c === '\t' || c === '\n';
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
- var c = this.text.charAt(this.pos);
62
- return c >= '0' && c <= '9';
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
- throw new ParseError(this.text, this.pos, message);
68
+ throw new ParseError(this.text, this.pos, message);
68
69
  }
69
70
 
70
71
  function checkPos() {
71
- if (this.pos >= this.len) {
72
- raiseHere.call(this, "unexpected end of input");
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
- checkPos.call(this);
79
- return this.text.charAt(this.pos);
78
+ checkPos.call(this);
79
+ return this.text.charAt(this.pos);
80
80
  }
81
81
 
82
82
  function spaces() {
83
- while (this.pos < this.len && isWhiteSpace.call(this)) {
84
- this.pos += 1;
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
- if (token.call(this) === character) {
90
- this.pos += 1;
91
- } else {
92
- raiseHere(this, "expecting <" + character + ">");
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
- spaces.call(this);
99
- if (this.text.substr(this.pos, 4).toUpperCase() === "TRUE") {
100
- this.pos += 4;
101
- return true;
102
- } else if (this.text.substr(this.pos, 5).toUpperCase() === "FALSE") {
103
- this.pos += 5;
104
- return false;
105
- }
106
- raiseHere.call(this, "expecting either true or false");
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
- checkPos.call(this);
112
- if (!isDigit.call(this)) {
113
- raiseHere.call(this, "expecting a digit");
114
- }
115
- var start = this.pos;
116
- while (true) {
117
- this.pos += 1;
118
- if (this.pos === this.len || !isDigit.call(this)) {
119
- break;
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
- return this.text.substr(start, this.pos - start);
123
- }
126
+ }
124
127
 
128
+ return this.text.substr(start, this.pos - start);
129
+ }
125
130
 
126
131
  function nextNaturalNumber(parser) {
127
- spaces.call(this);
128
- if (token.call(this) === "-") {
129
- this.pos += 1;
130
- return -parser(nextDigits.call(this));
131
- }
132
- return parser(nextDigits.call(this));
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
- return nextNaturalNumber.call(this, function (str) {
137
- return parseInt(str, 10);
138
- });
143
+ return nextNaturalNumber.call(this, function (str) {
144
+ return parseInt(str, 10);
145
+ });
139
146
  }
140
147
 
141
148
  function nextInt64() {
142
- var Int64 = require("long");
143
- return nextNaturalNumber.call(this, function (str) {
144
- return Int64.fromString(str);
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
- var str = nextDigits.call(this);
151
- if (this.pos < this.len) {
152
- if (this.text.charAt(this.pos) === '.') {
153
- this.pos += 1;
154
- str += "." + nextDigits.call(this);
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
- return parseFloat(str);
163
+ }
164
+
165
+ return parseFloat(str);
158
166
  }
159
167
 
160
168
  function nextFloat() {
161
- spaces.call(this);
162
- if (token.call(this) === '-') {
163
- this.pos += 1;
164
- return -nextPositiveFloat.call(this);
165
- }
166
- return nextPositiveFloat.call(this);
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
- spaces.call(this);
172
- var c = token.call(this);
173
- if (c === '\'') {
174
- this.pos += 1;
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
- return c;
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
- spaces.call(this);
187
- expect.call(this, '"');
188
- var start = this.pos;
189
- while (true) {
190
- if (this.pos >= this.len) {
191
- raiseHere.call(this, "expecting a closing quote");
192
- }
193
- if (token.call(this) === '"') {
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
- function nextElems(elemType, arr) {
211
- spaces.call(this);
212
- var c = token.call(this);
213
- if (c === ']') {
214
- this.pos += 1;
215
- return ;
216
- } else if (c === ',') {
217
- this.pos += 1;
218
- arr.push(this.next(elemType));
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
- raiseHere("expecting either <,> or <]>");
222
+ }
223
223
  }
224
224
 
225
- function nextArray(elemType) {
226
- var arr = [];
227
- spaces.call(this);
228
- expect.call(this, '[');
229
- spaces.call(this);
230
- if (token.call(this) === ']') {
231
- this.pos += 1;
232
- return arr;
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;