Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Javadocs generate hyperlinks to Oracle and ANTLR. Updated grammar to trigger events for pops and globs.

Author Dave Jarvis <email>
Date 2015-03-01 21:59:49 GMT-0800
Commit d96495528c047741100316eeaeb863263935c599
Parent 43c21c4
build.gradle
targetCompatibility = 1.8
-mainClassName = "com.whitemagicsoftware.rxm.Parser"
+// For testing.
+mainClassName = "com.whitemagicsoftware.rxm.Main"
+
+def javadocLinks = [
+ "http://docs.oracle.com/javase/8/docs/api",
+ "http://www.antlr.org/api/Java",
+] as String[]
sourceSets {
destinationDir = file( "docs/javadoc" )
include( "**/*.java" )
+
+ options.links( javadocLinks )
}
source/grammar/Query.g
/* Define the symbols. */
-T_POP : '^' ;
-T_GLOB : '.*' ;
T_MAP : '>' ;
T_INNER : '+>' ;
T_OUTER : '->' ;
-T_SEP : ',' ;
+T_POP : '^' ;
+T_GLOB : '.*' ;
+T_EOL : ',' ;
T_WHERE : ';' ;
/* Define the table and path symbols. */
T_PERIOD: '.' ;
T_AT : '@' ;
T_SLASH : '/' ;
/* Define the identifier. */
-T_ID : [A-Za-z0-9_]+ ;
+T_ID: [A-Za-z0-9_]+ ;
/* Define skippable tokens. */
-T_EOL : [\r\n]+ -> skip;
-T_WS : [ \t\r\n]+ -> skip ;
+T_WS: [ \t\r\n]+ -> skip ;
/* Define the WHERE clause symbols. */
/* Define the root, line map, and JOIN clauses.
*/
-start: (root | module) T_SEP ;
+start: (root | module) T_EOL ;
root : T_ROOT T_MAP element ;
line : statement+ ;
-statement: (T_POP | T_GLOB | map | iJoin | oJoin | include) T_SEP ;
+statement: (pop | glob | map | innerJoin | outerJoin | include) T_EOL ;
+pop : T_POP ;
+glob : T_GLOB ;
map : entity T_MAP node ;
-iJoin : tableColumn T_INNER tableColumn ;
-oJoin : tableColumn T_OUTER tableColumn ;
+innerJoin: tableColumn T_INNER tableColumn ;
+outerJoin: tableColumn T_OUTER tableColumn ;
include : T_IMPORT T_ID ;
module : T_MODULE T_ID ;
source/java/com/whitemagicsoftware/rxm/Parser.java
*/
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;
}
}
Delta 41 lines added, 37 lines removed, 4-line increase