1 5 6 package com.hp.hpl.jena.n3; 7 import java.io.* ; 8 import antlr.* ; 9 import antlr.collections.*; 10 11 16 17 public class AntlrUtils 18 { 19 20 static String ast(AST t) 21 { 22 return "[" + t.getText() + ", " + N3Parser.getTokenNames()[t.getType()] + "]"; 23 } 24 25 26 static void ast(PrintStream out, AST t) 27 { 28 String s = ast(t) ; 29 out.println(s); 30 } 31 32 33 static void ast(Writer w, AST t) 34 { 35 String s = ast(t) ; 36 try { w.write(s); } catch (IOException ioEx) {} 37 } 38 39 40 static public String ASTout(AST t) 41 { 42 String 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 85 | Popular Tags |