// 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; /**/ import nzdis.lang.oql.node.Node; import nzdis.lang.oql.lexer.Lexer; import nzdis.lang.oql.lexer.LexerException; import nzdis.lang.oql.parser.Parser; import nzdis.lang.oql.parser.ParserException; import java.io.*; /** * Generic parser API for OQL input. This class is not really a * builder (in terms of Builder pattern), while the result can be * collected directly from it. This builder will parse the input string * and create Abstract Syntax Tree, via set of utility methods. * *@author Mariusz Nowostawski *@version @version@ $Revision: 1.1 $ */ public class TreeBuilder { public static Node getNode(final Reader r, boolean simplified) throws IOException, LexerException, ParserException { return getNode(new PushbackReader(r), simplified); } public static Node getNode(final StringBuffer text, boolean simplified) throws IOException, LexerException, ParserException { return getNode(text.toString(), simplified); } public static Node getNode(final String text) throws IOException, LexerException, ParserException { return getNode(text, true); } public static Node getNode(final String text, boolean simplified) throws IOException, LexerException, ParserException { return getNode(new PushbackReader (new BufferedReader (new StringReader(text))), simplified); } public static Node getNode(final PushbackReader r, boolean simplified) throws IOException, LexerException, ParserException { Lexer lexer = new Lexer(r); Parser parser = new Parser(lexer); Node ast = parser.parse(); if(simplified) SimpleAstWalker.simplify(ast); return ast; } } //TreeBuilder /////////////// end of file /////////////////