Author: fguillaume
Date: Mon Jun 29 12:53:05 2009
New Revision: 789311
URL: http://svn.apache.org/viewvc?rev=789311&view=rev
Log:
Split grammar into lexer and parser, put generated .tokens file in the built
JAR for reuse
Added:
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
- copied, changed from r788671,
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
- copied, changed from r788671,
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
Removed:
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
Modified:
incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml
incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
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=789311&r1=789310&r2=789311&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml Mon Jun 29
12:53:05 2009
@@ -51,23 +51,57 @@
</dependencies>
<build>
+ <resources>
+ <resource>
+ <directory>target/generated-resources</directory>
+ </resource>
+ </resources>
+
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<executions>
<execution>
+ <!-- default phase: process-sources -->
+ <phase>generate-sources</phase>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase> <!-- after process-sources -->
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>target/generated-sources/antlr3</directory>
+ <includes>
+ <!-- don't include lexer tokens, which are identical -->
+ <include>*Parser.tokens</include>
+ </includes>
+ </resource>
+ </resources>
+
<outputDirectory>target/generated-resources/org/apache/chemistry/cmissql</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.antlr</groupId>
<artifactId>maven-gunit-plugin</artifactId>
<executions>
<execution>
+ <!-- default phase: test -->
<goals>
<goal>gunit</goal>
</goals>
Copied:
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
(from r788671,
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/CmisSqlLexer.g?p2=incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g&p1=incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g&r1=788671&r2=789311&rev=789311&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
Mon Jun 29 12:53:05 2009
@@ -13,28 +13,86 @@
*
* Authors:
* Stefane Fermigier, Nuxeo
+ * Florent Guillaume, 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.
+ * CMIS-SQL lexer.
*/
-grammar CmisSql;
+lexer grammar CmisSqlLexer;
-options {
- language = Java;
- output = AST;
+tokens {
+ ORDER_BY;
}
@header {
-package org.apache.chemistry.cmissql;
-}
-...@lexer::header {
+/*
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ *
+ * 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
+ * Florent Guillaume, Nuxeo
+ *
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ */
package org.apache.chemistry.cmissql;
}
-// LEXER
+// ----- Generic SQL -----
+
+SELECT : 'SELECT';
+FROM : 'FROM';
+AS : 'AS';
+JOIN : 'JOIN';
+INNER : 'INNER';
+OUTER : 'OUTER';
+LEFT : 'LEFT';
+RIGHT : 'RIGHT';
+ON : 'ON';
+WHERE : 'WHERE';
+ORDER : 'ORDER';
+BY : 'BY';
+ASC : 'ASC';
+DESC : 'DESC';
+
+// ----- Operators -----
+IS : 'IS';
+NULL : 'NULL';
+AND : 'AND';
+OR : 'OR';
+NOT : 'NOT';
+IN : 'IN';
+LIKE : 'LIKE';
+ANY : 'ANY';
+CONTAINS : 'CONTAINS';
+SCORE : 'SCORE';
+IN_FOLDER : 'IN_FOLDER';
+IN_TREE : 'IN_TREE';
+UPPER : 'UPPER';
+LOWER : 'LOWER';
+
+STAR : '*';
+LPAR : '(';
+RPAR : ')';
+COMMA : ',';
+DOT : '.';
+EQ : '=';
+NEQ : '<>';
+LT : '<';
+GT : '>';
+LTEQ : '<=';
+GTEQ : '>=';
ID
: ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
@@ -52,160 +110,5 @@
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;
Copied:
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
(from r788671,
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/CmisSqlParser.g?p2=incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g&p1=incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g&r1=788671&r2=789311&rev=789311&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSql.g
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
Mon Jun 29 12:53:05 2009
@@ -13,63 +13,60 @@
*
* Authors:
* Stefane Fermigier, Nuxeo
+ * Florent Guillaume, 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.
+ * CMIS-SQL parser.
*/
-grammar CmisSql;
+parser grammar CmisSqlParser;
options {
+ tokenVocab = CmisSqlLexer;
language = Java;
output = AST;
}
@header {
+/*
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ *
+ * 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
+ * Florent Guillaume, Nuxeo
+ *
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ */
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^ select_list from_clause where_clause?
;
select_list
- : '*'
- -> '*'
- | select_sublist ( ',' select_sublist )*
+ : STAR
+ -> STAR
+ | select_sublist ( COMMA select_sublist )*
-> ^(select_sublist select_sublist*)
;
select_sublist
- : value_expression ( 'AS'!? column_name )?
- | qualifier '.*'
+ : value_expression ( AS!? column_name )?
+ | qualifier DOT STAR
//| multi_valued_column_reference
;
@@ -80,16 +77,16 @@
;
column_reference:
- ( qualifier '.' )? column_name;
+ ( qualifier DOT )? column_name;
multi_valued_column_reference:
- ( qualifier '.' )? multi_valued_column_name;
+ ( qualifier DOT )? multi_valued_column_name;
string_value_function:
- ( 'UPPER' | 'LOWER' )? '('! column_reference ')'!;
+ ( UPPER | LOWER )? LPAR! column_reference RPAR!;
numeric_value_function:
- 'SCORE()';
+ SCORE LPAR RPAR;
qualifier:
table_name
@@ -98,43 +95,43 @@
// FROM stuff
-from_clause: 'FROM'^ table_reference;
+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 )?
+ : table_name ( AS!? correlation_name )?
| joined_table
;
joined_table
- : '(' joined_table ')'
+ : LPAR joined_table RPAR
//| table_reference join_type? 'JOIN' table_reference join_specification?
;
-join_type: 'INNER' | 'LEFT' 'OUTER'?;
+join_type: INNER | LEFT OUTER?;
join_specification:
- 'ON'^ '('! column_reference '='! column_reference ')'!;
+ ON^ LPAR! column_reference EQ! column_reference RPAR!;
// WHERE stuff
-where_clause: 'WHERE'^ search_condition;
+where_clause: WHERE^ search_condition;
// Rewritten from the spec to avoid left-recursion
search_condition:
- boolean_term ( 'OR'^ boolean_term )*;
+ boolean_term ( OR^ boolean_term )*;
// Rewritten from the spec to avoid left-recursion
boolean_term:
- boolean_factor ( 'AND'^ boolean_factor )*;
+ boolean_factor ( AND^ boolean_factor )*;
boolean_factor:
- 'NOT'^? boolean_test;
+ NOT^? boolean_test;
boolean_test:
predicate
- | '('! search_condition ')'!
+ | LPAR! search_condition RPAR!
;
predicate:
@@ -152,7 +149,7 @@
value_expression comp_op^ literal;
comp_op:
- '=' | '<>' | '<' | '>' | '<=' | '>=';
+ EQ | NEQ | LT | GT | LTEQ | GTEQ;
literal:
SIGNED_NUMERIC_LITERAL
@@ -160,37 +157,39 @@
;
in_predicate:
- column_reference 'NOT'? 'IN'^ '('! in_value_list ')'!;
+ column_reference NOT? IN^ LPAR! in_value_list RPAR!;
in_value_list:
- literal ( ','! literal )*;
+ literal ( COMMA! literal )*;
like_predicate:
- column_reference 'NOT'? 'LIKE'^ CHARACTER_STRING_LITERAL;
+ 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'
+ : column_reference IS^ NOT? NULL
;
quantified_comparison_predicate:
- literal comp_op^ 'ANY' multi_valued_column_reference;
+ literal comp_op^ ANY multi_valued_column_reference;
quantified_in_predicate:
- 'ANY' multi_valued_column_reference 'NOT'? 'IN'^ '('! in_value_list ')'!;
+ ANY multi_valued_column_reference NOT? IN^ LPAR! in_value_list RPAR!;
text_search_predicate:
- 'CONTAINS'^ '('! qualifier? ','! text_search_expression ')'!;
+ CONTAINS^ LPAR! qualifier? COMMA! text_search_expression RPAR!;
folder_predicate:
- ( 'IN_FOLDER' | 'IN_TREE' )^ '(' qualifier? ',' folder_id ')';
+ ( IN_FOLDER | IN_TREE )^ LPAR qualifier? COMMA folder_id RPAR;
order_by_clause:
- 'ORDER BY'^ sort_specification ( ','! sort_specification )*;
+ ORDER BY sort_specification ( COMMA sort_specification )*
+ -> ^(ORDER_BY sort_specification+)
+ ;
sort_specification:
- column_name ( 'ASC' | 'DESC' )?;
+ column_name ( ASC | DESC )?;
correlation_name:
ID;
Modified:
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=789311&r1=789310&r2=789311&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Mon Jun 29 12:53:05 2009
@@ -13,6 +13,7 @@
*
* Authors:
* Stefane Fermigier, Nuxeo
+ * Florent Guillaume, Nuxeo
*/
gunit CmisSql;
@@ -59,9 +60,9 @@
"'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)
+"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"
@@ -92,7 +93,7 @@
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)
+"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.
Modified: incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml?rev=789311&r1=789310&r2=789311&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml Mon Jun 29
12:53:05 2009
@@ -76,6 +76,15 @@
</execution>
</executions>
</plugin>
+ <!-- maven resources plugin 2.3 has the new copy-resources goal -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <filtering>false</filtering>
+ </configuration>
+ </plugin>
</plugins>
</build>