• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3<head>
4<meta http-equiv="content-type" content="text/html;charset=utf-8" />
5<title>t051treeRewriteAST</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t051treeRewriteASTaLexer.js"></script>
10<script type="text/javascript" src="t051treeRewriteASTaParser.js"></script>
11<script type="text/javascript" src="t051treeRewriteASTaWalker.js"></script>
12<script type="text/javascript" src="t051treeRewriteASTbLexer.js"></script>
13<script type="text/javascript" src="t051treeRewriteASTbParser.js"></script>
14<script type="text/javascript" src="t051treeRewriteASTbWalker.js"></script>
15<script type="text/javascript" src="t051treeRewriteASTcLexer.js"></script>
16<script type="text/javascript" src="t051treeRewriteASTcParser.js"></script>
17<script type="text/javascript" src="t051treeRewriteASTcWalker.js"></script>
18<script type="text/javascript" src="t051treeRewriteASTdLexer.js"></script>
19<script type="text/javascript" src="t051treeRewriteASTdParser.js"></script>
20<script type="text/javascript" src="t051treeRewriteASTdWalker.js"></script>
21<script type="text/javascript" src="t051treeRewriteASTeLexer.js"></script>
22<script type="text/javascript" src="t051treeRewriteASTeParser.js"></script>
23<script type="text/javascript" src="t051treeRewriteASTeWalker.js"></script>
24<script type="text/javascript" src="t051treeRewriteASTfLexer.js"></script>
25<script type="text/javascript" src="t051treeRewriteASTfParser.js"></script>
26<script type="text/javascript" src="t051treeRewriteASTfWalker.js"></script>
27<script type="text/javascript" src="t051treeRewriteASTgLexer.js"></script>
28<script type="text/javascript" src="t051treeRewriteASTgParser.js"></script>
29<script type="text/javascript" src="t051treeRewriteASTgWalker.js"></script>
30<script type="text/javascript" src="t051treeRewriteASThLexer.js"></script>
31<script type="text/javascript" src="t051treeRewriteASThParser.js"></script>
32<script type="text/javascript" src="t051treeRewriteASThWalker.js"></script>
33<script type="text/javascript" src="t051treeRewriteASTiLexer.js"></script>
34<script type="text/javascript" src="t051treeRewriteASTiParser.js"></script>
35<script type="text/javascript" src="t051treeRewriteASTiWalker.js"></script>
36<script type="text/javascript" src="t051treeRewriteASTjLexer.js"></script>
37<script type="text/javascript" src="t051treeRewriteASTjParser.js"></script>
38<script type="text/javascript" src="t051treeRewriteASTjWalker.js"></script>
39<script type="text/javascript" src="t051treeRewriteASTkLexer.js"></script>
40<script type="text/javascript" src="t051treeRewriteASTkParser.js"></script>
41<script type="text/javascript" src="t051treeRewriteASTkWalker.js"></script>
42<script type="text/javascript" src="t051treeRewriteASTlLexer.js"></script>
43<script type="text/javascript" src="t051treeRewriteASTlParser.js"></script>
44<script type="text/javascript" src="t051treeRewriteASTlWalker.js"></script>
45<script type="text/javascript" src="t051treeRewriteASTmLexer.js"></script>
46<script type="text/javascript" src="t051treeRewriteASTmParser.js"></script>
47<script type="text/javascript" src="t051treeRewriteASTmWalker.js"></script>
48<script type="text/javascript" src="t051treeRewriteASTnLexer.js"></script>
49<script type="text/javascript" src="t051treeRewriteASTnParser.js"></script>
50<script type="text/javascript" src="t051treeRewriteASTnWalker.js"></script>
51<script type="text/javascript" src="t051treeRewriteASToLexer.js"></script>
52<script type="text/javascript" src="t051treeRewriteASToParser.js"></script>
53<script type="text/javascript" src="t051treeRewriteASToWalker.js"></script>
54<script type="text/javascript" src="t051treeRewriteASTpLexer.js"></script>
55<script type="text/javascript" src="t051treeRewriteASTpParser.js"></script>
56<script type="text/javascript" src="t051treeRewriteASTpWalker.js"></script>
57<script type="text/javascript" src="t051treeRewriteASTqLexer.js"></script>
58<script type="text/javascript" src="t051treeRewriteASTqParser.js"></script>
59<script type="text/javascript" src="t051treeRewriteASTqWalker.js"></script>
60<script type="text/javascript" src="t051treeRewriteASTrLexer.js"></script>
61<script type="text/javascript" src="t051treeRewriteASTrParser.js"></script>
62<script type="text/javascript" src="t051treeRewriteASTrWalker.js"></script>
63<script type="text/javascript" src="t051treeRewriteASTsLexer.js"></script>
64<script type="text/javascript" src="t051treeRewriteASTsParser.js"></script>
65<script type="text/javascript" src="t051treeRewriteASTsWalker.js"></script>
66<script type="text/javascript" src="t051treeRewriteASTtLexer.js"></script>
67<script type="text/javascript" src="t051treeRewriteASTtParser.js"></script>
68<script type="text/javascript" src="t051treeRewriteASTtWalker.js"></script>
69<script type="text/javascript" src="t051treeRewriteASTuLexer.js"></script>
70<script type="text/javascript" src="t051treeRewriteASTuParser.js"></script>
71<script type="text/javascript" src="t051treeRewriteASTuWalker.js"></script>
72<script type="text/javascript" src="t051treeRewriteASTvLexer.js"></script>
73<script type="text/javascript" src="t051treeRewriteASTvParser.js"></script>
74<script type="text/javascript" src="t051treeRewriteASTvWalker.js"></script>
75<script type="text/javascript" src="t051treeRewriteASTwLexer.js"></script>
76<script type="text/javascript" src="t051treeRewriteASTwParser.js"></script>
77<script type="text/javascript" src="t051treeRewriteASTwWalker.js"></script>
78<script type="text/javascript" src="t051treeRewriteASTxLexer.js"></script>
79<script type="text/javascript" src="t051treeRewriteASTxParser.js"></script>
80<script type="text/javascript" src="t051treeRewriteASTxWalker.js"></script>
81<script type="text/javascript" src="t051treeRewriteASTyLexer.js"></script>
82<script type="text/javascript" src="t051treeRewriteASTyParser.js"></script>
83<script type="text/javascript" src="t051treeRewriteASTyWalker.js"></script>
84<script type="text/javascript" src="t051treeRewriteASTzLexer.js"></script>
85<script type="text/javascript" src="t051treeRewriteASTzParser.js"></script>
86<script type="text/javascript" src="t051treeRewriteASTzWalker.js"></script>
87<script type="text/javascript" src="t051treeRewriteASTaaLexer.js"></script>
88<script type="text/javascript" src="t051treeRewriteASTaaParser.js"></script>
89<script type="text/javascript" src="t051treeRewriteASTaaWalker.js"></script>
90<script type="text/javascript" src="t051treeRewriteASTabLexer.js"></script>
91<script type="text/javascript" src="t051treeRewriteASTabParser.js"></script>
92<script type="text/javascript" src="t051treeRewriteASTabWalker.js"></script>
93<script type="text/javascript" src="t051treeRewriteASTacLexer.js"></script>
94<script type="text/javascript" src="t051treeRewriteASTacParser.js"></script>
95<script type="text/javascript" src="t051treeRewriteASTacWalker.js"></script>
96
97<!-- JsUnit include -->
98<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
99
100<!-- Test Code -->
101<script type="text/javascript">
102    function execTreeParser(lexerCls, parserCls, grammarEntry, walkerCls, treeEntry, xinput)
103    {
104        var cstream = new org.antlr.runtime.ANTLRStringStream(xinput),
105            lexer = new lexerCls(cstream),
106            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
107            parser = new parserCls(tstream);
108        var r = parser[grammarEntry]();
109
110        var nodes = new org.antlr.runtime.tree.CommonTreeNodeStream(r.getTree());
111        nodes.setTokenStream(tstream);
112        var walker = new (walkerClass(walkerCls))(nodes);
113        var w = walker[treeEntry]();
114
115        if (w.tree) {
116            return w.tree.toStringTree();
117        }
118        return "";
119    }
120
121    function walkerClass(base) {
122        var TWalker = function() {
123            TWalker.superclass.constructor.apply(this, arguments);
124            this.traces = [];
125            this.buf = "";
126        };
127
128        org.antlr.lang.extend(TWalker, base, {
129            traceIn: function(ruleName, ruleIndex) {
130                this.traces.push(">"+ruleName);
131            },
132            traceOut: function(ruleName, ruleIndex) {
133                this.traces.push("<"+ruleName);
134            },
135            reportError: function(input, re) {
136                throw re;
137            }
138        });
139
140        return TWalker;
141    }
142
143    function testFlatList() {
144        var found = execTreeParser(t051treeRewriteASTaLexer,
145                t051treeRewriteASTaParser,
146                "a",
147                t051treeRewriteASTaWalker,
148                "a",
149                "abc 34");
150        assertEquals(found, "34 abc");
151    }
152
153    function testSimpleTree() {
154        var found = execTreeParser(t051treeRewriteASTbLexer,
155                t051treeRewriteASTbParser,
156                "a",
157                t051treeRewriteASTbWalker,
158                "a",
159                "abc 34");
160        assertEquals(found, "(34 abc)");
161    }
162
163    function testCombinedRewriteAndAuto() {
164        var found = execTreeParser(t051treeRewriteASTcLexer,
165                t051treeRewriteASTcParser,
166                "a",
167                t051treeRewriteASTcWalker,
168                "a",
169                "abc 34");
170        assertEquals(found, "(34 abc)");
171
172        found = execTreeParser(t051treeRewriteASTcLexer,
173                t051treeRewriteASTcParser,
174                "a",
175                t051treeRewriteASTcWalker,
176                "a",
177                "34");
178        assertEquals(found, "34");
179    }
180
181    function testAvoidDup() {
182        var found = execTreeParser(t051treeRewriteASTdLexer,
183                t051treeRewriteASTdParser,
184                "a",
185                t051treeRewriteASTdWalker,
186                "a",
187                "abc");
188        assertEquals(found, "(abc abc)");
189    }
190
191    function testLoop() {
192        var found = execTreeParser(t051treeRewriteASTeLexer,
193                t051treeRewriteASTeParser,
194                "a",
195                t051treeRewriteASTeWalker,
196                "a",
197                "a b c 3 4 5");
198        assertEquals(found, "3 4 5 a b c");
199    }
200
201    function testAutoDup() {
202        var found = execTreeParser(t051treeRewriteASTfLexer,
203                t051treeRewriteASTfParser,
204                "a",
205                t051treeRewriteASTfWalker,
206                "a",
207                "abc");
208        assertEquals(found, "abc");
209    }
210
211    function testAutoDupRule() {
212        var found = execTreeParser(t051treeRewriteASTgLexer,
213                t051treeRewriteASTgParser,
214                "a",
215                t051treeRewriteASTgWalker,
216                "a",
217                "a 1");
218        assertEquals(found, "a 1");
219    }
220
221    function testAutoDupMultiple() {
222        var found = execTreeParser(t051treeRewriteASThLexer,
223                t051treeRewriteASThParser,
224                "a",
225                t051treeRewriteASThWalker,
226                "a",
227                "a b 3");
228        assertEquals(found, "a b 3");
229    }
230
231    function testAutoDupTree() {
232        var found = execTreeParser(t051treeRewriteASTiLexer,
233                t051treeRewriteASTiParser,
234                "a",
235                t051treeRewriteASTiWalker,
236                "a",
237                "a 3");
238        assertEquals(found, "(a 3)");
239    }
240
241    function testAutoDupTreeWithLabels() {
242        var found = execTreeParser(t051treeRewriteASTjLexer,
243                t051treeRewriteASTjParser,
244                "a",
245                t051treeRewriteASTjWalker,
246                "a",
247                "a 3");
248        assertEquals(found, "(a 3)");
249    }
250
251    function testAutoDupTreeWithListLabels() {
252        var found = execTreeParser(t051treeRewriteASTkLexer,
253                t051treeRewriteASTkParser,
254                "a",
255                t051treeRewriteASTkWalker,
256                "a",
257                "a 3");
258        assertEquals(found, "(a 3)");
259    }
260
261    function testAutoDupTreeWithRuleRoot() {
262        var found = execTreeParser(t051treeRewriteASTlLexer,
263                t051treeRewriteASTlParser,
264                "a",
265                t051treeRewriteASTlWalker,
266                "a",
267                "a 3");
268        assertEquals(found, "(a 3)");
269    }
270
271    function testAutoDupTreeWithRuleRootAndLabels() {
272        var found = execTreeParser(t051treeRewriteASTmLexer,
273                t051treeRewriteASTmParser,
274                "a",
275                t051treeRewriteASTmWalker,
276                "a",
277                "a 3");
278        assertEquals(found, "(a 3)");
279    }
280
281    function testAutoDupTreeWithRuleRootAndListLabels() {
282        var found = execTreeParser(t051treeRewriteASTnLexer,
283                t051treeRewriteASTnParser,
284                "a",
285                t051treeRewriteASTnWalker,
286                "a",
287                "a 3");
288        assertEquals(found, "(a 3)");
289    }
290
291    function testAutoDupNestedTree() {
292        var found = execTreeParser(t051treeRewriteASToLexer,
293                t051treeRewriteASToParser,
294                "a",
295                t051treeRewriteASToWalker,
296                "a",
297                "a b 3");
298        assertEquals(found, "(a (b 3))");
299    }
300
301    function testDelete() {
302        var found = execTreeParser(t051treeRewriteASTpLexer,
303                t051treeRewriteASTpParser,
304                "a",
305                t051treeRewriteASTpWalker,
306                "a",
307                "abc");
308        assertEquals(found, "");
309    }
310
311    function testSetMatchNoRewrite() {
312        var found = execTreeParser(t051treeRewriteASTqLexer,
313                t051treeRewriteASTqParser,
314                "a",
315                t051treeRewriteASTqWalker,
316                "a",
317                "abc 34");
318        assertEquals(found, "abc 34");
319    }
320
321    function testSetMatchNoRewriteLevel2() {
322        var found = execTreeParser(t051treeRewriteASTrLexer,
323                t051treeRewriteASTrParser,
324                "a",
325                t051treeRewriteASTrWalker,
326                "a",
327                "abc 34");
328        assertEquals(found, "(abc 34)");
329    }
330
331    function testSetMatchNoRewriteLevel2Root() {
332        var found = execTreeParser(t051treeRewriteASTsLexer,
333                t051treeRewriteASTsParser,
334                "a",
335                t051treeRewriteASTsWalker,
336                "a",
337                "abc 34");
338        assertEquals(found, "(abc 34)");
339    }
340
341    function testRewriteModeCombinedRewriteAndAuto() {
342        var found = execTreeParser(t051treeRewriteASTtLexer,
343                t051treeRewriteASTtParser,
344                "a",
345                t051treeRewriteASTtWalker,
346                "a",
347                "abc 34");
348        assertEquals(found, "(ick 34)");
349
350        found = execTreeParser(t051treeRewriteASTtLexer,
351                t051treeRewriteASTtParser,
352                "a",
353                t051treeRewriteASTtWalker,
354                "a",
355                "34");
356        assertEquals(found, "34");
357    }
358
359    function testRewriteModeFlatTree() {
360        var found = execTreeParser(t051treeRewriteASTuLexer,
361                t051treeRewriteASTuParser,
362                "a",
363                t051treeRewriteASTuWalker,
364                "s",
365                "abc 34");
366        assertEquals(found, "abc 1");
367    }
368
369    function testRewriteModeChainRuleFlatTree() {
370        var found = execTreeParser(t051treeRewriteASTvLexer,
371                t051treeRewriteASTvParser,
372                "a",
373                t051treeRewriteASTvWalker,
374                "s",
375                "abc 34");
376        assertEquals(found, "34 abc");
377    }
378
379    function testRewriteModeChainRuleTree() {
380        var found = execTreeParser(t051treeRewriteASTwLexer,
381                t051treeRewriteASTwParser,
382                "a",
383                t051treeRewriteASTwWalker,
384                "s",
385                "abc 34");
386        assertEquals(found, "34");
387    }
388
389    function testRewriteModeChainRuleTree2() {
390        var found = execTreeParser(t051treeRewriteASTxLexer,
391                t051treeRewriteASTxParser,
392                "a",
393                t051treeRewriteASTxWalker,
394                "s",
395                "abc 34");
396        assertEquals(found, "34");
397    }
398
399    function testRewriteModeChainRuleTree3() {
400        var found = execTreeParser(t051treeRewriteASTyLexer,
401                t051treeRewriteASTyParser,
402                "a",
403                t051treeRewriteASTyWalker,
404                "s",
405                "boo abc 34");
406        assertEquals(found, "boo 34");
407    }
408
409    function testRewriteModeChainRuleTree4() {
410        var found = execTreeParser(t051treeRewriteASTzLexer,
411                t051treeRewriteASTzParser,
412                "a",
413                t051treeRewriteASTzWalker,
414                "s",
415                "boo abc 34");
416        assertEquals(found, "(boo 34)");
417    }
418
419    function testRewriteModeChainRuleTree5() {
420        var found = execTreeParser(t051treeRewriteASTaaLexer,
421                t051treeRewriteASTaaParser,
422                "a",
423                t051treeRewriteASTaaWalker,
424                "s",
425                "boo abc 34");
426        assertEquals(found, "(boo 34)");
427    }
428
429    function testRewriteModeWithPredicatedRewrites() {
430        var found = execTreeParser(t051treeRewriteASTabLexer,
431                t051treeRewriteASTabParser,
432                "a",
433                t051treeRewriteASTabWalker,
434                "s",
435                "abc 34");
436        assertEquals(found, "(root (ick 34))");
437    }
438
439    function testWildcard() {
440        var found = execTreeParser(t051treeRewriteASTacLexer,
441                t051treeRewriteASTacParser,
442                "a",
443                t051treeRewriteASTacWalker,
444                "s",
445                "abc 34");
446        assertEquals(found, "34");
447    }
448</script>
449
450</head>
451<body>
452    <h1>t051treeRewriteAST</h1>
453</body>
454</html>
455