Home | History | Annotate | Download | only in lucene
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * See LICENSE.txt included in this distribution for the specific
      9  * language governing permissions and limitations under the License.
     10  *
     11  * When distributing Covered Code, include this CDDL HEADER in each
     12  * file and include the License file at LICENSE.txt.
     13  * If applicable, add the following below this CDDL HEADER, with the
     14  * fields enclosed by brackets "[]" replaced with your own identifying
     15  * information: Portions Copyright [yyyy] [name of copyright owner]
     16  *
     17  * CDDL HEADER END
     18  */
     19 
     20 /*
     21  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     22  * Use is subject to license terms.
     23  */
     24 
     25 /*
     26  * ident	"$Id$"
     27  */
     28 
     29 package org.opensolaris.tonic.search.lucene;
     30 
     31 import java.io.*;
     32 %%
     33 
     34 %public
     35 %class TroffScanner
     36 %unicode
     37 %function next
     38 %type String
     39 %ignorecase
     40 
     41 %{
     42     public void close() throws IOException {
     43         yyclose();
     44     }
     45 
     46     public void reInit(char[] buf, int len) {
     47         yyreset((Reader) null);
     48         zzBuffer = buf;
     49         zzEndRead = len;
     50         zzAtEOF = true;
     51         zzStartRead = 0;
     52       }
     53 
     54     public static void main(String argv[]) {
     55         if (argv.length == 0) {
     56             System.out.println("Usage : java TroffReader <inputfile>");
     57         } else {
     58             long start = System.currentTimeMillis();
     59             for (String arg : argv) {
     60                 TroffScanner scanner = null;
     61                 try {
     62                     scanner = new TroffScanner( new BufferedReader(new java.io.FileReader(arg)));
     63                     String text;
     64                     while ((text = scanner.next()) != null) {
     65                         System.out.print(text);
     66                     }
     67                 } catch (Exception e) {
     68                     System.out.println(e);
     69                     e.printStackTrace();
     70                 }
     71             }
     72             long stop = System.currentTimeMillis();
     73 
     74             System.out.println("Duration: " + (stop - start) + " msec");
     75         }
     76     }
     77 
     78 %}
     79 
     80 Whitespace  = [ \t\f\r]
     81 Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
     82 Number = [0-9]+|[0-9]+\.[0-9]+| "0[xX]" [0-9a-fA-F]+
     83 Printable = [\@\$\%\^\&\-+=\'\?\.\:]
     84 
     85 %%
     86 ^\.[ \t]*(EQ|in|sp|sh|ne|rt|br|pn|ds|de|if|ig|el|ft|hy|ie|ll|ps|rm|ta|tm|nr|rr|ti|NH|DT|EE|Sp|Sh|\\\"|\.)[^\n]*\n {}
     87 ^.[a-zA-Z]{1,2} {}
     88 \\f[ABCIR]  {}
     89 ^"...\\\"" {}
     90 
     91 \\&.        {return ".";}
     92 {Identifier}|{Number}|{Printable}|{Whitespace}	{return yytext();}
     93 <<EOF>>   { return null;}
     94 .|\n	{return "\n";}
     95