CAMEL-9461: sql-stored: add support for using new lines and whitespace

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f1ff40ab
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f1ff40ab
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f1ff40ab

Branch: refs/heads/master
Commit: f1ff40abe5786ae15d8f433fdac01bb8dd9f7c2b
Parents: 8b3715d
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Feb 19 13:26:52 2016 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Feb 19 13:26:52 2016 +0100

----------------------------------------------------------------------
 .../stored/template/generated/SSPTParser.java   |  22 +--
 .../template/generated/SSPTParserConstants.java |  24 ++-
 .../generated/SSPTParserTokenManager.java       | 155 ++++++++++++-------
 .../sql/stored/template/grammar/sspt.jj         |  14 +-
 .../src/test/resources/sql/selectStored.sql     |   4 +-
 5 files changed, 138 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
index 858b203..066e5f2 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
@@ -17,7 +17,7 @@ public class SSPTParser implements SSPTParserConstants {
     procedureName = jj_consume_token(IDENTIFIER);
     jj_consume_token(1);
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
-    case 5:
+    case 4:
     case NUMBER:
     case IDENTIFIER:
       parameter = Parameter();
@@ -25,14 +25,14 @@ public class SSPTParser implements SSPTParserConstants {
       label_1:
       while (true) {
         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
-        case 2:
+        case SEPARATOR:
           ;
           break;
         default:
           jj_la1[0] = jj_gen;
           break label_1;
         }
-        jj_consume_token(2);
+        jj_consume_token(SEPARATOR);
         parameter = Parameter();
                 template.addParameter(parameter);
       }
@@ -41,7 +41,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1[1] = jj_gen;
       ;
     }
-    jj_consume_token(3);
+    jj_consume_token(2);
     jj_consume_token(0);
    template.setProcedureName(procedureName.toString());
    {if (true) return template;}
@@ -56,7 +56,7 @@ public class SSPTParser implements SSPTParserConstants {
       param = InputParameter();
                                 {if (true) return param;}
       break;
-    case 5:
+    case 4:
       param = OutParameter();
                                                                           {if 
(true) return param;}
       break;
@@ -73,7 +73,7 @@ public class SSPTParser implements SSPTParserConstants {
      String name;
      Token valueSrcToken;
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(4);
+    jj_consume_token(3);
     valueSrcToken = InputParameterSrc();
         int sqlType = ParseHelper.parseSqlType(sqlTypeToken);
         {if (true) return new 
InputParameter(createNextParameterName(),sqlType,valueSrcToken);}
@@ -84,10 +84,10 @@ public class SSPTParser implements SSPTParserConstants {
      Token sqlTypeToken;
      String name;
      String outValueMapKey;
-    jj_consume_token(5);
     jj_consume_token(4);
+    jj_consume_token(3);
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(4);
+    jj_consume_token(3);
     outValueMapKey = OutHeader();
         {if (true) return new 
OutParameter(createNextParameterName(),ParseHelper.parseSqlType(sqlTypeToken),outValueMapKey);}
     throw new Error("Missing return statement in function");
@@ -152,7 +152,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1_init_0();
    }
    private static void jj_la1_init_0() {
-      jj_la1_0 = new int[] {0x4,0x1060,0x1060,0x1040,0xc00,};
+      jj_la1_0 = new int[] {0x800,0x4030,0x4030,0x4020,0x3000,};
    }
 
   /** Constructor with InputStream. */
@@ -269,7 +269,7 @@ public class SSPTParser implements SSPTParserConstants {
   /** Generate ParseException. */
   public ParseException generateParseException() {
     jj_expentries.clear();
-    boolean[] la1tokens = new boolean[13];
+    boolean[] la1tokens = new boolean[15];
     if (jj_kind >= 0) {
       la1tokens[jj_kind] = true;
       jj_kind = -1;
@@ -283,7 +283,7 @@ public class SSPTParser implements SSPTParserConstants {
         }
       }
     }
-    for (int i = 0; i < 13; i++) {
+    for (int i = 0; i < 15; i++) {
       if (la1tokens[i]) {
         jj_expentry = new int[1];
         jj_expentry[0] = i;

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
index 0b66a49..dc48177 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
@@ -11,19 +11,25 @@ public interface SSPTParserConstants {
   /** End of File. */
   int EOF = 0;
   /** RegularExpression Id. */
-  int NUMBER = 6;
+  int NUMBER = 5;
   /** RegularExpression Id. */
-  int DIGIT = 7;
+  int DIGIT = 6;
   /** RegularExpression Id. */
-  int LETTER = 8;
+  int LETTER = 7;
   /** RegularExpression Id. */
-  int SPECIAL = 9;
+  int SPECIAL = 8;
   /** RegularExpression Id. */
-  int SIMPLE_EXP_TOKEN = 10;
+  int WHITESPACE = 9;
   /** RegularExpression Id. */
-  int PARAMETER_POS_TOKEN = 11;
+  int COMMA = 10;
   /** RegularExpression Id. */
-  int IDENTIFIER = 12;
+  int SEPARATOR = 11;
+  /** RegularExpression Id. */
+  int SIMPLE_EXP_TOKEN = 12;
+  /** RegularExpression Id. */
+  int PARAMETER_POS_TOKEN = 13;
+  /** RegularExpression Id. */
+  int IDENTIFIER = 14;
 
   /** Lexical state. */
   int DEFAULT = 0;
@@ -32,7 +38,6 @@ public interface SSPTParserConstants {
   String[] tokenImage = {
     "<EOF>",
     "\"(\"",
-    "\",\"",
     "\")\"",
     "\" \"",
     "\"OUT\"",
@@ -40,6 +45,9 @@ public interface SSPTParserConstants {
     "<DIGIT>",
     "<LETTER>",
     "<SPECIAL>",
+    "<WHITESPACE>",
+    "\",\"",
+    "<SEPARATOR>",
     "<SIMPLE_EXP_TOKEN>",
     "<PARAMETER_POS_TOKEN>",
     "<IDENTIFIER>",

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
index 1dd57a1..9d27a69 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
@@ -15,18 +15,20 @@ private final int jjStopStringLiteralDfa_0(int pos, long 
active0)
    switch (pos)
    {
       case 0:
-         if ((active0 & 0x20L) != 0L)
+         if ((active0 & 0x10L) != 0L)
          {
-            jjmatchedKind = 12;
-            return 8;
+            jjmatchedKind = 14;
+            return 11;
          }
+         if ((active0 & 0x8L) != 0L)
+            return 12;
          return -1;
       case 1:
-         if ((active0 & 0x20L) != 0L)
+         if ((active0 & 0x10L) != 0L)
          {
-            jjmatchedKind = 12;
+            jjmatchedKind = 14;
             jjmatchedPos = 1;
-            return 8;
+            return 11;
          }
          return -1;
       default :
@@ -48,17 +50,15 @@ private int jjMoveStringLiteralDfa0_0()
    switch(curChar)
    {
       case 32:
-         return jjStopAtPos(0, 4);
+         return jjStartNfaWithStates_0(0, 3, 12);
       case 40:
          return jjStopAtPos(0, 1);
       case 41:
-         return jjStopAtPos(0, 3);
-      case 44:
          return jjStopAtPos(0, 2);
       case 79:
-         return jjMoveStringLiteralDfa1_0(0x20L);
+         return jjMoveStringLiteralDfa1_0(0x10L);
       default :
-         return jjMoveNfa_0(4, 0);
+         return jjMoveNfa_0(7, 0);
    }
 }
 private int jjMoveStringLiteralDfa1_0(long active0)
@@ -71,7 +71,7 @@ private int jjMoveStringLiteralDfa1_0(long active0)
    switch(curChar)
    {
       case 85:
-         return jjMoveStringLiteralDfa2_0(active0, 0x20L);
+         return jjMoveStringLiteralDfa2_0(active0, 0x10L);
       default :
          break;
    }
@@ -89,8 +89,8 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0)
    switch(curChar)
    {
       case 84:
-         if ((active0 & 0x20L) != 0L)
-            return jjStartNfaWithStates_0(2, 5, 8);
+         if ((active0 & 0x10L) != 0L)
+            return jjStartNfaWithStates_0(2, 4, 11);
          break;
       default :
          break;
@@ -108,7 +108,7 @@ private int jjStartNfaWithStates_0(int pos, int kind, int 
state)
 private int jjMoveNfa_0(int startState, int curPos)
 {
    int startsAt = 0;
-   jjnewStateCnt = 9;
+   jjnewStateCnt = 12;
    int i = 1;
    jjstateSet[0] = startState;
    int kind = 0x7fffffff;
@@ -123,56 +123,91 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 4:
+               case 7:
                   if ((0x3ff609c00000000L & l) != 0L)
                   {
-                     if (kind > 12)
-                        kind = 12;
-                     jjCheckNAdd(8);
+                     if (kind > 14)
+                        kind = 14;
+                     jjCheckNAdd(11);
                   }
+                  else if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
                   else if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 5;
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  else if (curChar == 44)
+                  {
+                     if (kind > 11)
+                        kind = 11;
+                     jjCheckNAdd(3);
+                  }
                   if ((0x3ff000000000000L & l) != 0L)
                   {
-                     if (kind > 6)
-                        kind = 6;
+                     if (kind > 5)
+                        kind = 5;
                      jjCheckNAdd(0);
                   }
                   else if (curChar == 36)
-                     jjstateSet[jjnewStateCnt++] = 1;
+                     jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 12:
+                  if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  else if (curChar == 44)
+                  {
+                     if (kind > 11)
+                        kind = 11;
+                     jjCheckNAdd(3);
+                  }
                   break;
                case 0:
                   if ((0x3ff000000000000L & l) == 0L)
                      break;
-                  if (kind > 6)
-                     kind = 6;
+                  if (kind > 5)
+                     kind = 5;
                   jjCheckNAdd(0);
                   break;
+               case 1:
+                  if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
                case 2:
+                  if (curChar != 44)
+                     break;
+                  kind = 11;
+                  jjCheckNAdd(3);
+                  break;
+               case 3:
+                  if ((0x100000600L & l) == 0L)
+                     break;
+                  if (kind > 11)
+                     kind = 11;
+                  jjCheckNAdd(3);
+                  break;
+               case 5:
                   if ((0x3ff609d00000000L & l) != 0L)
                      jjAddStates(0, 1);
                   break;
-               case 5:
+               case 8:
                   if (curChar == 35)
-                     jjCheckNAdd(6);
+                     jjCheckNAdd(9);
                   break;
-               case 6:
+               case 9:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
-                  if (kind > 11)
-                     kind = 11;
-                  jjCheckNAdd(6);
+                  if (kind > 13)
+                     kind = 13;
+                  jjCheckNAdd(9);
                   break;
-               case 7:
+               case 10:
                   if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 5;
+                     jjstateSet[jjnewStateCnt++] = 8;
                   break;
-               case 8:
+               case 11:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
-                  if (kind > 12)
-                     kind = 12;
-                  jjCheckNAdd(8);
+                  if (kind > 14)
+                     kind = 14;
+                  jjCheckNAdd(11);
                   break;
                default : break;
             }
@@ -185,32 +220,32 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 4:
-               case 8:
+               case 7:
+               case 11:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
-                  if (kind > 12)
-                     kind = 12;
-                  jjCheckNAdd(8);
+                  if (kind > 14)
+                     kind = 14;
+                  jjCheckNAdd(11);
                   break;
-               case 1:
+               case 4:
                   if (curChar == 123)
-                     jjCheckNAdd(2);
+                     jjCheckNAdd(5);
                   break;
-               case 2:
+               case 5:
                   if ((0x2ffffffe87fffffeL & l) != 0L)
-                     jjCheckNAddTwoStates(2, 3);
-                  break;
-               case 3:
-                  if (curChar == 125 && kind > 10)
-                     kind = 10;
+                     jjCheckNAddTwoStates(5, 6);
                   break;
                case 6:
+                  if (curChar == 125 && kind > 12)
+                     kind = 12;
+                  break;
+               case 9:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
-                  if (kind > 11)
-                     kind = 11;
-                  jjstateSet[jjnewStateCnt++] = 6;
+                  if (kind > 13)
+                     kind = 13;
+                  jjstateSet[jjnewStateCnt++] = 9;
                   break;
                default : break;
             }
@@ -235,28 +270,28 @@ private int jjMoveNfa_0(int startState, int curPos)
          kind = 0x7fffffff;
       }
       ++curPos;
-      if ((i = jjnewStateCnt) == (startsAt = 9 - (jjnewStateCnt = startsAt)))
+      if ((i = jjnewStateCnt) == (startsAt = 12 - (jjnewStateCnt = startsAt)))
          return curPos;
       try { curChar = input_stream.readChar(); }
       catch(java.io.IOException e) { return curPos; }
    }
 }
 static final int[] jjnextStates = {
-   2, 3, 
+   5, 6, 
 };
 
 /** Token literal values. */
 public static final String[] jjstrLiteralImages = {
-"", "\50", "\54", "\51", "\40", "\117\125\124", null, null, null, null, null, 
-null, null, };
+"", "\50", "\51", "\40", "\117\125\124", null, null, null, null, null, null, 
+null, null, null, null, };
 
 /** Lexer state names. */
 public static final String[] lexStateNames = {
    "DEFAULT",
 };
 protected SimpleCharStream input_stream;
-private final int[] jjrounds = new int[9];
-private final int[] jjstateSet = new int[18];
+private final int[] jjrounds = new int[12];
+private final int[] jjstateSet = new int[24];
 protected char curChar;
 /** Constructor. */
 public SSPTParserTokenManager(SimpleCharStream stream){
@@ -283,7 +318,7 @@ private void ReInitRounds()
 {
    int i;
    jjround = 0x80000001;
-   for (i = 9; i-- > 0;)
+   for (i = 12; i-- > 0;)
       jjrounds[i] = 0x80000000;
 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
----------------------------------------------------------------------
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
index 0b3a295..da7af35 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
@@ -45,7 +45,7 @@ public Template parse() :
     Object parameter = null;
 }
 {
-  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { 
template.addParameter(parameter);}) (","
+  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { 
template.addParameter(parameter);}) (<SEPARATOR>
   parameter
   = Parameter(){template.addParameter(parameter);})*)? ")" <EOF>)
   {
@@ -146,6 +146,18 @@ TOKEN: {
     <#SPECIAL: (["#","_","-","'",".","$","{","}","\""])>
 }
 
+TOKEN: {
+    <#WHITESPACE: (" "|"\n"|"\t")>
+}
+
+TOKEN: {
+    <#COMMA: ",">
+}
+
+TOKEN: {
+    <SEPARATOR: ( ( <WHITESPACE> )* (<COMMA>) ( <WHITESPACE> )* )>
+}
+
 TOKEN : {
     <SIMPLE_EXP_TOKEN: "${"(<LETTER>|<DIGIT> | <SPECIAL> | " ")+ "}">
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/test/resources/sql/selectStored.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/selectStored.sql 
b/components/camel-sql/src/test/resources/sql/selectStored.sql
index ba6c39c..f881aa1 100644
--- a/components/camel-sql/src/test/resources/sql/selectStored.sql
+++ b/components/camel-sql/src/test/resources/sql/selectStored.sql
@@ -1 +1,3 @@
-SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers.num2},OUT INTEGER 
resultofsub)
\ No newline at end of file
+SUBNUMBERS(INTEGER ${headers.num1},
+  INTEGER ${headers.num2},
+  OUT INTEGER resultofsub)
\ No newline at end of file

Reply via email to