KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > n3 > AntlrUtils


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.n3;
7 import java.io.* ;
8 import antlr.* ;
9 import antlr.collections.*;
10
11 /** Miscellaneous things in support of Antlr-derived parsers
12  *
13  * @author Andy Seaborne
14  * @version $Id: AntlrUtils.java,v 1.7 2005/02/21 12:04:02 andy_seaborne Exp $
15  */

16
17 public class AntlrUtils
18 {
19     /** Format an AST node */
20     static String JavaDoc ast(AST t)
21     {
22         return "[" + t.getText() + ", " + N3Parser.getTokenNames()[t.getType()] + "]";
23     }
24     
25     /** Print an AST node (but not its subnodes) */
26     static void ast(PrintStream out, AST t)
27     {
28         String JavaDoc s = ast(t) ;
29         out.println(s);
30     }
31
32     /** Print an AST node (but not its subnodes) */
33     static void ast(Writer w, AST t)
34     {
35         String JavaDoc s = ast(t) ;
36         try { w.write(s); } catch (IOException ioEx) {}
37     }
38
39     /** Format an AST node and its subnodes. Derived from the antlr code */
40     static public String JavaDoc ASTout(AST t)
41     {
42         String JavaDoc ts = "";
43         if (t.getFirstChild() != null)
44             ts += " (";
45         ts += " '" + t.toString()+"'";
46         if (t.getFirstChild() != null)
47         {
48             ts += ASTout((BaseAST) t.getFirstChild()) ;
49         }
50         if (t.getFirstChild() != null)
51             ts += " )";
52         if (t.getNextSibling() != null)
53         {
54             ts += ASTout((BaseAST) t.getNextSibling()) ;
55         }
56         return ts;
57     }
58 }
59 /*
60  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
61  * All rights reserved.
62  *
63  * Redistribution and use in source and binary forms, with or without
64  * modification, are permitted provided that the following conditions
65  * are met:
66  * 1. Redistributions of source code must retain the above copyright
67  * notice, this list of conditions and the following disclaimer.
68  * 2. Redistributions in binary form must reproduce the above copyright
69  * notice, this list of conditions and the following disclaimer in the
70  * documentation and/or other materials provided with the distribution.
71  * 3. The name of the author may not be used to endorse or promote products
72  * derived from this software without specific prior written permission.
73  *
74  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84  */

85
Popular Tags