[NO ISSUE][COMP] Handle keywords in statement parameters

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Allow keywords to be used without backquotes
  in statement parameter names

Change-Id: Id30113fe6ee9ca8c1e92e6e1e8ad85b2a845721c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/9224
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.3.query.sqlpp
new file mode 100644
index 0000000..daf38c9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.3.query.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/*
+ * Description  : Test named statement parameters that have the same name as keywords (json encoded request)
+ * Expected Res : Success
+ * Date         : Dec 2020
+ */
+
+// requesttype=application/json
+
+// param $from:json="from"
+// param $select:json="select"
+
+{
+  "t1": {
+    "from": $from,
+    "select": $`select`
+  },
+
+  "t2": {
+    "from_type": is_string($from),
+    "select_type": is_string($`select`)
+  },
+
+  "t3": [ $from, $`select` ]
+}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.4.query.sqlpp
new file mode 100644
index 0000000..b769d89
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_01/named_01.4.query.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/*
+ * Description  : Test named statement parameters that have the same name as keywords (url encoded request)
+ * Expected Res : Success
+ * Date         : Dec 2020
+ */
+
+// requesttype=application/x-www-form-urlencoded
+
+// param $from:json="from"
+// param $select:json="select"
+
+{
+  "t1": {
+    "from": $from,
+    "select": $`select`
+  },
+
+  "t2": {
+    "from_type": is_string($from),
+    "select_type": is_string($`select`)
+  },
+
+  "t3": [ $from, $`select` ]
+}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.3.adm
new file mode 100644
index 0000000..f7dce44
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.3.adm
@@ -0,0 +1 @@
+{ "t1": { "from": "from", "select": "select" }, "t2": { "from_type": true, "select_type": true }, "t3": [ "from", "select" ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.4.adm
new file mode 100644
index 0000000..f7dce44
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_01/named_01.4.adm
@@ -0,0 +1 @@
+{ "t1": { "from": "from", "select": "select" }, "t2": { "from_type": true, "select_type": true }, "t3": [ "from", "select" ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index c9a7370..56f94ef 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -3403,18 +3403,10 @@
 }
 {
   (
-    (
-      <DOLLAR>
-      (
-        <INTEGER_LITERAL> { name = token.image; } |
-        <IDENTIFIER> { name = token.image; } |
-        name = QuotedString()
-      )
-    )
-    |
-    (
-      <QUES> { name = String.valueOf(++externalVarCounter); }
-    )
+      <DOLLAR_IDENTIFIER> { name = token.image.substring(1); }
+    | <DOLLAR_INTEGER_LITERAL> { name = token.image.substring(1); }
+    | <DOLLAR_QUOTED_STRING> { name = removeQuotesAndEscapes(token.image.substring(1)); }
+    | <QUES> { name = String.valueOf(++externalVarCounter); }
   )
   {
      String idName = SqlppVariableUtil.toExternalVariableName(name);
@@ -4634,6 +4626,7 @@
   | <EXCEPT : "except">
   | <EXISTS : "exists">
   | <EXTERNAL : "external">
+  | <FALSE : "false">
   | <FEED : "feed">
   | <FILTER : "filter">
   | <FLATTEN : "flatten">
@@ -4665,10 +4658,12 @@
   | <LIKE : "like">
   | <LIMIT : "limit">
   | <LOAD : "load">
+  | <MISSING : "missing">
   | <MOD : "mod">
   | <NODEGROUP : "nodegroup">
   | <NGRAM : "ngram">
   | <NOT : "not">
+  | <NULL : "null">
   | <OFFSET : "offset">
   | <ON : "on">
   | <OPEN : "open">
@@ -4698,8 +4693,9 @@
   | <SYNONYM : "synonym">
   | <TEMPORARY : "temporary"> // intentionally not used but reserved for future usage
   | <THEN : "then">
-  | <TYPE : "type">
   | <TO : "to">
+  | <TRUE : "true">
+  | <TYPE : "type">
   | <UNION : "union">
   | <UNKNOWN : "unknown">
   | <UNNEST : "unnest">
@@ -4733,7 +4729,6 @@
   | <ATT : "@">
   | <COLON : ":">
   | <COMMA : ",">
-  | <DOLLAR: "$">
   | <DOT : ".">
   | <PERCENT: "%">
   | <QUES : "?">
@@ -4777,44 +4772,33 @@
 <DEFAULT,IN_DBL_BRACE>
 TOKEN :
 {
-    <INTEGER_LITERAL : (<DIGIT>)+ >
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN [IGNORE_CASE]:
-{
-    <MISSING : "missing">
-  | <NULL : "null">
-  | <TRUE : "true">
-  | <FALSE : "false">
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
     <#DIGIT : ["0" - "9"]>
 }
 
 <DEFAULT,IN_DBL_BRACE>
 TOKEN:
 {
-    < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("+"|"-")? <DIGITS>)?
+    <INTEGER_LITERAL : <DIGITS> >
+  | <DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("+"|"-")? <DIGITS>)?
                       | <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)
                       | "." <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)?
     >
-  | < FLOAT_LITERAL:  <DIGITS> ( "f" | "F" )
+  | <FLOAT_LITERAL:  <DIGITS> ( "f" | "F" )
                       | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
                       | "." <DIGITS> ( "f" | "F" )
     >
-  | <DIGITS : (<DIGIT>)+ >
+  | <#DIGITS : (<DIGIT>)+ >
 }
 
 <DEFAULT,IN_DBL_BRACE>
 TOKEN :
 {
     <#LETTER : ["A" - "Z", "a" - "z"]>
-  | <#IDENTIFIER_SPECIALCHARS_START : ["_"]>
-  | <#IDENTIFIER_SPECIALCHARS_REST : ["$"]>
+  | <#IDENTIFIER_START_SPECIALCHAR : ["_"]>
+  | <#IDENTIFIER_REST_SPECIALCHAR : ["$"]>
+  | <#IDENTIFIER_START : <LETTER> | <IDENTIFIER_START_SPECIALCHAR> >
+  | <#IDENTIFIER_REST  : <LETTER> | <DIGIT> | <IDENTIFIER_START_SPECIALCHAR> | <IDENTIFIER_REST_SPECIALCHAR> >
+  | <IDENTIFIER : <IDENTIFIER_START> (<IDENTIFIER_REST>)* >
 }
 
 <DEFAULT,IN_DBL_BRACE>
@@ -4865,8 +4849,9 @@
 <DEFAULT,IN_DBL_BRACE>
 TOKEN :
 {
-    <IDENTIFIER : ( <LETTER> | <IDENTIFIER_SPECIALCHARS_START> )
-                  ( <LETTER> | <DIGIT> | <IDENTIFIER_SPECIALCHARS_START> | <IDENTIFIER_SPECIALCHARS_REST> )*>
+    <DOLLAR_INTEGER_LITERAL : "$" <INTEGER_LITERAL> >
+  | <DOLLAR_IDENTIFIER : "$" <IDENTIFIER> >
+  | <DOLLAR_QUOTED_STRING: "$" <QUOTED_STRING> >
 }
 
 <DEFAULT,IN_DBL_BRACE>