Home | History | Annotate | Download | only in functional
      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>t007lexer</title>
      6 
      7 <!-- ANTLR includes -->
      8 <script type="text/javascript" src="../../lib/antlr3-all.js"></script>
      9 <script type="text/javascript" src="t007lexer.js"></script>
     10 
     11 <!-- JsUnit include -->
     12 <script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
     13 
     14 <!-- Test Code -->
     15 <script type="text/javascript">
     16     function TLexer() {
     17         TLexer.superclass.constructor.apply(this, arguments);
     18     }
     19     org.antlr.lang.extend(TLexer, t007lexer, {
     20         reportError: function(re) {
     21             /* don't recover, just crash */
     22             throw re;
     23         }
     24     });
     25 
     26     function testValid() {
     27         var stream = new org.antlr.runtime.ANTLRStringStream("fofababbooabb"),
     28             lexer = new TLexer(stream),
     29             token;
     30 
     31         token = lexer.nextToken();
     32         assertEquals(token.getType(), lexer.FOO);
     33         assertEquals(token.getStartIndex(), 0);
     34         assertEquals(token.getStopIndex(), 1);
     35         assertEquals(token.getText(), "fo");
     36 
     37         token = lexer.nextToken();
     38         assertEquals(token.getType(), lexer.FOO);
     39         assertEquals(token.getStartIndex(), 2);
     40         assertEquals(token.getStopIndex(), 12);
     41         assertEquals(token.getText(), 'fababbooabb');
     42 
     43         token = lexer.nextToken();
     44         assertEquals(token.getType(), lexer.EOF);
     45     }
     46 
     47     function testMalformedInput() {
     48         var stream = new org.antlr.runtime.ANTLRStringStream('foaboao'),
     49             lexer = new TLexer(stream),
     50             token;
     51 
     52         try {
     53             token = lexer.nextToken();
     54             fail("nextToken should have thrown error on invalid input");
     55         } catch (e) {
     56             assertEquals(e.getUnexpectedType(), 'o');
     57             assertEquals(e.charPositionInLine, 6);
     58             assertEquals(e.line, 1);
     59         }
     60     }
     61 </script>
     62 
     63 </head>
     64 <body>
     65     <h1>t007lexer</h1>
     66 </body>
     67