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