chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r788422 - in /incubator/chemistry/trunk/chemistry: chemistry-commons/ chemistry-commons/src/main/antlr3/ chemistry-commons/src/main/antlr3/org/ chemistry-commons/src/main/antlr3/org/apache/ chemistry-commons/src/main/antlr3/org/apache/chemi...
Date Thu, 25 Jun 2009 16:48:08 GMT
Author: fguillaume
Date: Thu Jun 25 16:48:08 2009
New Revision: 788422

URL: http://svn.apache.org/viewvc?rev=788422&view=rev
Log:
Start of ANTLR grammar for CMIS SQL, mavenized and relicensed from http://hg.nuxeo.org/sandbox/nuxeo-cmis/

Added:
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml
    incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml?rev=788422&r1=788421&r2=788422&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml Thu Jun 25 16:48:08 2009
@@ -37,6 +37,10 @@
       <groupId>stax</groupId>
       <artifactId>stax-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.antlr</groupId>
+      <artifactId>antlr-runtime</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>junit</groupId>
@@ -45,4 +49,32 @@
     </dependency>
 
   </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.antlr</groupId>
+        <artifactId>antlr3-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>antlr</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.antlr</groupId>
+        <artifactId>maven-gunit-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>gunit</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
 </project>

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g?rev=788422&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
Thu Jun 25 16:48:08 2009
@@ -0,0 +1,211 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *     Stefane Fermigier, Nuxeo
+ */
+/**
+ * First try at a CMIS-SQL grammar.
+ * Directly translated from the CMIS 0.5 EBNF specs.
+ * Some rules have already been changed (or temporarily disabled) while
+ * we work around left-recursion and other issues.
+ */
+grammar CmisSql;
+
+options {
+    language = Java;
+    output = AST;
+}
+
+@header {
+package org.apache.chemistry.cmissql;
+}
+@lexer::header {
+package org.apache.chemistry.cmissql;
+}
+
+// LEXER
+
+ID
+    : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
+    ;
+
+SIGNED_NUMERIC_LITERAL
+    : '0'
+    | '-'? ('1'..'9')('0'..'9')*
+    ;
+
+CHARACTER_STRING_LITERAL
+    : '\'' ( ~'\'' | '\'\'')* '\''
+    ;
+
+WS  : ( ' ' | '\t' | '\r'? '\n' )+ { $channel=HIDDEN; }
+    ;
+
+// PARSER
+
+query: simple_table order_by_clause?;
+
+simple_table
+    : 'SELECT'^ select_list from_clause where_clause?
+    ;
+
+select_list
+    : '*'
+      -> '*'
+    | select_sublist ( ',' select_sublist )*
+      -> ^(select_sublist select_sublist*)
+    ;
+
+select_sublist
+    : value_expression ( 'AS'!? column_name )?
+    | qualifier '.*'
+    //| multi_valued_column_reference
+    ;
+
+value_expression:
+      column_reference
+    | string_value_function
+    | numeric_value_function
+    ;
+
+column_reference:
+    ( qualifier '.' )? column_name;
+
+multi_valued_column_reference:
+    ( qualifier '.' )? multi_valued_column_name;
+
+string_value_function:
+    ( 'UPPER' | 'LOWER' )? '('! column_reference ')'!;
+
+numeric_value_function:
+    'SCORE()';
+
+qualifier:
+      table_name
+    //| correlation_name
+    ;
+
+// FROM stuff
+
+from_clause: 'FROM'^ table_reference;
+
+// Use same trick as http://antlr.org/grammar/1057936474293/DmlSQL2.g to
+// remove left recursion.
+table_reference
+    : table_name ( 'AS'!? correlation_name )?
+    | joined_table
+    ;
+
+joined_table
+    : '(' joined_table ')'
+    //| table_reference join_type? 'JOIN' table_reference join_specification?
+    ;
+
+join_type: 'INNER' | 'LEFT' 'OUTER'?;
+
+join_specification:
+    'ON'^ '('! column_reference '='! column_reference ')'!;
+
+// WHERE stuff
+
+where_clause: 'WHERE'^ search_condition;
+
+// Rewritten from the spec to avoid left-recursion
+search_condition:
+    boolean_term ( 'OR'^ boolean_term )*;
+
+// Rewritten from the spec to avoid left-recursion
+boolean_term:
+    boolean_factor ( 'AND'^ boolean_factor )*;
+
+boolean_factor:
+    'NOT'^?  boolean_test;
+
+boolean_test:
+      predicate
+    | '('! search_condition ')'!
+    ;
+
+predicate:
+      comparison_predicate
+    | in_predicate
+    | like_predicate
+    | null_predicate
+    | quantified_comparison_predicate
+    | quantified_in_predicate
+    | text_search_predicate
+    | folder_predicate
+    ;
+
+comparison_predicate:
+    value_expression comp_op^ literal;
+
+comp_op:
+    '=' | '<>' | '<' | '>' | '<=' | '>=';
+
+literal:
+      SIGNED_NUMERIC_LITERAL
+    | CHARACTER_STRING_LITERAL
+    ;
+
+in_predicate:
+    column_reference 'NOT'? 'IN'^ '('! in_value_list ')'!;
+
+in_value_list:
+    literal ( ','! literal )*;
+
+like_predicate:
+    column_reference 'NOT'? 'LIKE'^ CHARACTER_STRING_LITERAL;
+
+null_predicate
+    // second alternative commented out to remove left recursion for now.
+    //( column_reference | multi_valued_column_reference ) 'IS' 'NOT'? 'NULL';
+    : column_reference 'IS'^ 'NOT'? 'NULL'
+    ;
+
+quantified_comparison_predicate:
+    literal comp_op^ 'ANY' multi_valued_column_reference;
+
+quantified_in_predicate:
+    'ANY' multi_valued_column_reference 'NOT'? 'IN'^ '('! in_value_list ')'!;
+
+text_search_predicate:
+    'CONTAINS'^ '('! qualifier? ','! text_search_expression ')'!;
+
+folder_predicate:
+    ( 'IN_FOLDER' | 'IN_TREE' )^ '(' qualifier? ',' folder_id ')';
+
+order_by_clause:
+    'ORDER BY'^ sort_specification ( ','! sort_specification )*;
+
+sort_specification:
+    column_name ( 'ASC' | 'DESC' )?;
+
+correlation_name:
+    ID;
+
+table_name:
+    ID;
+
+column_name:
+    ID;
+
+multi_valued_column_name:
+    ID;
+
+folder_id:
+    CHARACTER_STRING_LITERAL;
+
+text_search_expression:
+    CHARACTER_STRING_LITERAL;

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite?rev=788422&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Thu Jun 25 16:48:08 2009
@@ -0,0 +1,125 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *     Stefane Fermigier, Nuxeo
+ */
+gunit CmisSql;
+
+@header{
+package org.apache.chemistry.cmissql;
+}
+
+// Lexer tests
+
+ID:
+"a" OK
+"!" FAIL
+"toto" OK
+"toto123" OK
+"toto123_" OK
+"123" FAIL
+"123abc" FAIL
+
+SIGNED_NUMERIC_LITERAL:
+"123" OK
+"0" OK
+"1" OK
+"-1" OK
+"-123" OK
+"0123" FAIL
+"-0123" FAIL
+"123abc" FAIL
+
+CHARACTER_STRING_LITERAL:
+"'abc'" OK
+"'a''bc'" OK
+"'abc" FAIL
+"abc'" FAIL
+
+// Parser tests
+
+literal:
+"123" OK
+"-123" OK
+"0" OK
+"0123" FAIL
+"abc123" FAIL
+"123abc" FAIL
+"'abc'" OK
+
+order_by_clause:
+"ORDER BY toto" -> (ORDER BY toto)
+"ORDER BY titi ASC" -> (ORDER BY titi ASC)
+"ORDER BY tutu DESC" -> (ORDER BY tutu DESC)
+
+column_reference:
+"toto" -> "toto"
+"toto.titi" -> "toto . titi"
+
+in_predicate:
+"toto IN ( 'a', 'b', 'c')" -> (IN toto 'a' 'b' 'c')
+"toto IN ( 1, 2, 3)" -> (IN toto 1 2 3)
+
+comparison_predicate:
+"a = 1" -> (= a 1)
+"a <> 1" -> (<> a 1)
+
+predicate:
+"a = 1" -> (= a 1)
+"b IN ('test')" -> (IN b 'test')
+"c IS NULL" -> (IS c NULL)
+"c IS NOT NULL" -> (IS c NOT NULL)
+"1 = ANY d" -> (= 1 ANY d)
+"LOWER(type) = 'email'" -> (= LOWER type 'email')
+
+search_condition:
+"toto = 1" -> (= toto 1)
+"a = 1 AND b <> 2 OR c >= 3 AND NOT d <= 4" -> (OR (AND (= a 1) (<>
b 2)) (AND (>= c 3) (NOT (<= d 4))))
+
+// ---------------------------------------------------------------
+
+query:
+"SELECT * FROM Document" -> (SELECT * (FROM Document))
+"SELECT a, b, c FROM Document" -> (SELECT (a b c) (FROM Document))
+"SELECT a, b, c FROM Document ORDER BY a, b, c" -> (SELECT (a b c) (FROM Document)) (ORDER
BY a b c)
+
+
+// Examples from the specs.
+
+<<
+SELECT TITLE, AUTHORS, DATE
+FROM WHITE_PAPER
+WHERE ( IN_TREE( , 'ID00093854763') ) AND ( 'SMITH' = ANY AUTHORS )
+>> -> (SELECT (TITLE AUTHORS DATE) (FROM WHITE_PAPER) (WHERE (AND (IN_TREE ( , 'ID00093854763'
)) (= 'SMITH' ANY AUTHORS))))
+
+<<
+SELECT OBJECT_ID, SCORE() AS X, DESTINATION, DEPARTURE_DATES
+FROM TRAVEL_BROCHURE
+WHERE ( CONTAINS( , 'CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND
+  ( '2010-1-1' < ANY DEPARTURE_DATES )
+ORDER BY X DESC
+>> OK
+
+<<
+SELECT *
+FROM CAR_REVIEW
+WHERE ( LOWER(MAKE) = 'buick' ) OR
+  ( ANY FEATURES IN ('NAVIGATION SYSTEM', 'SATELLITE RADIO', 'MP3' ) )
+>> OK
+
+/* JOINs not working yet.
+<<SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES
+FROM POLICY AS X JOIN CLAIMS AS Y ON ( X.POLICY_NUM = Y.POLICY_NUM )
+WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )>>
OK
+*/

Modified: incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml?rev=788422&r1=788421&r2=788422&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml Thu Jun 25 16:48:08 2009
@@ -40,8 +40,19 @@
           <artifactId>cxf-codegen-plugin</artifactId>
           <version>${cxf.version}</version>
         </plugin>
+        <plugin>
+          <groupId>org.antlr</groupId>
+          <artifactId>antlr3-maven-plugin</artifactId>
+          <version>3.1.3-1</version>
+        </plugin>
+        <plugin>
+          <groupId>org.antlr</groupId>
+          <artifactId>maven-gunit-plugin</artifactId>
+          <version>3.1.3</version>
+        </plugin>
       </plugins>
     </pluginManagement>
+
     <plugins>
       <!-- Use Java 1.5 everywhere -->
       <plugin>
@@ -146,6 +157,11 @@
 	<artifactId>cxf-rt-frontend-jaxrs</artifactId>
 	<version>${cxf.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.antlr</groupId>
+        <artifactId>antlr-runtime</artifactId>
+        <version>3.1.3</version>
+      </dependency>
 
       <dependency>
         <groupId>junit</groupId>



Mime
View raw message