// This file is copyrighted and is part of nzdis-oql package. // See the file LICENSE for copyright information and the terms and conditions for copying, distributing and modifications of nzdis-oql package. // @copyright@ package nzdis.lang.oql.app; /**/ import nzdis.lang.oql.analysis.DepthFirstAdapter; import nzdis.lang.oql.node.*; /** * Simple OQL AST walker. This is simple OQL Abstract Syntax Tree walker * which will visit each of the nodes and print on standard output the * name of particular node visited. This class can be very usefull while * testing the tree structure for a given OQL sentence. * *@author Mariusz Nowostawski *@version @version@ $Revision: 1.1 $ */ class PrintWalker extends DepthFirstAdapter { int indent = 0; void indent(){ String s = new String (""); for(int i=0; i < indent; i++) s += " "; System.out.print(s); } public void defaultIn(Node node) { indent(); System.out.println(node.getClass().toString().substring(27)); indent++; } public void defaultOut(Node node) { indent--; } public void defaultCase(Node node) { indent(); System.out.println(node.getClass().toString().substring(27)+": " + ((Token) node).getText()); } }