Changeset: f15ffa2ad094 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f15ffa2ad094
Modified Files:
        sql/ChangeLog
        sql/server/sql_parser.y
        sql/server/sql_scan.c
Branch: default
Log Message:

Implemented X'...' '...'... binary string literals.


diffs (111 lines):

diff --git a/sql/ChangeLog b/sql/ChangeLog
--- a/sql/ChangeLog
+++ b/sql/ChangeLog
@@ -2,6 +2,7 @@
 # This file is updated with Maddlog
 
 * Fri Nov 23 2018 Sjoerd Mullender <sjo...@acm.org>
+- Implemented X'...' style binary string literals.
 - Implemented U&'...' Unicode character string literals and
   U&"..." Unicode delimited identifiers, including UESCAPE.  For the
   string literals, you can have U&'...' '...' '...' UESCAPE '...' where
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -393,6 +393,7 @@ int yydebug=1;
        string
        sstring
        ustring
+       blobstring
        type_alias
        varchar
        clob
@@ -592,7 +593,7 @@ int yydebug=1;
        opt_nulls_first_last
        tz
 
-%right <sval> STRING USTRING
+%right <sval> STRING USTRING XSTRING
 %right <sval> X_BODY
 
 /* sql prefixes to avoid name clashes on various architectures */
@@ -5018,6 +5019,23 @@ literal:
                        YYABORT;
                  }
                }
+ |  blobstring
+               { sql_subtype t;
+                 atom *a= 0;
+                 int r;
+
+                 $$ = NULL;
+                 r = sql_find_subtype(&t, "blob", 0, 0);
+                 if (r && (a = atom_general(SA, &t, $1)) != NULL)
+                       $$ = _newAtomNode(a);
+                 if (!$$) {
+                       char *msg = sql_message(SQLSTATE(22M28) "incorrect blob 
%s", $1);
+
+                       yyerror(m, msg);
+                       _DELETE(msg);
+                       YYABORT;
+                 }
+               }
  |  aTYPE string
                { sql_subtype t;
                  atom *a= 0;
@@ -5850,6 +5868,16 @@ ustring:
                }
  ;
 
+blobstring:
+    XSTRING    /* X'<hexit>...' */
+               { $$ = $1; }
+ |  XSTRING sstring
+               { char *s = strconcat($1,$2);
+                 $$ = sa_strdup(SA, s);
+                 _DELETE(s);
+               }
+ ;
+
 sstring:
     STRING
                { $$ = $1; }
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -1147,6 +1147,10 @@ tokenize(mvc * c, int cur)
                            lc->rs->buf[lc->rs->pos + lc->yycur] == '\'') {
                                return scanner_string(c, scanner_getc(lc), 
true);
                        }
+                       if ((cur == 'X' || cur == 'x') &&
+                           lc->rs->buf[lc->rs->pos + lc->yycur] == '\'') {
+                               return scanner_string(c, scanner_getc(lc), 
true);
+                       }
                        if ((cur == 'U' || cur == 'u') &&
                            lc->rs->buf[lc->rs->pos + lc->yycur] == '&' &&
                            (lc->rs->buf[lc->rs->pos + lc->yycur + 1] == '\'' ||
@@ -1238,7 +1242,7 @@ sql_get_next_token(YYSTYPE *yylval, void
        else if (token == STRING) {
                char quote = *yylval->sval;
                char *str = sa_alloc( c->sa, (lc->yycur-lc->yysval-2)*2 + 1 );
-               assert(quote == '"' || quote == '\'' || quote == 'E' || quote 
== 'e' || quote == 'U' || quote == 'u');
+               assert(quote == '"' || quote == '\'' || quote == 'E' || quote 
== 'e' || quote == 'U' || quote == 'u' || quote == 'X' || quote == 'x');
 
                lc->rs->buf[lc->rs->pos + lc->yycur - 1] = 0;
                if (quote == '"') {
@@ -1260,6 +1264,15 @@ sql_get_next_token(YYSTYPE *yylval, void
                        strcpy(str, yylval->sval + 3);
                        token = yylval->sval[2] == '\'' ? USTRING : UIDENT;
                        quote = yylval->sval[2];
+               } else if (quote == 'X' || quote == 'x') {
+                       assert(yylval->sval[1] == '\'');
+                       char *dst = str;
+                       for (char *src = yylval->sval + 2; *src; dst++)
+                               if ((*dst = *src++) == '\'' && *src == '\'')
+                                       src++;
+                       *dst = 0;
+                       quote = '\'';
+                       token = XSTRING;
                } else {
 #if 0
                        char *dst = str;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to