rubybreaker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/AUTHORS +7 -0
  2. data/LICENSE +26 -0
  3. data/README.md +403 -0
  4. data/Rakefile +90 -0
  5. data/TODO +30 -0
  6. data/bin/gen_stub_rubylib +64 -0
  7. data/bin/rubybreaker +67 -0
  8. data/lib/rubybreaker/context.rb +122 -0
  9. data/lib/rubybreaker/debug.rb +48 -0
  10. data/lib/rubybreaker/error.rb +59 -0
  11. data/lib/rubybreaker/rubylib/core.rb +2316 -0
  12. data/lib/rubybreaker/rubylib.rb +3 -0
  13. data/lib/rubybreaker/runtime/inspector.rb +57 -0
  14. data/lib/rubybreaker/runtime/monitor.rb +235 -0
  15. data/lib/rubybreaker/runtime/object_wrapper.rb +77 -0
  16. data/lib/rubybreaker/runtime/overrides.rb +42 -0
  17. data/lib/rubybreaker/runtime/pluggable.rb +57 -0
  18. data/lib/rubybreaker/runtime/type_placeholder.rb +27 -0
  19. data/lib/rubybreaker/runtime/type_system.rb +228 -0
  20. data/lib/rubybreaker/runtime/typesig_parser.rb +45 -0
  21. data/lib/rubybreaker/runtime.rb +103 -0
  22. data/lib/rubybreaker/test/testcase.rb +39 -0
  23. data/lib/rubybreaker/test.rb +1 -0
  24. data/lib/rubybreaker/type/type.rb +241 -0
  25. data/lib/rubybreaker/type/type_comparer.rb +143 -0
  26. data/lib/rubybreaker/type/type_grammar.treetop +285 -0
  27. data/lib/rubybreaker/type/type_unparser.rb +142 -0
  28. data/lib/rubybreaker/type.rb +2 -0
  29. data/lib/rubybreaker/typing/rubytype.rb +47 -0
  30. data/lib/rubybreaker/typing/subtyping.rb +480 -0
  31. data/lib/rubybreaker/typing.rb +3 -0
  32. data/lib/rubybreaker/util.rb +31 -0
  33. data/lib/rubybreaker.rb +193 -0
  34. data/test/integrated/tc_method_missing.rb +30 -0
  35. data/test/integrated/tc_simple1.rb +77 -0
  36. data/test/runtime/tc_obj_wrapper.rb +73 -0
  37. data/test/runtime/tc_typesig_parser.rb +33 -0
  38. data/test/ts_integrated.rb +4 -0
  39. data/test/ts_runtime.rb +5 -0
  40. data/test/ts_type.rb +5 -0
  41. data/test/ts_typing.rb +4 -0
  42. data/test/type/tc_comparer.rb +211 -0
  43. data/test/type/tc_parser.rb +219 -0
  44. data/test/type/tc_unparser.rb +276 -0
  45. data/test/typing/tc_rubytype.rb +63 -0
  46. data/test/typing/tc_typing.rb +219 -0
  47. data/webpage/footer.html +5 -0
  48. data/webpage/generated_toc.js +319 -0
  49. data/webpage/header.html +14 -0
  50. data/webpage/images/logo.png +0 -0
  51. data/webpage/index.html +439 -0
  52. data/webpage/rubybreaker.css +53 -0
  53. metadata +119 -0
@@ -0,0 +1,319 @@
1
+ /** Generated TOC
2
+ Stuart Langridge, July 2007
3
+
4
+ Generate a table of contents, based on headings in the page.
5
+
6
+ To place the TOC on the page, add
7
+
8
+ <div id="generated-toc"></div>
9
+
10
+ to the page where you want the TOC to appear. If this element
11
+ is not present, the TOC will not appear.
12
+
13
+ The TOC defaults to displaying all headings that are contained within
14
+ the same element as it itself is contained in (or all headings on the
15
+ page if you did not provide a generated-toc container). To override this,
16
+ provide a "highest heading" value by adding class="generate_from_h3"
17
+ (or h2, h4, etc) to the container. (If unspecified, this will display all
18
+ headings, as if class="generate_from_h1" was specified.)
19
+
20
+ The TOC defaults to operating only on headings contained within the same
21
+ element as it itself, i.e., in a page like this:
22
+
23
+ <div>
24
+ <div>
25
+ <div id="generated-toc"></div>
26
+ <h1>foo</h1>
27
+ <h2>bar</h2>
28
+ </div>
29
+ <h1>quux</h1>
30
+ </div>
31
+
32
+ The "quux" heading will not appear in the TOC. To override this,
33
+ add class="generate_for_page" to the container, which will process
34
+ all headings on the page wheresoever they may be.
35
+
36
+ REVISIONS:
37
+
38
+ 05/05/12 David An - Remove skip table of content (link)
39
+
40
+ */
41
+
42
+ generated_toc = {
43
+ generate: function() {
44
+ // Identify our TOC element, and what it applies to
45
+ generate_from = '0';
46
+ generate_for = 'unset';
47
+ tocparent = document.getElementById('generated-toc');
48
+ if (tocparent) {
49
+ // there is a div class="generated-toc" in the document
50
+ // dictating where the TOC should appear
51
+ classes = tocparent.className.split(/\s+/);
52
+ for (var i=0; i<classes.length; i++) {
53
+ // if it specifies which heading level to generate from,
54
+ // or what level to generate for, save these specifications
55
+ if (classes[i].match(/^generate_from_h[1-6]$/)) {
56
+ generate_from = classes[i].substr(classes[i].length-1,1);
57
+ } else if (classes[i].match(/^generate_for_[a-z]+$/)) {
58
+ generate_for = classes[i].match(/^generate_for_([a-z])+$/)[1];
59
+ }
60
+ }
61
+ } else {
62
+ // They didn't specify a TOC element; exit
63
+ return;
64
+ }
65
+
66
+ // set top_node to be the element in the document under which
67
+ // we'll be analysing headings
68
+ if (generate_for == 'page') {
69
+ top_node = document.getElementsByTagName('body');
70
+ } else {
71
+ // i.e., explicitly set to "parent", left blank (so "unset"),
72
+ // or some invalid value
73
+ top_node = tocparent.parentNode;
74
+ }
75
+
76
+ // If there isn't a specified header level to generate from, work
77
+ // out what the first header level inside top_node is
78
+ // and make that the specified header level
79
+ if (generate_from == 0) {
80
+ first_header_found = generated_toc.findFirstHeader(top_node);
81
+ if (!first_header_found) {
82
+ // there were no headers at all inside top_node!
83
+ return;
84
+ } else {
85
+ generate_from = first_header_found.toLowerCase().substr(1);
86
+ }
87
+ }
88
+
89
+ // add all levels of heading we're paying attention to to the
90
+ // headings_to_treat dictionary, ready to be filled in later
91
+ headings_to_treat = {"h6":''};
92
+ for (var i=5; i>= parseInt(generate_from); i--) {
93
+ headings_to_treat["h" + i] = '';
94
+ }
95
+
96
+ // get headings. We can't say
97
+ // getElementsByTagName("h1" or "h2" or "h3"), etc, so get all
98
+ // elements and filter them ourselves
99
+ // need to use .all here because IE doesn't support gEBTN('*')
100
+ nodes = top_node.all ? top_node.all : top_node.getElementsByTagName('*');
101
+
102
+ // put all the headings we care about in headings
103
+ headings = [];
104
+ for (var i=0; i<nodes.length;i++) {
105
+ if (nodes[i].nodeName.toLowerCase() in headings_to_treat) {
106
+ // if heading has class no-TOC, skip it
107
+ if ((' ' + nodes[i].className + ' ').indexOf('no-TOC') != -1) {
108
+ continue;
109
+ }
110
+ headings.push(nodes[i]);
111
+ }
112
+ }
113
+
114
+ // make the basic elements of the TOC itself, ready to fill into
115
+
116
+ // first, check if there's a cookie defined to save the state as open
117
+ status = generated_toc.readCookie("generated_toc_display");
118
+ if (status && status == "open") {
119
+ display_initially = "block";
120
+ toggle_initially = "Hide table of contents";
121
+ } else {
122
+ display_initially = "none";
123
+ toggle_initially = "Show table of contents";
124
+ }
125
+
126
+ cur_head_lvl = "h" + generate_from;
127
+ cur_list_el = document.createElement('ul');
128
+ cur_list_el.style.display = display_initially;
129
+ p = document.createElement('p');
130
+ span = document.createElement('span');
131
+ span.className = 'hidden';
132
+ a = document.createElement('a');
133
+ a.href = '#aftertoc';
134
+ // a.appendChild(document.createTextNode('skip table of contents'));
135
+ span.appendChild(a);
136
+ p.appendChild(span);
137
+ tocparent.appendChild(p);
138
+ p = document.createElement('p');
139
+ p.id = 'toggle-container';
140
+ a = document.createElement('a');
141
+ a.id = 'generated_toc_d_toggle';
142
+ a.appendChild(document.createTextNode(toggle_initially));
143
+ p.appendChild(a);
144
+ a.onclick = generated_toc.wrapOpenClose(a,cur_list_el);
145
+ a.href = '#';
146
+ tocparent.appendChild(p);
147
+ tocparent.appendChild(cur_list_el);
148
+
149
+ // now walk through our saved heading nodes
150
+ for (var i=0; i<headings.length; i++) {
151
+ this_head_el = headings[i];
152
+ this_head_lvl = headings[i].nodeName.toLowerCase();
153
+ if (!this_head_el.id) {
154
+ // if heading doesn't have an ID, give it one
155
+ this_head_el.id = 'heading_toc_j_' + i;
156
+ this_head_el.setAttribute('tabindex','-1');
157
+ }
158
+
159
+ while(this_head_lvl > cur_head_lvl) {
160
+ // this heading is at a lower level than the last one;
161
+ // create additional nested lists to put it at the right level
162
+
163
+ // get the *last* LI in the current list, and add our new UL to it
164
+ var last_listitem_el = null;
165
+ for (var j=0; j<cur_list_el.childNodes.length; j++) {
166
+ if (cur_list_el.childNodes[j].nodeName.toLowerCase() == 'li') {
167
+ last_listitem_el = cur_list_el.childNodes[j];
168
+ }
169
+ }
170
+ if (!last_listitem_el) {
171
+ // there aren't any LIs, so create a new one to add the UL to
172
+ last_listitem_el = document.createElement('li');
173
+ }
174
+ new_list_el = document.createElement('ul');
175
+ last_listitem_el.appendChild(new_list_el);
176
+ cur_list_el.appendChild(last_listitem_el);
177
+ cur_list_el = new_list_el;
178
+ cur_head_lvl = 'h' + (parseInt(cur_head_lvl.substr(1,1)) + 1);
179
+ }
180
+
181
+ while (this_head_lvl < cur_head_lvl) {
182
+ // this heading is at a higher level than the last one;
183
+ // go back up the TOC to put it at the right level
184
+ cur_list_el = cur_list_el.parentNode.parentNode;
185
+ cur_head_lvl = 'h' + (parseInt(cur_head_lvl.substr(1,1)) - 1);
186
+ }
187
+
188
+ // create a link to this heading, and add it to the TOC
189
+ li = document.createElement('li');
190
+ a = document.createElement('a');
191
+ a.href = '#' + this_head_el.id;
192
+ a.appendChild(document.createTextNode(generated_toc.innerText(this_head_el)));
193
+ li.appendChild(a);
194
+ cur_list_el.appendChild(li);
195
+ }
196
+
197
+ // add an aftertoc paragraph as destination for the skip-toc link
198
+ p = document.createElement('p');
199
+ p.id = 'aftertoc';
200
+ tocparent.appendChild(p);
201
+
202
+ // go through the TOC and find all LIs that are "empty", i.e., contain
203
+ // only ULs and no links, and give them class="missing"
204
+ var alllis = tocparent.getElementsByTagName("li");
205
+ for (var i=0; i<alllis.length; i++) {
206
+ var foundlink = false;
207
+ for (var j=0; j<alllis[i].childNodes.length; j++) {
208
+ if (alllis[i].childNodes[j].nodeName.toLowerCase() == 'a') {
209
+ foundlink = true;
210
+ }
211
+ }
212
+ if (!foundlink) {
213
+ alllis[i].className = "missing";
214
+ } else {
215
+ alllis[i].className = "notmissing";
216
+ }
217
+ }
218
+
219
+ },
220
+
221
+ wrapOpenClose: function(a, cur_list_el) {
222
+ // we return a function here so that it acts as a closure;
223
+ // in essence the inner function, which is the event handler
224
+ // for clicking on the toggle-toc link, remembers the a and cur_list_el
225
+ // elements as they are when they're passed in to it.
226
+ // This is an explicit function rather than an anonymous function
227
+ // defined where it's called so it's easier to understand.
228
+ return function(e) {
229
+ d = cur_list_el.style.display;
230
+ a.firstChild.nodeValue = (d == 'block' ? 'Show' : 'Hide') + ' table of contents';
231
+ a.className = (d == 'block' ? 'toggle-closed' : 'toggle-open');
232
+ cur_list_el.style.display = d == 'block' ? 'none' : 'block';
233
+ // set a cookie to "open" or "closed" to save the state of the TOC
234
+ if (cur_list_el.style.display == "block") {
235
+ generated_toc.createCookie("generated_toc_display","open",21);
236
+ } else {
237
+ generated_toc.createCookie("generated_toc_display","closed",21);
238
+ }
239
+ if (window.event) {
240
+ window.event.returnValue = false;
241
+ window.event.cancelBubble = true;
242
+ } else {
243
+ e.preventDefault();
244
+ e.stopPropagation();
245
+ }
246
+ }
247
+ },
248
+
249
+ /* cookie handling: http://www.quirksmode.org/js/cookies.html */
250
+ createCookie: function(name,value,days) {
251
+ if (days) {
252
+ var date = new Date();
253
+ date.setTime(date.getTime()+(days*24*60*60*1000));
254
+ var expires = "; expires="+date.toGMTString();
255
+ }
256
+ else var expires = "";
257
+ document.cookie = name+"="+value+expires+"; path=/";
258
+ },
259
+
260
+ readCookie: function(name) {
261
+ var nameEQ = name + "=";
262
+ var ca = document.cookie.split(';');
263
+ for(var i=0;i < ca.length;i++) {
264
+ var c = ca[i];
265
+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
266
+ if (c.indexOf(nameEQ) == 0)
267
+ return c.substring(nameEQ.length,c.length);
268
+ }
269
+ return null;
270
+ },
271
+
272
+ eraseCookie: function(name) {
273
+ createCookie(name,"",-1);
274
+ },
275
+
276
+ innerText: function(el) {
277
+ return (typeof(el.innerText) != 'undefined') ? el.innerText :
278
+ (typeof(el.textContent) != 'undefined') ? el.textContent :
279
+ el.innerHTML.replace(/<[^>]+>/g, '');
280
+ },
281
+
282
+ findFirstHeader: function(node) {
283
+ // a recursive function which returns the first header it finds inside
284
+ // node, or null if there are no functions inside node.
285
+ var nn = node.nodeName.toLowerCase();
286
+ if (nn.match(/^h[1-6]$/)) {
287
+ // this node is itself a header; return our name
288
+ return nn;
289
+ } else {
290
+ for (var i=0; i<node.childNodes.length; i++) {
291
+ var subvalue = generated_toc.findFirstHeader(node.childNodes[i]);
292
+ // if one of the subnodes finds a header, abort the loop and return it
293
+ if (subvalue) return subvalue;
294
+ }
295
+ // no headers in this node at all
296
+ return null;
297
+ }
298
+ },
299
+
300
+ init: function() {
301
+ // quit if this function has already been called
302
+ if (arguments.callee.done) return;
303
+
304
+ // flag this function so we don't do the same thing twice
305
+ arguments.callee.done = true;
306
+
307
+ generated_toc.generate();
308
+ }
309
+ };
310
+
311
+ (function(i) {var u =navigator.userAgent;var e=/*@cc_on!@*/false; var st =
312
+ setTimeout;if(/webkit/i.test(u)){st(function(){var dr=document.readyState;
313
+ if(dr=="loaded"||dr=="complete"){i()}else{st(arguments.callee,10);}},10);}
314
+ else if((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))){
315
+ document.addEventListener("DOMContentLoaded",i,false); } else if(e){ (
316
+ function(){var t=document.createElement('doc:rdy');try{t.doScroll('left');
317
+ i();t=null;}catch(e){st(arguments.callee,0);}})();}else{window.onload=i;}})(generated_toc.init);
318
+
319
+
@@ -0,0 +1,14 @@
1
+ <html>
2
+ <head>
3
+ <title>RubyBreaker</title>
4
+ <LINK REL=StyleSheet HREF="rubybreaker.css" TYPE="text/css">
5
+ <script type="text/javascript" src="generated_toc.js"> </script>
6
+ </head>
7
+ <body onLoad="createTOC()">
8
+ <center>
9
+ <div id="content">
10
+ <div id="logo">
11
+ <img src="images/logo.png" border="0">
12
+ </div>
13
+ <hr />
14
+ <div id="generated-toc"></div>
Binary file