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>t049treeparser</title> 6 7<!-- ANTLR includes --> 8<script type="text/javascript" src="../../lib/antlr3-all.js"></script> 9<script type="text/javascript" src="t049treeparseraLexer.js"></script> 10<script type="text/javascript" src="t049treeparseraParser.js"></script> 11<script type="text/javascript" src="t049treeparseraWalker.js"></script> 12<script type="text/javascript" src="t049treeparserbLexer.js"></script> 13<script type="text/javascript" src="t049treeparserbParser.js"></script> 14<script type="text/javascript" src="t049treeparserbWalker.js"></script> 15<script type="text/javascript" src="t049treeparsercLexer.js"></script> 16<script type="text/javascript" src="t049treeparsercParser.js"></script> 17<script type="text/javascript" src="t049treeparsercWalker.js"></script> 18<script type="text/javascript" src="t049treeparserdLexer.js"></script> 19<script type="text/javascript" src="t049treeparserdParser.js"></script> 20<script type="text/javascript" src="t049treeparserdWalker.js"></script> 21<script type="text/javascript" src="t049treeparsereLexer.js"></script> 22<script type="text/javascript" src="t049treeparsereParser.js"></script> 23<script type="text/javascript" src="t049treeparsereWalker.js"></script> 24<script type="text/javascript" src="t049treeparserfLexer.js"></script> 25<script type="text/javascript" src="t049treeparserfParser.js"></script> 26<script type="text/javascript" src="t049treeparserfWalker.js"></script> 27<script type="text/javascript" src="t049treeparsergLexer.js"></script> 28<script type="text/javascript" src="t049treeparsergParser.js"></script> 29<script type="text/javascript" src="t049treeparsergWalker.js"></script> 30<script type="text/javascript" src="t049treeparserhLexer.js"></script> 31<script type="text/javascript" src="t049treeparserhParser.js"></script> 32<script type="text/javascript" src="t049treeparserhWalker.js"></script> 33<script type="text/javascript" src="t049treeparseriLexer.js"></script> 34<script type="text/javascript" src="t049treeparseriParser.js"></script> 35<script type="text/javascript" src="t049treeparseriWalker.js"></script> 36 37 38 39<!-- JsUnit include --> 40<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script> 41 42<!-- Test Code --> 43<script type="text/javascript"> 44 function execTreeParser(lexerCls, parserCls, grammarEntry, walkerCls, treeEntry, xinput) 45 { 46 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 47 lexer = new lexerCls(cstream), 48 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 49 parser = new parserCls(tstream); 50 var r = parser[grammarEntry](); 51 52 var nodes = new org.antlr.runtime.tree.CommonTreeNodeStream(r.getTree()); 53 nodes.setTokenStream(tstream); 54 var walker = new (walkerClass(walkerCls))(nodes); 55 walker[treeEntry](); 56 57 return walker._output; 58 } 59 60 function walkerClass(base) { 61 var TWalker = function() { 62 TWalker.superclass.constructor.apply(this, arguments); 63 this._output = ""; 64 this.traces = []; 65 }; 66 67 org.antlr.lang.extend(TWalker, base, { 68 capture: function(t) { 69 this._output += t; 70 }, 71 traceIn: function(ruleName, ruleIndex) { 72 this.traces.push(">"+ruleName); 73 }, 74 traceOut: function(ruleName, ruleIndex) { 75 this.traces.push("<"+ruleName); 76 }, 77 recover: function(input, re) { 78 throw re; 79 } 80 }); 81 82 return TWalker; 83 } 84 85 function testFlatList() { 86 var found = execTreeParser(t049treeparseraLexer, 87 t049treeparseraParser, 88 "a", 89 t049treeparseraWalker, 90 "a", 91 "abc 34"); 92 assertEquals(found, "abc, 34"); 93 } 94 95 function testSimpleTree() { 96 var found = execTreeParser(t049treeparserbLexer, 97 t049treeparserbParser, 98 "a", 99 t049treeparserbWalker, 100 "a", 101 "abc 34"); 102 assertEquals(found, "abc, 34"); 103 } 104 105 function testFlatVsTreeDecision() { 106 var found = execTreeParser(t049treeparsercLexer, 107 t049treeparsercParser, 108 "a", 109 t049treeparsercWalker, 110 "a", 111 "a 1 b 2"); 112 assertEquals(found, "^(a 1)b 2\n"); 113 } 114 115 function testFlatVsTreeDecision2() { 116 var found = execTreeParser(t049treeparserdLexer, 117 t049treeparserdParser, 118 "a", 119 t049treeparserdWalker, 120 "a", 121 "a 1 2 3 b 4 5"); 122 assertEquals(found, "^(a 3)b 5\n"); 123 } 124 125 function testCyclicDFALookahead() { 126 var found = execTreeParser(t049treeparsereLexer, 127 t049treeparsereParser, 128 "a", 129 t049treeparsereWalker, 130 "a", 131 "a 1 2 3."); 132 assertEquals(found, "alt 1"); 133 } 134 135 function testNullableChildList() { 136 var found = execTreeParser(t049treeparserfLexer, 137 t049treeparserfParser, 138 "a", 139 t049treeparserfWalker, 140 "a", 141 "abc"); 142 assertEquals(found, "abc"); 143 } 144 145 function testNullableChildList2() { 146 var found = execTreeParser(t049treeparsergLexer, 147 t049treeparsergParser, 148 "a", 149 t049treeparsergWalker, 150 "a", 151 "abc 3;"); 152 assertEquals(found, "abc"); 153 } 154 155 function testNullableChildList3() { 156 var found = execTreeParser(t049treeparserhLexer, 157 t049treeparserhParser, 158 "a", 159 t049treeparserhWalker, 160 "a", 161 "abc 3 def;"); 162 assertEquals(found, "abc, def"); 163 } 164 165 function testActionsAfterRoot() { 166 var found = execTreeParser(t049treeparseriLexer, 167 t049treeparseriParser, 168 "a", 169 t049treeparseriWalker, 170 "a", 171 "abc;"); 172 assertEquals(found, "abc, 2"); 173 } 174 175 176</script> 177 178</head> 179<body> 180 <h1>t049treeparser</h1> 181</body> 182</html> 183