Skip to content
Snippets Groups Projects
Commit 5d5dda0a authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Started to write a prettyprinter

parent 0137d4eb
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
import AST.Start;
public class PrettyPrint extends Parser {
public static void main(String args[]) {
Start ast = parse(args);
// Dump the AST
ast.prettyPrint(" ", System.out);
}
}
// -*-Java-*-
/*
* Copyright (C) 2007 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of XmlSchemaCompiler.
*/
import java.io.PrintStream;
aspect PrettyPrinter {
public void ASTNode.prettyPrint(String ind, PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).prettyPrint(ind,pStream);
}
}
public void XsElement.prettyPrint(String ind, PrintStream pStream) {
if (hasName()) {
pStream.println(ind+"Element: "+getName());
}
}
}
aspect Misc {
syn String XsElement.getName() {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof Name) {
return getAttribute(i).getAttValue().getSTRING_LITERAL();
}
}
// OK, no name found so let's report that
return "NoNameFound";
}
syn boolean XsElement.hasName() {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof Name) {
return true;
}
}
// OK, no name found so let's report that
return false;
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment