• 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>t056lexer</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t056lexer1Lexer.js"></script>
10<script type="text/javascript" src="t056lexer1Parser.js"></script>
11<script type="text/javascript" src="t056lexer2Lexer.js"></script>
12<script type="text/javascript" src="t056lexer2Parser.js"></script>
13<script type="text/javascript" src="t056lexer3Lexer.js"></script>
14<script type="text/javascript" src="t056lexer3Parser.js"></script>
15<script type="text/javascript" src="t056lexer4Lexer.js"></script>
16<script type="text/javascript" src="t056lexer4Parser.js"></script>
17<script type="text/javascript" src="t056lexer5Lexer.js"></script>
18<script type="text/javascript" src="t056lexer5Parser.js"></script>
19<script type="text/javascript" src="t056lexer6Lexer.js"></script>
20<script type="text/javascript" src="t056lexer6Parser.js"></script>
21<script type="text/javascript" src="t056lexer7Lexer.js"></script>
22<script type="text/javascript" src="t056lexer7Parser.js"></script>
23<script type="text/javascript" src="t056lexer8Lexer.js"></script>
24<script type="text/javascript" src="t056lexer8Parser.js"></script>
25<script type="text/javascript" src="t056lexer9Lexer.js"></script>
26<script type="text/javascript" src="t056lexer9Parser.js"></script>
27<script type="text/javascript" src="t056lexer10Lexer.js"></script>
28<script type="text/javascript" src="t056lexer10Parser.js"></script>
29<script type="text/javascript" src="t056lexer11Lexer.js"></script>
30<script type="text/javascript" src="t056lexer11Parser.js"></script>
31<script type="text/javascript" src="t056lexer12.js"></script>
32<script type="text/javascript" src="t056lexer13.js"></script>
33<script type="text/javascript" src="t056lexer14.js"></script>
34<script type="text/javascript" src="t056lexer15.js"></script>
35
36<!-- JsUnit include -->
37<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
38
39<!-- Test Code -->
40<script type="text/javascript">
41    function execParser(lexerCls, parserCls, grammarEntry, xinput)
42    {
43        var cstream = new org.antlr.runtime.ANTLRStringStream(xinput),
44            lexer = new lexerCls(cstream),
45            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
46            parser = new parserCls(tstream),
47            output = "";
48        lexer.xlog = function(msg){output += msg;};
49        parser.xlog = lexer.xlog;
50        var r = parser[grammarEntry]();
51
52        return output;
53    }
54
55    function execLexer(lexerCls, xinput) {
56        var token,
57            cstream = new org.antlr.runtime.ANTLRStringStream(xinput),
58            lexer = new lexerCls(cstream);
59        do {
60            token = lexer.nextToken();
61        } while (token.getType()!==lexer.EOF);
62    }
63
64function testSetText() {
65    var found = execParser(t056lexer1Lexer, t056lexer1Parser, "a", "\\t");
66    assertEquals("  ", found);
67}
68
69function testRefToRuleDoesNotSetTokenNorEmitAnother() {
70    // this must return A not I to the parser; calling a nonfragment rule
71    // from a nonfragment rule does not set the overall token.
72    var found = execParser(t056lexer2Lexer, t056lexer2Parser, "a", "-34");
73    assertEquals("-34", found);
74}
75
76function testRefToRuleDoesNotSetChannel() {
77    // this must set channel of A to HIDDEN.  $channel is local to rule
78    // like $type.
79    var found = execParser(t056lexer3Lexer, t056lexer3Parser, "a", "- 34");
80    assertEquals("- 34, channel=0", found);
81}
82
83function testWeCanSetType() {
84    var found = execParser(t056lexer4Lexer, t056lexer4Parser, "a", "-34");
85    assertEquals("-34", found);
86}
87
88function testRefToFragment() {
89    // this must return A not I to the parser; calling a nonfragment rule
90    // from a nonfragment rule does not set the overall token.
91    var found = execParser(t056lexer5Lexer, t056lexer5Parser, "a", "-34");
92    assertEquals("-34", found);
93}
94
95function testMultipleRefToFragment() {
96    // this must return A not I to the parser; calling a nonfragment rule
97    // from a nonfragment rule does not set the overall token.
98    var found = execParser(t056lexer6Lexer, t056lexer6Parser, "a", "3.14159");
99    assertEquals("3.14159", found);
100}
101
102function testLabelInSubrule() {
103    // can we see v outside?
104    var found = execParser(t056lexer7Lexer, t056lexer7Parser, "a", "hi 342");
105    assertEquals("342", found);
106}
107
108function testRefToTokenInLexer() {
109    var found = execParser(t056lexer8Lexer, t056lexer8Parser, "a", "342");
110    assertEquals("342", found);
111}
112
113function testListLabelInLexer() {
114    var found = execParser(t056lexer9Lexer, t056lexer9Parser, "a", "33 297");
115    assertEquals(" 33 297", found);
116}
117
118function testDupListRefInLexer() {
119    var found = execParser(t056lexer10Lexer, t056lexer10Parser, "a", "33 297");
120    assertEquals(" 33 297", found);
121}
122
123function testCharLabelInLexer() {
124    var found = execParser(t056lexer11Lexer, t056lexer11Parser, "a", "a");
125    assertEquals("a", found);
126}
127
128function testRepeatedLabelInLexer() {
129    execLexer(t056lexer12, "ababab");
130}
131
132function testRepeatedRuleLabelInLexer() {
133    execLexer(t056lexer13, "aa");
134}
135
136function testIsolatedEOTEdge() {
137    execLexer(t056lexer14, "qbalogna!q");
138}
139
140function testEscapedLiterals() {
141    execLexer(t056lexer15, "\\\"");
142}
143</script>
144
145</head>
146<body>
147    <h1>t056lexer</h1>
148</body>
149</html>
150
151