Browse code
feat: add ts tool for java->sexp
Ed Langley authored on 29/10/2020 23:43:21
Showing 3 changed files
Showing 3 changed files
0 | 4 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,255 @@ |
1 |
+(function($) { |
|
2 |
+ $.widget("ui.accordion1", { |
|
3 |
+ options: { |
|
4 |
+ helpDialog: $('<div class="help"></div>'), |
|
5 |
+ active: 0, |
|
6 |
+ animated: 'slide', |
|
7 |
+ clearStyle: false, |
|
8 |
+ manyOpen: true, |
|
9 |
+ event: "click", |
|
10 |
+ fillSpace: false, |
|
11 |
+ header: "> li > :first-child,> :not(li):even", |
|
12 |
+ icons: { |
|
13 |
+ header: "ui-icon-triangle-1-e", |
|
14 |
+ headerSelected: "ui-icon-triangle-1-s" |
|
15 |
+ }, |
|
16 |
+ navigation: false, |
|
17 |
+ navigationFilter: function() { |
|
18 |
+ return this.href.toLowerCase() == location.href.toLowerCase(); |
|
19 |
+ } |
|
20 |
+ |
|
21 |
+ }, |
|
22 |
+ |
|
23 |
+ _create: function() { |
|
24 |
+ |
|
25 |
+ var o = this.options, self = this; |
|
26 |
+ this.running = 0; |
|
27 |
+ |
|
28 |
+ this._initHelp(o.helpDialog); |
|
29 |
+ this.element.addClass("ui-accordion ui-widget ui-helper-reset"); |
|
30 |
+ |
|
31 |
+ // in lack of child-selectors in CSS we need to mark top-LIs in a UL-accordion for some IE-fix |
|
32 |
+ this.element.children("li").addClass("ui-accordion-li-fix"); |
|
33 |
+ |
|
34 |
+ this.headers = this.element.find(o.header).addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all") |
|
35 |
+ .bind("mouseenter.accordion", function(){ $(this).addClass('ui-state-hover'); }) |
|
36 |
+ .bind("mouseleave.accordion", function(){ $(this).removeClass('ui-state-hover'); }) |
|
37 |
+ .bind("focus.accordion", function(){ $(this).addClass('ui-state-focus'); }) |
|
38 |
+ .bind("blur.accordion", function(){ $(this).removeClass('ui-state-focus'); }); |
|
39 |
+ |
|
40 |
+ this.headers |
|
41 |
+ .next() |
|
42 |
+ .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom"); |
|
43 |
+ |
|
44 |
+ if ( o.navigation ) { |
|
45 |
+ var current = this.element.find("a").filter(o.navigationFilter); |
|
46 |
+ if ( current.length ) { |
|
47 |
+ var header = current.closest(".ui-accordion-header"); |
|
48 |
+ if ( header.length ) { |
|
49 |
+ // anchor within header |
|
50 |
+ this.active = header; |
|
51 |
+ } else { |
|
52 |
+ // anchor within content |
|
53 |
+ this.active = current.closest(".ui-accordion-content").prev(); |
|
54 |
+ } |
|
55 |
+ } |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ this.active = $(this.headers.get(0)); |
|
59 |
+ |
|
60 |
+ //Append icon elements |
|
61 |
+ //this._createIcons(); |
|
62 |
+ |
|
63 |
+ //this.resize(); |
|
64 |
+ |
|
65 |
+ //ARIA |
|
66 |
+ this.element.attr('role','tablist'); |
|
67 |
+ |
|
68 |
+ this.headers |
|
69 |
+ .attr('role','tab') |
|
70 |
+ .bind('keydown', function(event) { return self._keydown(event); }) |
|
71 |
+ .next() |
|
72 |
+ .attr('role','tabpanel'); |
|
73 |
+ |
|
74 |
+ this.headers |
|
75 |
+ .attr('aria-expanded','false') |
|
76 |
+ .attr("tabIndex", "0") |
|
77 |
+ .next() |
|
78 |
+ .hide(); |
|
79 |
+ |
|
80 |
+ |
|
81 |
+ // only need links in taborder for Safari |
|
82 |
+ if (!$.browser.safari) |
|
83 |
+ this.headers.find('a').attr('tabIndex','-1'); |
|
84 |
+ |
|
85 |
+ if (o.event) { |
|
86 |
+ this.headers.bind((o.event) + ".accordion", function(event) { |
|
87 |
+ self._clickHandler.call(self, event, this); |
|
88 |
+ event.preventDefault(); |
|
89 |
+ }); |
|
90 |
+ this.active.trigger(o.event) |
|
91 |
+ } |
|
92 |
+ |
|
93 |
+ this.active.focus(); |
|
94 |
+ }, |
|
95 |
+ |
|
96 |
+ _initHelp: function(target) { |
|
97 |
+ var self = this; |
|
98 |
+ $(target).prepend( |
|
99 |
+ '<table style="margin: auto auto">\n' + |
|
100 |
+ ' <thead><tr><th>Key</th><th>Action</th></tr></thead>\n' + |
|
101 |
+ ' <tbody><tr><td>Movement:</td><td>Arrow keys, vi keys or wasd</tr>\n' + |
|
102 |
+ ' <tr><td><pre>\n' + |
|
103 |
+ ' w\n' + |
|
104 |
+ ' a s d\n' + |
|
105 |
+ ' </pre></td><td><pre>\n' + |
|
106 |
+ ' k\n' + |
|
107 |
+ ' h j l\n' + |
|
108 |
+ ' </pre></td>\n' + |
|
109 |
+ ' </tr><tr class="s">\n' + |
|
110 |
+ ' <td>Shift+up or down:</td><td>Keep current pane open and switch to appropriate pane</td>\n' + |
|
111 |
+ ' </tr><tr>\n' + |
|
112 |
+ ' <td>Right, Enter:</td><td>Open current item</td>\n' + |
|
113 |
+ ' </tr><tr class="s">\n' + |
|
114 |
+ ' <td>Left, Enter:</td><td>Close current item</td>\n' + |
|
115 |
+ ' </tr><tr class="s">\n' + |
|
116 |
+ ' <td>Space:</td><td>Scroll down if current element not fully visible, otherwise go to next</td>\n' + |
|
117 |
+ ' </tr><tr>\n' + |
|
118 |
+ " <td>'?':</td><td>Help</td>\n" + |
|
119 |
+ ' </tr>\n' + |
|
120 |
+ ' </tbody>\n' + |
|
121 |
+ '</table>\n' |
|
122 |
+ ).dialog({autoOpen: false, modal: true, title: 'Help (\'q\' or Escape to exit)', minWidth: 402, width: 402}); |
|
123 |
+ |
|
124 |
+ $('body').bind('keydown', function(event) { |
|
125 |
+ if (event.shiftKey && event.which == 191) { // 191 == '?' |
|
126 |
+ self.help(); |
|
127 |
+ } else if (event.which == 81 && self.options.helpDialog.dialog('isOpen')) { // 81 == 'q' |
|
128 |
+ self.help(); |
|
129 |
+ }; |
|
130 |
+ }); |
|
131 |
+ if (this.options.helpTrigger) { |
|
132 |
+ $(this.options.helpTrigger).click( function() { self.help(); }); |
|
133 |
+ } |
|
134 |
+ |
|
135 |
+ |
|
136 |
+ |
|
137 |
+ }, |
|
138 |
+ |
|
139 |
+ _keydown: function(event) { |
|
140 |
+ |
|
141 |
+ var o = this.options, keyCode = $.ui.keyCode; |
|
142 |
+ |
|
143 |
+ if (o.disabled || event.altKey || event.ctrlKey) |
|
144 |
+ return; |
|
145 |
+ |
|
146 |
+ var length = this.headers.length; |
|
147 |
+ var currentIndex = this.headers.index(event.target); |
|
148 |
+ var toFocus = false; |
|
149 |
+ var is_space = false; |
|
150 |
+ var result = false; |
|
151 |
+ |
|
152 |
+ switch(event.keyCode) { |
|
153 |
+ case keyCode.SPACE: |
|
154 |
+ is_space = true; |
|
155 |
+ toFocus = this.headers[(currentIndex + 1) % length]; |
|
156 |
+ break; |
|
157 |
+ case 74: // j |
|
158 |
+ case 83: // s |
|
159 |
+ case keyCode.DOWN: |
|
160 |
+ toFocus = this.headers[(currentIndex + 1) % length]; |
|
161 |
+ break; |
|
162 |
+ case keyCode.UP: |
|
163 |
+ case 75: // k |
|
164 |
+ case 87: // w |
|
165 |
+ toFocus = this.headers[(currentIndex - 1 + length) % length]; |
|
166 |
+ break; |
|
167 |
+ case keyCode.RIGHT: |
|
168 |
+ case 76: // l |
|
169 |
+ case 68: // l |
|
170 |
+ this.show(event.target); |
|
171 |
+ break; |
|
172 |
+ case keyCode.LEFT: |
|
173 |
+ case 72: // h |
|
174 |
+ case 65: // h |
|
175 |
+ this.hide(event.target); |
|
176 |
+ break; |
|
177 |
+ case keyCode.ENTER: |
|
178 |
+ $(event.target).stop(); |
|
179 |
+ this.toggle(event.target); |
|
180 |
+ event.preventDefault(); |
|
181 |
+ } |
|
182 |
+ |
|
183 |
+ if (toFocus) { |
|
184 |
+ //console.log(this.active.next().offset().top + this.active.next().outerHeight()); |
|
185 |
+ //console.log($(window).height()+$(window).scrollTop()); |
|
186 |
+ console.log((this.active.next().offset().top + this.active.next().outerHeight()) > ($(window).height() + $(window).scrollTop())); |
|
187 |
+ console.log(toFocus); |
|
188 |
+ var windowBottom = $(window).height() + $(window).scrollTop() |
|
189 |
+ if (is_space && ((this.active.next().offset().top + this.active.next().outerHeight()) > windowBottom)) { |
|
190 |
+ result = true; |
|
191 |
+ toFocus = this.active; |
|
192 |
+ } else { |
|
193 |
+ result = false; |
|
194 |
+ if (!event.shiftKey) this.hide(this.active); |
|
195 |
+ }; |
|
196 |
+ console.log(toFocus); |
|
197 |
+ console.log(toFocus == this.active); |
|
198 |
+ |
|
199 |
+ if (toFocus != this.active) { |
|
200 |
+ this.active = $(toFocus); |
|
201 |
+ toFocus.focus(); |
|
202 |
+ this.show(this.active); |
|
203 |
+ } |
|
204 |
+ |
|
205 |
+ } else { result = true; } |
|
206 |
+ |
|
207 |
+ return result; |
|
208 |
+ |
|
209 |
+ }, |
|
210 |
+ |
|
211 |
+ show: function(target) { |
|
212 |
+ var target = $(target); |
|
213 |
+ target.stop(); |
|
214 |
+ target.removeClass("ui-state-default").addClass("ui-state-active").removeClass("ui-corner-all").addClass("ui-corner-top"); |
|
215 |
+ target.next().show(); |
|
216 |
+ }, |
|
217 |
+ hide: function(target) { |
|
218 |
+ var target = $(target); |
|
219 |
+ target.stop(); |
|
220 |
+ target.addClass("ui-state-default").removeClass("ui-state-active").addClass("ui-corner-all").removeClass("ui-corner-top"); |
|
221 |
+ target.next().hide(); |
|
222 |
+ }, |
|
223 |
+ toggle: function(target) { |
|
224 |
+ var target = $(target); |
|
225 |
+ target.stop(); |
|
226 |
+ target.toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top"); |
|
227 |
+ target.next().toggle(); |
|
228 |
+ }, |
|
229 |
+ |
|
230 |
+ _clickHandler: function(event, target) { |
|
231 |
+ console.log(target); |
|
232 |
+ this.active = $(target); |
|
233 |
+ this.active.stop() |
|
234 |
+ this.active.toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top"); |
|
235 |
+ this.active.next().toggle(); |
|
236 |
+ this.active.focus(); |
|
237 |
+ |
|
238 |
+ }, |
|
239 |
+ |
|
240 |
+ destroy: function() { |
|
241 |
+ }, |
|
242 |
+ |
|
243 |
+ _setOption: function(option, value) { |
|
244 |
+ $.Widget.prototype._setOption.apply( this, arguments ); |
|
245 |
+ }, |
|
246 |
+ |
|
247 |
+ help: function(target) { |
|
248 |
+ if (!this.options.helpDialog.dialog('isOpen')) |
|
249 |
+ this.options.helpDialog.dialog('open'); |
|
250 |
+ else |
|
251 |
+ this.options.helpDialog.dialog('close'); |
|
252 |
+ } |
|
253 |
+ |
|
254 |
+ }); |
|
255 |
+})(jQuery); |
0 | 256 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,67 @@ |
1 |
+# Copyright (c) 2019 Edward Langley |
|
2 |
+# All rights reserved. |
|
3 |
+# |
|
4 |
+# Redistribution and use in source and binary forms, with or without |
|
5 |
+# modification, are permitted provided that the following conditions |
|
6 |
+# are met: |
|
7 |
+# |
|
8 |
+# Redistributions of source code must retain the above copyright notice, |
|
9 |
+# this list of conditions and the following disclaimer. |
|
10 |
+# |
|
11 |
+# Redistributions in binary form must reproduce the above copyright |
|
12 |
+# notice, this list of conditions and the following disclaimer in the |
|
13 |
+# documentation and/or other materials provided with the distribution. |
|
14 |
+# |
|
15 |
+# Neither the name of the project's author nor the names of its |
|
16 |
+# contributors may be used to endorse or promote products derived from |
|
17 |
+# this software without specific prior written permission. |
|
18 |
+# |
|
19 |
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
20 |
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
21 |
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
22 |
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
23 |
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
24 |
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
|
25 |
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
26 |
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
27 |
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
29 |
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
+ |
|
31 |
+import tree_sitter as t |
|
32 |
+ |
|
33 |
+t.Language.build_library('ts.so', [ |
|
34 |
+ 'tree-sitter-javascript', |
|
35 |
+ 'tree-sitter-scala', |
|
36 |
+ 'tree-sitter-java', |
|
37 |
+ 'tree-sitter-kotlin' |
|
38 |
+]) |
|
39 |
+ |
|
40 |
+def listify(text, cursor, level=1): |
|
41 |
+ node = cursor.node |
|
42 |
+ result = [] |
|
43 |
+ |
|
44 |
+ print(' '*level, '>', node.type, node.start_byte, node.end_byte) |
|
45 |
+ |
|
46 |
+ result.append(node.type) |
|
47 |
+ |
|
48 |
+ if cursor.goto_first_child(): |
|
49 |
+ result.append(listify(text, cursor, level+1)) |
|
50 |
+ cursor.goto_parent() |
|
51 |
+ else: |
|
52 |
+ result.append(text[node.start_byte:node.end_byte].decode('utf-8')) |
|
53 |
+ |
|
54 |
+ while cursor.goto_next_sibling(): |
|
55 |
+ result.append(listify(text, cursor, level+1)) |
|
56 |
+ |
|
57 |
+ print(' '*level, '<', node.type, node.start_byte, node.end_byte) |
|
58 |
+ |
|
59 |
+ return result |
|
60 |
+ |
|
61 |
+ |
|
62 |
+ |
|
63 |
+java = t.Language('ts.so', 'java') |
|
64 |
+parser = t.Parser(java) |
|
65 |
+parser.set_language(java) |
|
66 |
+ |
|
67 |
+text = open('/java/file.java', 'rb').read() |