| | */ |
| | public class Parser extends QueryBaseListener { |
| | + private RXM rxm; |
| | + |
| | /** |
| | * Creates a Parser instance that parses a given <b>rxm</b> string. |
| | * |
| | - * @param rxm The <b>rxm</b> to parse into a SQL statement. |
| | + * @param rxm The <b>rxm</b> instance responsible for receiving information |
| | + * that allows it to build a SQL statement. |
| | * |
| | - * @throws ParserException The <b>rxm</b> string could not be parsed |
| | - * into a SQL statement. |
| | + * @throws NullRXMException The <b>rxm</b> parameter is null. |
| | */ |
| | - public Parser( String rxm ) throws ParserException { |
| | + public Parser( RXM rxm ) throws NullRXMException { |
| | + if( rxm == null ) { |
| | + throw new NullRXMException(); |
| | + } |
| | + |
| | + this.rxm = rxm; |
| | + } |
| | + |
| | + public void parse( String rxm ) { |
| | QueryLexer lexer = new QueryLexer( new ANTLRInputStream( rxm ) ); |
| | CommonTokenStream tokens = new CommonTokenStream( lexer ); |
 |
| | @Override |
| | public void enterRoot( QueryParser.RootContext context ) { |
| | - System.out.println( ">> root" ); |
| | + |
| | } |
| | |
 |
| | public void enterElement( QueryParser.ElementContext context ) { |
| | System.out.println( "Element: " + context.getText() ); |
| | - } |
| | - |
| | - /** |
| | - * Runs the parser to generate a SQL statement. |
| | - * |
| | - * @param args Contains the file name with an <b>rxm</b> to parse. |
| | - * |
| | - * @throws IOException The file could not be read. |
| | - * @throws ParserException The file could not be parsed. |
| | - */ |
| | - public static void main( String args[] ) |
| | - throws IOException, ParserException { |
| | - Parser parser = new Parser( readFile( args[0] ) ); |
| | } |
| | |
| | /** |
| | - * Reads the entire contents of the file (specified by the given path). |
| | - * This uses the default character set when reading the file. |
| | + * Returns the Relational eXpression Map to populate while walking |
| | + * through the AST. |
| | * |
| | - * @param path The path to the file with an <b>rxm</b> to read. |
| | - * @throws IOException The file could not be read. |
| | + * @return The <b>rxm</b> instance to update with information from |
| | + * the AST. |
| | */ |
| | - private static String readFile( String path ) throws IOException { |
| | - Charset encoding = Charset.defaultCharset(); |
| | - byte[] encoded = Files.readAllBytes( Paths.get(path) ); |
| | - return new String(encoded, encoding); |
| | + private RXM getRXM() { |
| | + return this.rxm; |
| | } |
| | } |