[hibernate-commits] Hibernate SVN: r18795 - core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sat Feb 13 16:13:45 EST 2010


Author: steve.ebersole at jboss.com
Date: 2010-02-13 16:13:44 -0500 (Sat, 13 Feb 2010)
New Revision: 18795

Modified:
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g
Log:
Initial working versions of order-by processing using antlr3+stringtemplate

Modified: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g	2010-02-12 17:22:48 UTC (rev 18794)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g	2010-02-13 21:13:44 UTC (rev 18795)
@@ -43,6 +43,12 @@
 }
 
 @parser::members {
+	private Stack flattenTuples = new Stack();
+
+    protected void prepareFlattenTuplesStack() {
+        flattenTuples.push( Boolean.FALSE );
+    }
+
     /**
      * A check to see if the text represents a known function name (in addition to the
      * set of known {@link #standardFunction "standard"} functions.  This is only needed in the
@@ -99,6 +105,10 @@
 		Token token = input.LT(offset);
 		return token == null ? null : token.getText();
 	}
+
+    public Boolean shouldFlattenTuplesInOrderBy() {
+        return Boolean.TRUE;
+    }
 }
 
 
@@ -109,7 +119,16 @@
  * Main recognition rule for this grammar
  */
 orderByFragment
-    : sortSpecification ( COMMA sortSpecification )*
+ at init {
+    if ( state.backtracking == 0 ) {
+        flattenTuples.push( shouldFlattenTuplesInOrderBy() );
+    }
+}
+ at after {
+    if ( state.backtracking == 0 ) {
+        flattenTuples.pop();
+    }
+} : sortSpecification ( COMMA sortSpecification )*
         -> ^( ORDER_BY sortSpecification+ )
     ;
 
@@ -117,10 +136,13 @@
 /**
  * Reconition rule for what ANSI SQL terms the <tt>sort specification</tt>.  These are the atomic elements of the
  * <tt>ORDER BY</tt> list pieces.
+ * </p>
+ * IMPL NOTE : The '+' on the outside of the ^( SORT_SPEC ... ) rewrite forces a duplication of the root, one
+ *    for each child return from
  */
 sortSpecification
     : sortKey collationSpecification? orderingSpecification?
-        -> ^( SORT_SPEC sortKey collationSpecification? orderingSpecification? )
+        -> ^( SORT_SPEC sortKey collationSpecification? orderingSpecification? )+
     ;
 
 
@@ -136,7 +158,17 @@
  * Reconition rule what this grammar recognizes as valid <tt>sort key</tt>.
  */
 expression
-    : QUOTED_IDENTIFIER -> ^( COLUMN ALIAS_REF[Template.TEMPLATE] QUOTED_IDENTIFIER[$QUOTED_IDENTIFIER] )
+ at init {
+    if ( state.backtracking == 0 ) {
+        enableParameterUsage.push(Boolean.TRUE);
+    }
+}
+ at after {
+    if ( state.backtracking == 0 ) {
+        enableParameterUsage.pop();
+    }
+}
+   : QUOTED_IDENTIFIER -> ^( COLUMN ALIAS_REF[Template.TEMPLATE] QUOTED_IDENTIFIER[$QUOTED_IDENTIFIER] )
     // we treat the so-called standard functions differently because they are handled differently by the HQL lexer which we also use here...
     | standardFunction
     | literal



More information about the hibernate-commits mailing list