• 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>t044trace</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t044traceLexer.js"></script>
10<script type="text/javascript" src="t044traceParser.js"></script>
11
12<!-- JsUnit include -->
13<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
14
15<!-- Test Code -->
16<script type="text/javascript">
17    var TLexer = function() {
18        TLexer.superclass.constructor.apply(this, arguments);
19        this.traces = [];
20    };
21    org.antlr.lang.extend(TLexer, t044traceLexer, {
22        traceIn: function(ruleName, ruleIndex) {
23            this.traces.push(">"+ruleName);
24        },
25        traceOut: function(ruleName, ruleIndex) {
26            this.traces.push("<"+ruleName);
27        },
28        recover: function(re) {
29            /* don't recover, just crash */
30            throw re;
31        }
32    });
33
34    var TParser = function() {
35        TParser.superclass.constructor.apply(this, arguments);
36        this.traces = [];
37    };
38    org.antlr.lang.extend(TParser, t044traceParser, {
39        traceIn: function(ruleName, ruleIndex) {
40            this.traces.push(">"+ruleName);
41        },
42        traceOut: function(ruleName, ruleIndex) {
43            this.traces.push("<"+ruleName);
44        },
45        recover: function(re) {
46            /* don't recover, just crash */
47            throw re;
48        }
49    });
50
51
52    function testTrace() {
53        var cstream = new org.antlr.runtime.ANTLRStringStream('< 1 + 2 + 3 >'),
54            lexer = new TLexer(cstream),
55            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
56            parser = new TParser(tstream);
57
58        parser.a();
59        assertArrayEquals(lexer.traces,
60            [ '>T__6', '<T__6', '>WS', '<WS', '>INT', '<INT', '>WS', '<WS',
61              '>T__8', '<T__8', '>WS', '<WS', '>INT', '<INT', '>WS', '<WS',
62              '>T__8', '<T__8', '>WS', '<WS', '>INT', '<INT', '>WS', '<WS',
63              '>T__7', '<T__7']
64        );
65        assertArrayEquals(parser.traces,
66            [ '>a', '>synpred1_t044trace_fragment', '<synpred1_t044trace_fragment', '>b', '>c',
67              '<c', '>c', '<c', '>c', '<c', '<b', '<a' ]
68        );
69    }
70</script>
71
72</head>
73<body>
74    <h1>t044trace</h1>
75</body>
76</html>
77