yhara-ticketmap 0.3.1

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 (47) hide show
  1. data/.gitignore +2 -0
  2. data/.gitmodules +3 -0
  3. data/MANIFEST +29 -0
  4. data/README.rdoc +20 -0
  5. data/Rakefile +52 -0
  6. data/TODO +82 -0
  7. data/VERSION +1 -0
  8. data/controller/config.rb +9 -0
  9. data/controller/init.rb +7 -0
  10. data/controller/main.rb +11 -0
  11. data/controller/tickets.rb +49 -0
  12. data/db/migrate/001_create_tickets.rb +14 -0
  13. data/db/migrate/002_add_deleted_to_tickets.rb +13 -0
  14. data/db/migrate/003_add_timeouted_to_tickets.rb +13 -0
  15. data/main.rb +40 -0
  16. data/model/init.rb +32 -0
  17. data/model/ticket.rb +49 -0
  18. data/public/biwascheme/lib/biwascheme.js +106 -0
  19. data/public/biwascheme/lib/dumper.js +192 -0
  20. data/public/biwascheme/lib/extra_lib.js +534 -0
  21. data/public/biwascheme/lib/io.js +326 -0
  22. data/public/biwascheme/lib/prototype.js +4320 -0
  23. data/public/biwascheme/lib/r6rs_lib.js +2439 -0
  24. data/public/biwascheme/lib/stackbase.js +1697 -0
  25. data/public/biwascheme/lib/webscheme_lib.js +809 -0
  26. data/public/js/builder.js +136 -0
  27. data/public/js/controls.js +965 -0
  28. data/public/js/dragdrop.js +975 -0
  29. data/public/js/effects.js +1130 -0
  30. data/public/js/scriptaculous.js +60 -0
  31. data/public/js/slider.js +275 -0
  32. data/public/js/sound.js +55 -0
  33. data/public/js/unittest.js +568 -0
  34. data/public/scm/board.scm +23 -0
  35. data/public/scm/hand.scm +48 -0
  36. data/public/scm/main.scm +69 -0
  37. data/public/scm/server.scm +30 -0
  38. data/public/scm/ticket.scm +44 -0
  39. data/spec/config.rb +13 -0
  40. data/spec/helper.rb +2 -0
  41. data/spec/main.rb +13 -0
  42. data/spec/models.rb +34 -0
  43. data/spec/tickets.rb +65 -0
  44. data/ticketmap.gemspec +96 -0
  45. data/view/index.xhtml +63 -0
  46. data/view/track.xhtml +29 -0
  47. metadata +131 -0
@@ -0,0 +1,106 @@
1
+ //for application
2
+
3
+
4
+ var BiwaScheme = {
5
+ Version: 0.5,
6
+
7
+ // load library and execute proc after loading
8
+ require: function(src, check, proc){
9
+ var script = document.createElement('script')
10
+ script.src = src;
11
+ document.body.appendChild(script);
12
+
13
+ var checker = new Function("return !!(" + check + ")");
14
+
15
+ if(checker()) proc();
16
+ else setTimeout(function(){ checker() ? proc() : setTimeout(arguments.callee, 10); }, 10);
17
+ }
18
+ };
19
+
20
+ (function(){ //local namespace
21
+ var require = BiwaScheme.require;
22
+
23
+ // taken from prototype.js 1.6.0
24
+ var readAttribute = function(element, name) {
25
+ if (/*Prototype.Browser.IE*/ !!(window.attachEvent && !window.opera)){
26
+ var t = {
27
+ names: {
28
+ 'class': 'className',
29
+ 'for': 'htmlFor'
30
+ },
31
+ values: {
32
+ _getAttr: function(element, attribute) {
33
+ return element.getAttribute(attribute, 2);
34
+ },
35
+ _getAttrNode: function(element, attribute) {
36
+ var node = element.getAttributeNode(attribute);
37
+ return node ? node.value : "";
38
+ },
39
+ _getEv: function(element, attribute) {
40
+ var attribute = element.getAttribute(attribute);
41
+ return attribute ? attribute.toString().slice(23, -2) : null;
42
+ },
43
+ _flag: function(element, attribute) {
44
+ return $(element).hasAttribute(attribute) ? attribute : null;
45
+ },
46
+ style: function(element) {
47
+ return element.style.cssText.toLowerCase();
48
+ },
49
+ title: function(element) {
50
+ return element.title;
51
+ }
52
+ }
53
+ };
54
+ if (t.values[name]) return t.values[name](element, name);
55
+ if (t.names[name]) name = t.names[name];
56
+ if (name.indexOf(':') > -1){
57
+ return (!element.attributes || !element.attributes[name]) ? null :
58
+ element.attributes[name].value;
59
+ }
60
+ }
61
+ return element.getAttribute(name);
62
+ }
63
+
64
+ // main
65
+ var script = (function(e){
66
+ if(e.id == '_firebugConsole'){
67
+ return arguments.callee(document.body);
68
+ }
69
+ else if(e.nodeName.toLowerCase() == 'script'){
70
+ return e;
71
+ }
72
+ else{
73
+ return arguments.callee(e.lastChild);
74
+ }
75
+ })(document);
76
+
77
+ var src = readAttribute(script, 'src');
78
+ var dir = src.match(/(.*)biwascheme.js/)[1];
79
+
80
+ require(dir+'prototype.js', 'window.$$', function(){
81
+ require(dir+'stackbase.js', 'window.BiwaScheme.CoreEnv', function(){
82
+ require(dir+'r6rs_lib.js', 'window.BiwaScheme.CoreEnv["+"]', function(){
83
+ require(dir+'webscheme_lib.js', 'window.BiwaScheme.CoreEnv["getelem"]', function(){
84
+ require(dir+'extra_lib.js', 'window.BiwaScheme.CoreEnv["print"]', function(){
85
+ require(dir+'dumper.js', 'window.BiwaScheme.Dumper', function(){
86
+ require(dir+'io.js', 'window.JSIO', function(){
87
+ var onError = function(e, state){
88
+ puts(e.message);
89
+ if($("biwascheme-debugger")){
90
+ var dumper = new BiwaScheme.Dumper($("biwascheme-debugger"));
91
+ dumper.dump(new Hash(state));
92
+ dumper.dump_move(1);
93
+ }
94
+ throw(e);
95
+ }
96
+ var intp = new BiwaScheme.Interpreter(onError);
97
+ try{
98
+ intp.evaluate(script.innerHTML, Prototype.emptyFunction);
99
+ }
100
+ catch(e){
101
+ onError(e);
102
+ }
103
+ })})})})})})});
104
+ })();
105
+
106
+ //vim: set ft=javascript:
@@ -0,0 +1,192 @@
1
+ //
2
+ // Dumper - graphical state dumper
3
+ //
4
+ with(BiwaScheme) {
5
+
6
+ BiwaScheme.Dumper = Class.create({
7
+ initialize: function(dumparea){
8
+ this.dumparea = dumparea || $("dumparea");
9
+ },
10
+
11
+ is_opc: function(obj){
12
+ return (obj instanceof Array && typeof(obj[0]) == 'string');
13
+ },
14
+
15
+ dump_pad: "   ",
16
+ dump_opc: function(obj, level){
17
+ var s="";
18
+ var pad1="", pad2="";
19
+ var level = level || 0;
20
+ level.times(function(){ pad1 += this.dump_pad; }.bind(this));
21
+ (level+1).times(function(){ pad2 += this.dump_pad; }.bind(this));
22
+
23
+ s += pad1 + '[<span class="dump_opecode">' + obj[0] + '</span>';
24
+ var i = 1;
25
+ while(!(obj[i] instanceof Array) && i<obj.length){
26
+ if(obj[0] == "constant")
27
+ s += "&nbsp;<span class='dump_constant'>" +
28
+ this.dump_obj(obj[i]) + "</span>";
29
+ else
30
+ s += "&nbsp;" + this.dump_obj(obj[i]);
31
+ i++;
32
+ }
33
+ if(i < obj.length) s += '<br>\n';
34
+ for(; i<obj.length; i++){
35
+ if(this.is_opc(obj[i])){
36
+ s += this.dump_opc(obj[i], (i == obj.length-1 ? level : level+1));
37
+ }
38
+ else{
39
+ s += (i == obj.length-1) ? pad1 : pad2;
40
+ s += this.dump_obj(obj[i]); //String(obj[i]).escapeHTML();
41
+ }
42
+ if(i != obj.length-1) s += "<br>\n";
43
+ }
44
+ s += "]";
45
+ return (level==0 ? this.add_fold(s) : s);
46
+ },
47
+
48
+ fold_limit: 20,
49
+ n_folds: 0,
50
+ add_fold: function(s){
51
+ var lines = s.split(/<br>/gmi);
52
+
53
+ if(lines.length > this.fold_limit){
54
+ var fold_btn = " <span style='text-decoration:underline; color:blue; cursor:pointer;'" +
55
+ "onclick='BiwaScheme.Dumper.toggle_fold("+this.n_folds+")'>more</span>"
56
+ var fold_start = "<div style='display:none' id='fold"+this.n_folds+"'>";
57
+ var fold_end = "</div>"
58
+ this.n_folds++;
59
+ return [
60
+ lines.slice(0, this.fold_limit).join("<br>"), fold_btn,
61
+ fold_start, lines.slice(this.fold_limit+1).join("<br>"), fold_end
62
+ ].join("");
63
+ }
64
+ else{
65
+ return s;
66
+ }
67
+ },
68
+
69
+ stack_max_len: 80,
70
+ dump_stack: function(stk, size){
71
+ if(stk === null || stk === undefined) return Object.inspect(stk)
72
+ var s = "<table>";
73
+ for(var i=stk.length-1; i >= 0; i--){
74
+ if(i < size){
75
+ s += "<tr><td class='dump_stknum'>[" + i + "]</td>" +
76
+ "<td>" + this.dump_obj(stk[i]).truncate(this.stack_max_len) +
77
+ "</td></tr>";
78
+ }
79
+ else{
80
+ s += "<tr><td class='dump_dead'>[" + i + "]</td>" +
81
+ "<td class='dump_dead'>" +
82
+ this.dump_obj(stk[i]).truncate(this.stack_max_len) +
83
+ "</td></tr>";
84
+ }
85
+ }
86
+ return s + "</table>";
87
+ },
88
+
89
+ dump_object: function(obj){
90
+ var a = [];
91
+ for(var k in obj){
92
+ //if(this.prototype[k]) continue;
93
+ a.push( k.toString() );//+" => "+this[k].toString() );
94
+ }
95
+ return "#<Object{"+a.join(",")+"}>";
96
+ },
97
+
98
+ closures: [],
99
+ dump_closure: function(cls){
100
+ if(cls.length == 0) return "[]";
101
+
102
+ var cls_num = null;
103
+ for(var i=0; i<this.closures.length; i++){
104
+ if(this.closures[i] == cls) cls_num = i;
105
+ }
106
+ if(cls_num == null){
107
+ cls_num = this.closures.length;
108
+ this.closures.push(cls);
109
+ }
110
+
111
+ var c = cls.clone ? cls.clone() : [c];
112
+ var body = c.shift();
113
+ return [
114
+ "c", cls_num, " <span class='dump_closure'>free vars :</span> ",
115
+ this.dump_obj(c), " <span class='dump_closure'>body :</span> ",
116
+ this.dump_obj(body).truncate(100)
117
+ ].join("");
118
+ },
119
+
120
+ dump_obj: function(obj){
121
+ if(obj && typeof(obj.to_html) == 'function')
122
+ return obj.to_html();
123
+ else{
124
+ var s = write_ss(obj, true); //true=Array mode
125
+ if(s == "[object Object]") s = this.dump_object(obj);
126
+ return s.escapeHTML();
127
+ }
128
+ },
129
+
130
+ n_dumps: 0,
131
+ dump: function(obj){
132
+ var dumpitem = document.createElement("div");
133
+ var s = "";
134
+ if(obj instanceof Hash){
135
+ s += "<table>"
136
+ s += "<tr><td colspan='4'>#"+this.n_dumps+"</td></tr>"
137
+ obj.each(function(pair){
138
+ if(pair.key!="x" && pair.key != "stack"){
139
+ var value = (pair.key=="c" ? this.dump_closure(pair.value)
140
+ : this.dump_obj(pair.value))
141
+ s += "<tr><td>" + pair.key + ": </td>" +
142
+ "<td colspan='3'>" + value + "</td></tr>";
143
+ }
144
+ }.bind(this));
145
+ s += "<tr><td>x:</td><td>" +
146
+ (this.is_opc(obj.get("x")) ? this.dump_opc(obj.get("x"))
147
+ : this.dump_obj(obj.get("x"))) +
148
+ "</td>";
149
+ s += "<td style='border-left: 1px solid black'>stack:</td><td>" +
150
+ this.dump_stack(obj.get("stack"), obj.get("s")) +
151
+ "</td></tr>";
152
+ s += "</table>";
153
+ }
154
+ else{
155
+ s = Object.inspect(obj).escapeHTML() + "<br>\n";
156
+ }
157
+ dumpitem.id = "dump" + this.n_dumps;
158
+ dumpitem.innerHTML = s;
159
+ this.dumparea.appendChild(dumpitem);
160
+ Element.hide(dumpitem);
161
+ this.n_dumps++;
162
+ },
163
+
164
+ cur: -1,
165
+ dump_move: function(dir){
166
+ if(0 <= this.cur && this.cur < this.n_dumps)
167
+ Element.hide($("dump"+this.cur));
168
+
169
+ if(0 <= this.cur+dir && this.cur+dir < this.n_dumps)
170
+ this.cur += dir;
171
+
172
+ Element.show($("dump"+this.cur));
173
+ },
174
+
175
+ is_folded: true,
176
+ dump_toggle_fold: function(){
177
+ if(this.is_folded){ //open all
178
+ for(var i=0; i<this.n_dumps; i++)
179
+ Element.show($("dump"+i));
180
+ }
181
+ else{ //close all
182
+ for(var i=0; i<this.n_dumps; i++)
183
+ if(i!=this.cur) Element.hide($("dump"+i));
184
+ }
185
+ this.is_folded = (!this.is_folded);
186
+ }
187
+ })
188
+ } // with(BiwaScheme);
189
+
190
+ BiwaScheme.Dumper.toggle_fold = function(n){
191
+ Element.toggle("fold"+n);
192
+ }
@@ -0,0 +1,534 @@
1
+
2
+ if( typeof(BiwaScheme)!='object' ) BiwaScheme={}; with(BiwaScheme) {
3
+ define_libfunc("html-escape", 1, 1, function(ar){
4
+ assert_string(ar[0]);
5
+ return ar[0].escapeHTML();
6
+ });
7
+ BiwaScheme.inspect_objs = function(objs){
8
+ return objs.map(function(obj){
9
+ if(obj.inspect)
10
+ return obj.inspect();
11
+ else
12
+ return Object.inspect($H(obj));
13
+ }).join(" ");
14
+ };
15
+ define_libfunc("inspect", 1, null, function(ar){
16
+ return BiwaScheme.inspect_objs(ar);
17
+ });
18
+ define_libfunc("inspect!", 1, null, function(ar){
19
+ return puts(BiwaScheme.inspect_objs(ar));
20
+ });
21
+
22
+ //
23
+ // json
24
+ //
25
+ // json->sexp
26
+ // Array -> list
27
+ // Object -> alist
28
+ // (number, boolean, string,
29
+ //
30
+ BiwaScheme.json2sexp = function(json){
31
+ switch(true){
32
+ case Object.isNumber(json) ||
33
+ Object.isString(json) ||
34
+ json === true || json === false:
35
+ return json;
36
+ case Object.isArray(json):
37
+ return json.map(function(item){
38
+ return json2sexp(item);
39
+ }).to_list();
40
+ case typeof(json) == "object":
41
+ var ls = nil;
42
+ for(key in json){
43
+ ls = new Pair(new Pair(key, json2sexp(json[key])),
44
+ ls);
45
+ }
46
+ return ls;
47
+ default:
48
+ throw new Error("json->sexp: detected invalid value for json: "+Object.inspect(json));
49
+ }
50
+ throw new Bug("must not happen");
51
+ }
52
+ define_libfunc("json->sexp", 1, 1, function(ar){
53
+ return json2sexp(ar[0]);
54
+ })
55
+
56
+ //
57
+ //from Gauche
58
+ //
59
+
60
+ define_libfunc("string-concat", 1, 1, function(ar){
61
+ assert_pair(ar[0]);
62
+ return ar[0].to_array().join("");
63
+ })
64
+ define_libfunc("string-split", 2, 2, function(ar){
65
+ assert_string(ar[0]);
66
+ assert_string(ar[1]);
67
+ return ar[0].split(ar[1]).to_list();
68
+ })
69
+ define_libfunc("string-join", 1, 2, function(ar){
70
+ assert_pair(ar[0]);
71
+ var delim = ""
72
+ if(ar[1]){
73
+ assert_string(ar[1]);
74
+ delim = ar[1];
75
+ }
76
+ return ar[0].to_array().join(delim);
77
+ })
78
+
79
+ define_libfunc("intersperse", 2, 2, function(ar){
80
+ var item = ar[0], ls = ar[1];
81
+ assert_pair(ls);
82
+
83
+ var ret = [];
84
+ ls.to_array().reverse().each(function(x){
85
+ ret.push(x);
86
+ ret.push(item);
87
+ });
88
+ ret.pop();
89
+ return ret.to_list();
90
+ });
91
+
92
+ define_libfunc("map-with-index", 2, null, function(ar){
93
+ var proc = ar.shift(), lists = ar;
94
+ lists.each(function(ls){ assert_pair(ls) });
95
+
96
+ var results = [], i = 0;
97
+ return Call.multi_foreach(lists, {
98
+ call: function(xs){
99
+ var args = xs.map(function(x){ return x.car });
100
+ args.unshift(i);
101
+ i++;
102
+ return new Call(proc, args);
103
+ },
104
+ result: function(res){ results.push(res); },
105
+ finish: function(){ return results.to_list(); }
106
+ });
107
+ });
108
+
109
+ //(define-macro (foo x) body ...)
110
+ //(define-macro foo lambda)
111
+
112
+ var rearrange_args = function (expected, given) {
113
+ var args = [];
114
+ var dotpos = (new Compiler).find_dot_pos(expected);
115
+ if (dotpos == -1)
116
+ args = given;
117
+ else {
118
+ for (var i = 0; i < dotpos; i++)
119
+ args[i] = given[i];
120
+ args[i] = given.slice(i).to_list();
121
+ }
122
+ return args;
123
+ }
124
+ define_syntax("define-macro", function(x){
125
+ var head = x.cdr.car;
126
+ var expected_args;
127
+ if(head instanceof Pair){
128
+ var name = head.car;
129
+ expected_args = head.cdr;
130
+ var body = x.cdr.cdr;
131
+ var lambda = new Pair(Sym("lambda"),
132
+ new Pair(expected_args,
133
+ body))
134
+ }
135
+ else{
136
+ var name = head;
137
+ var lambda = x.cdr.cdr.car;
138
+ expected_args = lambda.cdr.car;
139
+ }
140
+
141
+ //[close, n_frees, do_body, next]
142
+ var opc = Compiler.compile(lambda);
143
+ if(opc[1] != 0)
144
+ throw new Bug("you cannot use free variables in macro expander (or define-macro must be on toplevel)")
145
+ var cls = [opc[2]];
146
+
147
+ TopEnv[name.name] = new Syntax(name.name, function(sexp){
148
+ var given_args = sexp.to_array();
149
+
150
+ given_args.shift();
151
+
152
+ var intp = new Interpreter();
153
+ var args = rearrange_args(expected_args, given_args);
154
+ var result = intp.invoke_closure(cls, args);
155
+ return result;
156
+ });
157
+
158
+ return BiwaScheme.undef;
159
+ })
160
+
161
+ var macroexpand_1 = function(x){
162
+ if(x instanceof Pair){
163
+ if(x.car instanceof Symbol && TopEnv[x.car.name] instanceof Syntax){
164
+ var transformer = TopEnv[x.car.name];
165
+ x = transformer.transform(x);
166
+ }
167
+ else
168
+ throw new Error("macroexpand-1: `" + to_write_ss(x) + "' is not a macro");
169
+ }
170
+ return x;
171
+ }
172
+ define_syntax("%macroexpand", function(x){
173
+ var expanded = (new Interpreter).expand(x.cdr.car);
174
+ return [Sym("quote"), expanded].to_list();
175
+ });
176
+ define_syntax("%macroexpand-1", function(x){
177
+ var expanded = macroexpand_1(x.cdr.car);
178
+ return [Sym("quote"), expanded].to_list();
179
+ });
180
+
181
+ define_libfunc("macroexpand", 1, 1, function(ar){
182
+ return (new Interpreter).expand(ar[0]);
183
+ });
184
+ define_libfunc("macroexpand-1", 1, 1, function(ar){
185
+ return macroexpand_1(ar[0]);
186
+ });
187
+
188
+ define_libfunc("print", 1, null, function(ar){
189
+ ar.map(function(item){
190
+ puts(to_display(item), true);
191
+ })
192
+ puts(""); //newline
193
+ return BiwaScheme.undef;
194
+ })
195
+ define_syntax("let1", function(x){
196
+ //(let1 vari expr body ...)
197
+ //=> ((lambda (var) body ...) expr)
198
+ var vari = x.cdr.car;
199
+ var expr = x.cdr.cdr.car;
200
+ var body = x.cdr.cdr.cdr;
201
+
202
+ return new Pair(new Pair(Sym("lambda"),
203
+ new Pair(new Pair(vari, nil),
204
+ body)),
205
+ new Pair(expr, nil));
206
+ })
207
+
208
+ define_libfunc("write-to-string", 1, 1, function(ar){
209
+ return to_write(ar[0]);
210
+ });
211
+ define_libfunc("read-from-string", 1, 1, function(ar){
212
+ assert_string(ar[0]);
213
+ return Interpreter.read(ar[0]);
214
+ });
215
+
216
+ //
217
+ // srfi
218
+ //
219
+
220
+ // srfi-1 (list)
221
+ define_libfunc("iota", 1, 3, function(ar){
222
+ var count = ar[0];
223
+ var start = ar[1] || 0;
224
+ var step = (ar[2]===undefined) ? 1 : ar[2];
225
+ assert_integer(count);
226
+ assert_number(start);
227
+ assert_number(step);
228
+
229
+ var a = [], n = start;
230
+ for(var i=0; i<count; i++){
231
+ a.push(n);
232
+ n += step;
233
+ }
234
+ return a.to_list();
235
+ });
236
+
237
+ // srfi-6 & Gauche (string port)
238
+ BiwaScheme.Port.StringOutput = Class.create(Port, {
239
+ initialize: function($super){
240
+ this.buffer = [];
241
+ $super(false, true);
242
+ },
243
+ put_string: function(str){
244
+ this.buffer.push(str);
245
+ },
246
+ output_string: function(str){
247
+ return this.buffer.join("");
248
+ }
249
+ });
250
+ BiwaScheme.Port.StringInput = Class.create(Port, {
251
+ initialize: function($super){
252
+ $super(true, false);
253
+ },
254
+ get_string: function(after){
255
+ }
256
+ });
257
+ define_libfunc("open-input-string", 1, 1, function(ar){
258
+ assert_string(ar[0]);
259
+ return new Port.StringInput(ar[0]);
260
+ })
261
+ define_libfunc("open-output-string", 0, 0, function(ar){
262
+ return new Port.StringOutput();
263
+ })
264
+ define_libfunc("get-output-string", 1, 1, function(ar){
265
+ assert_port(ar[0]);
266
+ if(!(ar[0] instanceof Port.StringOutput))
267
+ throw new Error("get-output-string: port must be made by 'open-output-string'");
268
+ return ar[0].output_string();
269
+ })
270
+
271
+ // srfi-19 (time)
272
+ //
273
+ // // constants
274
+ //time-duration
275
+ //time-monotonic
276
+ //time-process
277
+ //time-tai
278
+ //time-thread
279
+ //time-utc
280
+ // Current time and clock resolution
281
+ define_libfunc("current-date", 0, 1, function(ar){
282
+ //todo: tz-offset (ar[1])
283
+ return new Date();
284
+ })
285
+ //
286
+ //current-julian-day -> jdn
287
+ //current-modified-julian-day -> mjdn
288
+ //current-time [time-type] -> time
289
+ //time-resolution [time-type] -> integer
290
+ // // Time object and accessors
291
+ //make-time type nanosecond second -> time
292
+ //time? object -> boolean
293
+ //time-type time -> time-type
294
+ //time-nanosecond time -> integer
295
+ //time-second time -> integer
296
+ //set-time-type! time time-type
297
+ //set-time-nanosecond! time integer
298
+ //set-time-second! time integer
299
+ //copy-time time1 -> time2
300
+ // // Time comparison procedures
301
+ //time<=? time1 time2 -> boolean
302
+ //time<? time1 time2 -> boolean
303
+ //time=? time1 time2 -> boolean
304
+ //time>=? time1 time2 -> boolean
305
+ //time>? time1 time2 -> boolean
306
+ // // Time arithmetic procedures
307
+ //time-difference time1 time2 -> time-duration
308
+ //time-difference! time1 time2 -> time-duration
309
+ //add-duration time1 time-duration -> time
310
+ //add-duration! time1 time-duration -> time
311
+ //subtract-duration time1 time-duration -> time
312
+ //subtract-duration! time1 time-duration -> time
313
+ // Date object and accessors
314
+ // make-date
315
+ define_libfunc("date?", 1, 1, function(ar){
316
+ return (ar[0] instanceof Date);
317
+ })
318
+ define_libfunc("date-nanosecond", 1, 1, function(ar){
319
+ assert_date(ar[0]);
320
+ return ar[0].getMilliseconds() * 1000000;
321
+ })
322
+ define_libfunc("date-millisecond", 1, 1, function(ar){ // not srfi-19
323
+ assert_date(ar[0]);
324
+ return ar[0].getMilliseconds();
325
+ })
326
+ define_libfunc("date-second", 1, 1, function(ar){
327
+ assert_date(ar[0]);
328
+ return ar[0].getSeconds();
329
+ })
330
+ define_libfunc("date-minute", 1, 1, function(ar){
331
+ assert_date(ar[0]);
332
+ return ar[0].getMinutes();
333
+ })
334
+ define_libfunc("date-hour", 1, 1, function(ar){
335
+ assert_date(ar[0]);
336
+ return ar[0].getHours();
337
+ })
338
+ define_libfunc("date-day", 1, 1, function(ar){
339
+ assert_date(ar[0]);
340
+ return ar[0].getDate();
341
+ })
342
+ define_libfunc("date-month", 1, 1, function(ar){
343
+ assert_date(ar[0]);
344
+ return ar[0].getMonth() + 1; //Jan = 0 in javascript..
345
+ })
346
+ define_libfunc("date-year", 1, 1, function(ar){
347
+ assert_date(ar[0]);
348
+ return ar[0].getFullYear();
349
+ })
350
+ //date-zone-offset
351
+ //date-year-day
352
+ define_libfunc("date-week-day", 1, 1, function(ar){
353
+ assert_date(ar[0]);
354
+ return ar[0].getDay();
355
+ })
356
+ //date-week-number
357
+
358
+ // Time/Date/Julian Day/Modified Julian Day Converters
359
+ // (snipped)
360
+
361
+ // Date to String/String to Date Converters
362
+ // TODO: support locale
363
+ // * date_names
364
+ // * ~f 5.2 sec
365
+ // * ~p AM/PM
366
+ // * ~X 2007/01/01
367
+ BiwaScheme.date_names = {
368
+ weekday: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
369
+ full_weekday: ["Sunday", "Monday", "Tuesday",
370
+ "Wednesday", "Thursday", "Friday", "Saturday"],
371
+ month: ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
372
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
373
+ full_month: ["January", "February", "March", "April",
374
+ "May", "June", "July", "August", "September",
375
+ "Octorber", "November", "December"]
376
+ }
377
+
378
+ BiwaScheme.date2string = function(date, format){
379
+ var zeropad = function(n){ return n<10 ? "0"+n : ""+n };
380
+ var spacepad = function(n){ return n<10 ? " "+n : ""+n };
381
+
382
+ var getter = {
383
+ a: function(x){ return date_names.weekday[x.getDay()] },
384
+ A: function(x){ return date_names.full_weekday[x.getDay()] },
385
+ b: function(x){ return date_names.month[x.getMonth()] },
386
+ B: function(x){ return date_names.full_month[x.getMonth()] },
387
+ c: function(x){ return x.toString() },
388
+ d: function(x){ return zeropad(x.getDate()) },
389
+ D: function(x){ return getter.d(x) + getter.m(x) + getter.y(x); },
390
+ e: function(x){ return spacepad(x.getDate()) },
391
+ f: function(x){ return x.getSeconds() + x.getMilliseconds()/1000; },
392
+ h: function(x){ return date_names.month[x.getMonth()] },
393
+ H: function(x){ return zeropad(x.getHours()) },
394
+ I: function(x){ var h = x.getHours(); return zeropad(h<13 ? h : h-12) },
395
+ j: function(x){ throw new Bug("not implemented: day of year") },
396
+ k: function(x){ return spacepad(x.getHours()) },
397
+ l: function(x){ var h = x.getHours(); return spacepad(h<13 ? h : h-12) },
398
+ m: function(x){ return zeropad(x.getMonth()) },
399
+ M: function(x){ return zeropad(x.getMinutes()) },
400
+ n: function(x){ return "\n" },
401
+ N: function(x){ throw new Bug("not implemented: nanoseconds") },
402
+ p: function(x){ return x.getHours()<13 ? "AM" : "PM" },
403
+ r: function(x){ return getter.I(x) + ":" + getter.M(x) + ":" + getter.S(x) + " " + getter.p(x) },
404
+ s: function(x){ return Math.floor(x.getTime() / 1000) },
405
+ S: function(x){ return zeropad(x.getSeconds()) },
406
+ t: function(x){ return "\t" },
407
+ T: function(x){ return getter.H(x) + ":" + getter.M(x) + ":" + getter.S(x) },
408
+ U: function(x){ throw new Bug("not implemented: weeknum(0~, Sun)") },
409
+ V: function(x){ throw new Bug("not implemented: weeknum(1~, Sun?)") },
410
+ w: function(x){ return x.getDay() },
411
+ W: function(x){ throw new Bug("not implemented: weeknum(0~, Mon)") },
412
+ x: function(x){ throw new Bug("not implemented: weeknum(1~, Mon)") },
413
+ X: function(x){ return getter.Y(x) + "/" + getter.m(x) + "/" + getter.d(x) },
414
+ y: function(x){ return x.getFullYear() % 100 },
415
+ Y: function(x){ return x.getFullYear() },
416
+ z: function(x){ throw new Bug("not implemented: time-zone") },
417
+ Z: function(x){ throw new Bug("not implemented: symbol time zone") },
418
+ 1: function(x){ throw new Bug("not implemented: ISO-8601 year-month-day format") },
419
+ 2: function(x){ throw new Bug("not implemented: ISO-8601 hour-minute-second-timezone format") },
420
+ 3: function(x){ throw new Bug("not implemented: ISO-8601 hour-minute-second format") },
421
+ 4: function(x){ throw new Bug("not implemented: ISO-8601 year-month-day-hour-minute-second-timezone format") },
422
+ 5: function(x){ throw new Bug("not implemented: ISO-8601 year-month-day-hour-minute-second format") }
423
+ }
424
+
425
+ return format.replace(/~([\w1-5~])/g, function(_, x){
426
+ var func = getter[x];
427
+ if(func)
428
+ return func(date);
429
+ else if(x == "~")
430
+ return "~";
431
+ else
432
+ return x;
433
+ })
434
+ }
435
+
436
+ // date->string
437
+ define_libfunc("date->string", 1, 2, function(ar){
438
+ assert_date(ar[0]);
439
+
440
+ if(ar[1]){
441
+ assert_string(ar[1]);
442
+ return date2string(ar[0], ar[1]);
443
+ }
444
+ else
445
+ return ar[0].toString();
446
+ })
447
+ // string->date
448
+
449
+ define_libfunc("parse-date", 1, 1, function(ar){ // not srfi-19
450
+ assert_string(ar[0]);
451
+ return new Date(Date.parse(ar[0]));
452
+ })
453
+
454
+ //
455
+ // srfi-38 (write/ss)
456
+ //
457
+ var user_write_ss = function(ar){
458
+ puts(write_ss(ar[0]), true);
459
+ return BiwaScheme.undef;
460
+ }
461
+ define_libfunc("write/ss", 1, 2, user_write_ss);
462
+ define_libfunc("write-with-shared-structure", 1, 2, user_write_ss);
463
+ define_libfunc("write*", 1, 2, user_write_ss); //from Gauche(STklos)
464
+
465
+ //
466
+ // srfi-43 (vector library)
467
+ //
468
+ define_libfunc("vector-append", 2, null, function(ar){
469
+ var vec = [];
470
+ return vec.concat.apply(vec, ar);
471
+ })
472
+
473
+ //
474
+ // Regular Expression
475
+ //
476
+ var assert_regexp = function(obj, fname){
477
+ if(!(obj instanceof RegExp))
478
+ throw new Error(fname + ": regexp required, but got " + to_write(obj));
479
+ }
480
+
481
+ //Function: string->regexp string &keyword case-fold
482
+ define_libfunc("string->regexp", 1, 1, function(ar){
483
+ assert_string(ar[0], "string->regexp");
484
+ return new RegExp(ar[0]); //todo: case-fold
485
+ })
486
+ //Function: regexp? obj
487
+ define_libfunc("regexp?", 1, 1, function(ar){
488
+ return (ar[0] instanceof RegExp);
489
+ })
490
+ //Function: regexp->string regexp
491
+ define_libfunc("regexp->string", 1, 1, function(ar){
492
+ assert_regexp(ar[0], "regexp->string");
493
+ return ar[0].toString().slice(1, -1); //cut '/'
494
+ })
495
+
496
+ define_libfunc("regexp-exec", 2, 2, function(ar){
497
+ var rexp = ar[0];
498
+ if(Object.isString(ar[0])){
499
+ rexp = new RegExp(ar[0]);
500
+ }
501
+ assert_regexp(rexp, "regexp-exec");
502
+ assert_string(ar[1], "regexp-exec");
503
+ var ret = rexp.exec(ar[1])
504
+ return (ret === null) ? false : ret.to_list();
505
+ })
506
+
507
+ // //Function: rxmatch regexp string
508
+ // define_libfunc("rxmatch", 1, 1, function(ar){
509
+ // assert_regexp(ar[0], "rxmatch");
510
+ // assert_string(ar[1], "rxmatch");
511
+ // return ar[0].match(ar[1]);
512
+ // });
513
+ //Function: rxmatch-start match &optional (i 0)
514
+ //Function: rxmatch-end match &optional (i 0)
515
+ //Function: rxmatch-substring match &optional (i 0)
516
+ //Function: rxmatch-num-matches match
517
+ //Function: rxmatch-after match &optional (i 0)
518
+ //Function: rxmatch-before match &optional (i 0)
519
+ //Generic application: regmatch &optional index
520
+ //Generic application: regmatch 'before &optional index
521
+ //Generic application: regmatch 'after &optional index
522
+ //Function: regexp-replace regexp string substitution
523
+ //Function: regexp-replace-all regexp string substitution
524
+ //Function: regexp-replace* string rx1 sub1 rx2 sub2 ...
525
+ //Function: regexp-replace-all* string rx1 sub1 rx2 sub2 ...
526
+ //Function: regexp-quote string
527
+ //Macro: rxmatch-let match-expr (var ...) form ...
528
+ //Macro: rxmatch-if match-expr (var ...) then-form else-form
529
+ //Macro: rxmatch-cond clause ...
530
+ //Macro: rxmatch-case string-expr clause ...
531
+
532
+ }
533
+
534
+