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>t006lexer</title>
      6 
      7 <!-- ANTLR includes -->
      8 <script type="text/javascript" src="../../lib/antlr3-all.js"></script>
      9 <script type="text/javascript" src="t006lexer.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, t006lexer, {
     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("fofaaooa"),
     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(), 7);
     41         assertEquals(token.getText(), 'faaooa');
     42 
     43         token = lexer.nextToken();
     44         assertEquals(token.getType(), lexer.EOF);
     45     }
     46 
     47     function testMalformedInput() {
     48         var stream = new org.antlr.runtime.ANTLRStringStream('fofoaooaoa2'),
     49             lexer = new TLexer(stream),
     50             token;
     51 
     52         lexer.nextToken();
     53         lexer.nextToken();
     54         try {
     55             token = lexer.nextToken();
     56             fail("nextToken should have thrown error on invalid input");
     57         } catch (e) {
     58             assertEquals(e.expecting, 'f');
     59             assertEquals(e.getUnexpectedType(), '2');
     60             assertEquals(e.charPositionInLine, 10);
     61             assertEquals(e.line, 1);
     62         }
     63     }
     64 </script>
     65 
     66 </head>
     67 <body>
     68     <h1>t006lexer</h1>
     69 </body>
     70