KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > parser > re > DebugRegExp


1 /*
2  * DebugRegExp.java
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 2.1
7  * of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17  * MA 02111-1307, USA.
18  *
19  * Copyright (c) 2003-2005 Per Cederberg. All rights reserved.
20  */

21
22 package net.percederberg.grammatica.parser.re;
23
24 import java.io.FileReader JavaDoc;
25
26 /**
27  * A test program for the RegExp class.
28  *
29  * @author Per Cederberg, <per at percederberg dot net>
30  * @version 1.5
31  */

32 public class DebugRegExp {
33
34     /**
35      * The application entry point.
36      *
37      * @param args the command-line parameters
38      */

39     public static void main(String JavaDoc[] args) {
40         char[] buffer = new char[1024];
41         FileReader JavaDoc in;
42         int length;
43         String JavaDoc str = "";
44
45         // Check command-line arguments
46
if (args.length != 1) {
47             System.err.println("Syntax: DebugRegExp <regexpfile>");
48             System.exit(1);
49         }
50
51         // Read file contents
52
try {
53             in = new FileReader JavaDoc(args[0]);
54             length = in.read(buffer);
55             str = new String JavaDoc(buffer, 0, length);
56         } catch (Exception JavaDoc e) {
57             e.printStackTrace();
58             System.exit(1);
59         }
60
61         // Create regular expression
62
try {
63             System.out.println(new RegExp(str, false));
64         } catch (RegExpException e) {
65             e.printStackTrace();
66             System.exit(1);
67         }
68     }
69 }
70
Popular Tags