Dave Jarvis' Repositories

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

Compiles and runs. No parsing, yet.

Author Dave Jarvis <email>
Date 2015-02-28 19:51:24 GMT-0800
Commit 996bdf6017ce30f09029321bc61cea030579eb9e
Parent f4683aa
build.gradle
apply plugin: "java"
+apply plugin: "application"
sourceCompatibility = 1.8
targetCompatibility = 1.8
+
+mainClassName = "com.whitemagicsoftware.rxm.Parser"
sourceSets {
main {
output.classesDir = "$buildDir/"
java {
srcDir "source"
}
+ }
+}
+
+task copyLibraries( type: Copy ) {
+ from configurations.runtime
+ into "$buildDir/libs"
+}
+
+run.dependsOn( [copyLibraries] )
+
+run {
+ if( project.hasProperty( 'args' ) ) {
+ args project.args.split()
}
}
+// Configure ANTLR
ext.antlr = [
grammarPackage: "com.whitemagicsoftware.rxm.grammar",
}
+// Run ANTLR against the grammar.
task generateGrammarSource( dependsOn: antlrOutputDir, type: JavaExec ) {
description = "Generates Java sources from ANTLR4 grammars."
source/grammar/Expr.g
-grammar Expr ;
-prog: (expr NEWLINE)* ;
-expr: expr ('*'|'/') expr
- | expr ('+'|'-') expr
- | INT
- | '(' expr ')' ;
-NEWLINE : [\r\n]+ ;
-INT : [0-9]+ ;
-
source/grammar/Query.g
+/* Relational eXpression Map
+ */
+grammar Query ;
+
+query: root line where? EOF ;
+
+/* Define the root, line map, and JOIN clauses.
+ */
+root: (TOKEN_ROOT TOKEN_MAP element) | module ;
+line: statement* ;
+
+statement: (TOKEN_POP | TOKEN_GLOB | map | iJoin | oJoin | include) ',' ;
+map : entity TOKEN_MAP node ;
+iJoin : tableColumn TOKEN_INNER tableColumn ;
+oJoin : tableColumn TOKEN_OUTER tableColumn ;
+include : TOKEN_IMPORT TOKEN_ID ;
+module : TOKEN_MODULE TOKEN_ID ;
+
+table : TOKEN_ID ;
+column : '.' TOKEN_ID ;
+tableColumn: table column ;
+
+attribute : '@' TOKEN_ID ;
+element : TOKEN_ID ;
+path : element '/' element ;
+entity : table | column ;
+node : element | attribute ;
+
+/* Define the WHERE clause.
+ */
+where : TOKEN_ID ;
+
+/* Define the tokens.
+ */
+TOKEN_ID : [A-Za-z0-9_]+ ;
+TOKEN_EOL : [\r\n]+ -> skip;
+TOKEN_WS : [ \t\r\n]+ -> skip ;
+TOKEN_POP : '^' ;
+TOKEN_GLOB : '.*' ;
+TOKEN_ROOT : 'root' ;
+TOKEN_MAP : '>' ;
+TOKEN_INNER : '+>' ;
+TOKEN_OUTER : '->' ;
+TOKEN_IMPORT: 'import' ;
+TOKEN_MODULE: 'module' ;
+
Delta 64 lines added, 9 lines removed, 55-line increase