Dave Jarvis' Repositories

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

Compiles, parses, and runs.

Author Dave Jarvis <email>
Date 2015-03-01 00:08:36 GMT-0800
Commit 27d4551b549b95ba60319b4cbdfff4c922885243
Parent 34dc914
Delta 91 lines added, 48 lines removed, 43-line increase
source/grammar/Query.g
-/* Relational eXpression Map
- */
+/* Relational eXpression Map */
grammar Query ;
-query: start line ;
-/*query: start line where? EOF ;*/
+/* Define the keywords first (otherwise T_ID would match first). */
+T_ROOT : 'root' ;
+T_IMPORT: 'import' ;
+T_MODULE: 'module' ;
+
+/* Define the symbols. */
+T_POP : '^' ;
+T_GLOB : '.*' ;
+T_MAP : '>' ;
+T_INNER : '+>' ;
+T_OUTER : '->' ;
+T_SEP : ',' ;
+T_WHERE : ';' ;
+
+/* Define the table and path symbols. */
+T_PERIOD: '.' ;
+T_AT : '@' ;
+T_SLASH : '/' ;
+
+/* Define the identifier. */
+T_ID : [A-Za-z0-9_]+ ;
+
+/* Define skippable tokens. */
+T_EOL : [\r\n]+ -> skip;
+T_WS : [ \t\r\n]+ -> skip ;
+
+/* Define the WHERE clause symbols. */
+T_COMP_EQ : '=' ;
+T_COMP_INEQ : '<>' ;
+T_COMP_LT : '<' ;
+T_COMP_GT : '>' ;
+T_COMP_LTE : '<=' ;
+T_COMP_GTE : '>=' ;
+
+T_LOGIC_AND : '&&' ;
+T_LOGIC_OR : '||' ;
+
+T_EXPR_OPEN : '(' ;
+T_EXPR_CLOSE: ')' ;
+
+query: start line where? EOF ;
/* Define the root, line map, and JOIN clauses.
*/
-start: (root | module) TOKEN_TERM ;
-root : TOKEN_ROOT TOKEN_MAP element ;
+start: (root | module) T_SEP ;
+root : T_ROOT T_MAP element ;
line : statement+ ;
-statement: (TOKEN_POP | TOKEN_GLOB | map | iJoin | oJoin | include) TOKEN_TERM ;
-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 ;
+statement: (T_POP | T_GLOB | map | iJoin | oJoin | include) T_SEP ;
+map : entity T_MAP node ;
+iJoin : tableColumn T_INNER tableColumn ;
+oJoin : tableColumn T_OUTER tableColumn ;
+include : T_IMPORT T_ID ;
+module : T_MODULE T_ID ;
-table : TOKEN_ID ;
-column : TOKEN_PERIOD TOKEN_ID ;
+table : T_ID ;
+column : T_PERIOD T_ID ;
tableColumn: table column ;
-attribute : TOKEN_AT TOKEN_ID ;
-element : TOKEN_ID ;
-path : element TOKEN_SLASH element ;
+attribute : T_AT T_ID ;
+element : T_ID ;
+path : element T_SLASH element ;
+
entity : table | column ;
-node : element | attribute ;
+node : element | attribute | path ;
-/* Define the tokens.
+/* Define the WHERE clause.
*/
-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' ;
-TOKEN_TERM : ',' ;
+where : T_WHERE ;
-TOKEN_PERIOD : '.' ;
-TOKEN_AT : '@' ;
-TOKEN_SLASH : '/' ;
+/*
+expression : tableColumn () tableColumn ;
+
+
+WEmpty. Where : Where ;
+WEq. Where : TableColumn ComparatorOperatorEquality AllValues ;
+WComp. Where : TableColumn ComparatorOperator Value ;
+WLogic. Where : Where LogicalOp Where ;
+WParen. Where : "(" Where ")" ;
+*/
source/java/com/whitemagicsoftware/rxm/Parser.java
@Override
- public void enterQuery( QueryParser.QueryContext context ) {
- System.out.println( "Enter Query" );
+ public void enterRoot( QueryParser.RootContext context ) {
+ System.out.println( ">> root" );
}
- public void exitQuery( QueryParser.QueryContext context ) {
- System.out.println( "Exit Query" );
+ @Override
+ public void exitRoot( QueryParser.RootContext context ) {
+ System.out.println( "<< root" );
+ }
+
+ @Override
+ public void enterElement( QueryParser.ElementContext context ) {
+ System.out.println( "Element: " + context.getText() );
}
+
/**
test/people.rxm
-root > people,
-person > person,
-.first_name > first,
-.last_name > name/last,
-.age > @age,
-account.person_id +> person.person_id,
-account > account,
-.id > @id,
+root > people,
+person > person,
+.first_name > first,
+.last_name > name/last,
+.age > @age,
+account.person_id +> person.person_id,
+account > account,
+.id > @id,
^,
-address > address,
+address > address,
.*,
-account.person_id -> company.person_id,
+account.person_id -> company.person_id,
+;