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>t052import</title> 6 7<!-- ANTLR includes --> 8<script type="text/javascript" src="../../lib/antlr3-all.js"></script> 9 10<script type="text/javascript" src="t052importS1.js"></script> 11<script type="text/javascript" src="t052importM1_t052importS1.js"></script> 12<script type="text/javascript" src="t052importM1Lexer.js"></script> 13<script type="text/javascript" src="t052importM1Parser.js"></script> 14 15<script type="text/javascript" src="t052importS2.js"></script> 16<script type="text/javascript" src="t052importM2_t052importS2.js"></script> 17<script type="text/javascript" src="t052importM2Lexer.js"></script> 18<script type="text/javascript" src="t052importM2Parser.js"></script> 19 20<script type="text/javascript" src="t052importS3.js"></script> 21<script type="text/javascript" src="t052importM3_t052importS3.js"></script> 22<script type="text/javascript" src="t052importM3Lexer.js"></script> 23<script type="text/javascript" src="t052importM3Parser.js"></script> 24 25<script type="text/javascript" src="t052importS4.js"></script> 26<script type="text/javascript" src="t052importT4.js"></script> 27<script type="text/javascript" src="t052importM4_t052importS4.js"></script> 28<script type="text/javascript" src="t052importM4_t052importT4.js"></script> 29<script type="text/javascript" src="t052importM4Lexer.js"></script> 30<script type="text/javascript" src="t052importM4Parser.js"></script> 31 32<script type="text/javascript" src="t052importS5.js"></script> 33<script type="text/javascript" src="t052importT5.js"></script> 34<script type="text/javascript" src="t052importM5_t052importS5.js"></script> 35<script type="text/javascript" src="t052importM5_t052importT5.js"></script> 36<script type="text/javascript" src="t052importM5Lexer.js"></script> 37<script type="text/javascript" src="t052importM5Parser.js"></script> 38 39<script type="text/javascript" src="t052importS6.js"></script> 40<script type="text/javascript" src="t052importM6_t052importS6.js"></script> 41<script type="text/javascript" src="t052importM6Lexer.js"></script> 42<script type="text/javascript" src="t052importM6Parser.js"></script> 43 44<script type="text/javascript" src="t052importS7.js"></script> 45<script type="text/javascript" src="t052importM7_t052importS7.js"></script> 46<script type="text/javascript" src="t052importM7.js"></script> 47 48<script type="text/javascript" src="t052importS8.js"></script> 49<script type="text/javascript" src="t052importM8_t052importS8.js"></script> 50<script type="text/javascript" src="t052importM8.js"></script> 51 52<!-- JsUnit include --> 53<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script> 54 55<!-- Test Code --> 56<script type="text/javascript"> 57 // Parser Tests 58 59 function execLexer(lexerCls, xinput) { 60 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 61 lexer = new (EnhancedParser(lexerCls))(cstream), 62 token; 63 64 while (true) { 65 token = lexer.nextToken(); 66 if (!token || token.getType()===org.antlr.runtime.Token.EOF) { 67 break; 68 } 69 lexer.buf += token.getText(); 70 } 71 72 return lexer.buf; 73 } 74 75 function execParser(lexerCls, parserCls, grammarEntry, xinput) { 76 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 77 lexer = new (EnhancedParser(lexerCls))(cstream), 78 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 79 parser = new (EnhancedParser(parserCls))(tstream); 80 var r = parser[grammarEntry](); 81 82 return parser.buf; 83 } 84 85 function EnhancedParser(base) { 86 var T = function() { 87 T.superclass.constructor.apply(this, arguments); 88 this.traces = []; 89 this.buf = ""; 90 }; 91 92 org.antlr.lang.extend(T, base, { 93 capture: function(t) { 94 this.buf += t; 95 }, 96 traceIn: function(ruleName, ruleIndex) { 97 this.traces.push(">"+ruleName); 98 }, 99 traceOut: function(ruleName, ruleIndex) { 100 this.traces.push("<"+ruleName); 101 }, 102 reportError: function(input, re) { 103 throw re; 104 } 105 }); 106 107 return T; 108 } 109 110 function testDelegatorInvokesDelegateRule() { 111 var found = execParser(t052importM1Lexer, 112 t052importM1Parser, 113 "s", 114 "b"); 115 assertEquals("S.a", found); 116 } 117 118 function testDelegatorInvokesDelegateRuleWithArgs() { 119 var found = execParser(t052importM2Lexer, 120 t052importM2Parser, 121 "s", 122 "b"); 123 assertEquals("S.a1000", found); 124 } 125 126 function testDelegatorAccessesDelegateMembers() { 127 var found = execParser(t052importM3Lexer, 128 t052importM3Parser, 129 "s", 130 "b"); 131 assertEquals("foo", found); 132 } 133 134 function testDelegatorInvokesFirstVersionOfDelegateRule() { 135 var found = execParser(t052importM4Lexer, 136 t052importM4Parser, 137 "s", 138 "b"); 139 assertEquals("S.a", found); 140 } 141 142 function testDelegatesSeeSameTokenType() { 143 var found = execParser(t052importM5Lexer, 144 t052importM5Parser, 145 "s", 146 "aa"); 147 assertEquals("S.x T.y", found); 148 } 149 150 function testDelegatorRuleOverridesDelegate() { 151 var found = execParser(t052importM6Lexer, 152 t052importM6Parser, 153 "a", 154 "c"); 155 assertEquals("S.a", found); 156 } 157 158 // Lexer Tests 159 160 function testLexerDelegatorInvokesDelegateRule() { 161 var found = execLexer(t052importM7, "abc"); 162 assertEquals("S.A abc", found); 163 } 164 165 function testLexerDelegatorRuleOverridesDelegate() { 166 var found = execLexer(t052importM8, "a"); 167 assertEquals("M.A a", found); 168 } 169</script> 170 171</head> 172<body> 173 <h1>t052import</h1> 174</body> 175</html> 176