Changeset: 52faef40c2e9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=52faef40c2e9
Modified Files:
        sql/server/sql_scan.c
        sql/test/pg_regress/Tests/comments.stable.err
        sql/test/pg_regress/Tests/comments.stable.out
Branch: Dec2016
Log Message:

Block comments can nest.
See ISO 9075 Part 2, Foundation, Section 5.2.


diffs (95 lines):

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
@@ -821,15 +821,20 @@ skip_c_comment(struct scanner * lc)
        int cur;
        int prev = 0;
        int started = lc->started;
+       int depth = 1;
 
        lc->started = 1;
-       while ((cur = scanner_getc(lc)) != EOF && 
-              !(cur == '/' && prev == '*')) 
+       while ((cur = scanner_getc(lc)) != EOF && depth > 0) {
+               if (prev == '*' && cur == '/')
+                       depth--;
+               else if (prev == '/' && cur == '*') {
+                       cur = 0; /* prevent slash-star-slash from matching */
+                       depth++;
+               }
                prev = cur;
+       }
        lc->yysval = lc->yycur;
        lc->started = started;
-       if (cur == '/')
-               cur = scanner_getc(lc);
        return cur;
 }
 
diff --git a/sql/test/pg_regress/Tests/comments.stable.err 
b/sql/test/pg_regress/Tests/comments.stable.err
--- a/sql/test/pg_regress/Tests/comments.stable.err
+++ b/sql/test/pg_regress/Tests/comments.stable.err
@@ -30,31 +30,8 @@ stderr of test 'comments` in directory '
 # 17:48:13 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-5017" "--port=30983"
 # 17:48:13 >  
 
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = /* This block comment surrounds a query which itself has a block 
comment...
-        SELECT /* embedded single line */ 'embedded' AS x2;
-ERROR = !syntax error, unexpected STRING in: "/* This block comment surrounds 
a query which itself has a block comment...
-        !SELE"
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = */
         
-        SELECT -- continued after the following block comments...
-        /* Deeply nested comment.
-           This includes a single apostrophe to make sure we aren't decoding 
this part as a string.
-        SELECT 'deep nest' AS n1;
-        /* Second level of nesting...
-        SELECT 'deeper nest' as n2;
-        /* Third level of nesting...
-        SELECT 'deepest nest' as n3;
-        */
-        Hoo boy. Still two deep...
-        */
-        Now just one deep...
-        */
-        'deeply nested example' AS sixth;
-ERROR = !syntax error, unexpected '*' in: "*"
+# 15:42:49 >  
+# 15:42:49 >  "Done."
+# 15:42:49 >  
 
-# 17:48:13 >  
-# 17:48:13 >  "Done."
-# 17:48:13 >  
-
diff --git a/sql/test/pg_regress/Tests/comments.stable.out 
b/sql/test/pg_regress/Tests/comments.stable.out
--- a/sql/test/pg_regress/Tests/comments.stable.out
+++ b/sql/test/pg_regress/Tests/comments.stable.out
@@ -58,6 +58,25 @@ Ready.
 % char # type
 % 16 # length
 [ "after multi-line" ]
+#SELECT -- continued after the following block comments...
+#/* Deeply nested comment.
+#   This includes a single apostrophe to make sure we aren't decoding this 
part as a string.
+#SELECT 'deep nest' AS n1;
+#/* Second level of nesting...
+#SELECT 'deeper nest' as n2;
+#/* Third level of nesting...
+#SELECT 'deepest nest' as n3;
+#*/
+#Hoo boy. Still two deep...
+#*/
+#Now just one deep...
+#*/
+#'deeply nested example' AS sixth;
+% .L2 # table_name
+% sixth # name
+% char # type
+% 21 # length
+[ "deeply nested example"      ]
 
 # 16:12:37 >  
 # 16:12:37 >  "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to