emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/sql-indent 1bb06f8 5/9: Fix detection of DECLARE blocks


From: Alex Harsanyi
Subject: [elpa] externals/sql-indent 1bb06f8 5/9: Fix detection of DECLARE blocks in PostgresSQL (#92)
Date: Fri, 20 Mar 2020 19:08:02 -0400 (EDT)

branch: externals/sql-indent
commit 1bb06f8d11188c3954bd1fb928e2084890397806
Author: Alex Harsanyi <address@hidden>
Commit: Alex Harsanyi <address@hidden>

    Fix detection of DECLARE blocks in PostgresSQL (#92)
    
    In PostgresSQL, the DECLARE keyword might begin a block of declarations, or
    declare a single cursor.  Updated the syntax scanning code to only consider
    DECLARE a block start when it is part of a program block.
    
    This change will alter how PostgresSQL blocks are indented, hopefully for 
the
    better.
    
    Added tests for the relevant cases, and updated existing test cases which 
also
    incorrectly detected DECLARE statements.
---
 sql-indent-test.el      |  10 +
 sql-indent.el           |  70 +++-
 test-data/pr67-syn.eld  | 823 +++++++++++++++++++++++++-----------------------
 test-data/pr67.sql      | 421 +++++++++++++------------
 test-data/pr88-syn.eld  |  31 +-
 test-data/pr89-syn.eld  |  12 +-
 test-data/pr92-syn.eld  |  54 ++++
 test-data/pr92.sql      |  29 ++
 test-data/pr92a-syn.eld |  13 +
 test-data/pr92a.sql     |   9 +
 10 files changed, 826 insertions(+), 646 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 07d79d3..d9752c9 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -442,4 +442,14 @@ information read from DATA-FILE (as generated by
    "test-data/pr90.sql"
    "test-data/pr90-syn.eld"))
 
+(ert-deftest sqlind-ert-pr92 ()
+  (sqlind-ert-check-file-syntax
+   "test-data/pr92.sql"
+   "test-data/pr92-syn.eld"))
+
+(ert-deftest sqlind-ert-pr92a ()
+  (sqlind-ert-check-file-syntax
+   "test-data/pr92a.sql"
+   "test-data/pr92a-syn.eld"))
+
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 983991d..9f413af 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -282,7 +282,7 @@ determine the statement start in SQLite scripts.")
    (regexp-opt '("use" "go" "declare") t)
    "\\)\\b")
   "Match an MS SQL Sever directive at the beginning of a line.")
-  
+
 (defun sqlind-beginning-of-directive ()
   "Return the position of an SQL directive, or nil.
 We will never move past one of these in our scan.  We also assume
@@ -309,7 +309,7 @@ But don't go before LIMIT."
     (catch 'done
       (while (> (point) (or limit (point-min)))
         (when (re-search-backward
-               
";\\|:=\\|\\_<\\(declare\\|begin\\|cursor\\|for\\|while\\|loop\\|if\\|then\\|else\\|elsif\\|elseif\\)\\_>\\|)"
+               
";\\|:=\\|\\_<\\(declare\\|begin\\|cursor\\|for\\|while\\|loop\\|if\\|then\\|else\\|elsif\\|elseif\\)\\_>\\|)\\|\\$\\$"
                limit 'noerror)
           (unless (sqlind-in-comment-or-string (point))
             (let ((candidate-pos (match-end 0)))
@@ -318,9 +318,14 @@ But don't go before LIMIT."
                      ;; of the keywords inside one of them and think this is a
                      ;; statement start.
                      (progn (forward-char 1) (forward-sexp -1)))
-                    ((looking-at "cursor\\|for\\|while")
-                     ;; statement begins at the start of the keyword
+                    ((looking-at "cursor\\|for")
+                     (unless (eq sql-product 'postgres)
+                       (throw 'done (point))))
+                    ((looking-at "while")
                      (throw 'done (point)))
+                    ((looking-at "declare")
+                     (when (eq sql-product 'postgres)
+                       (throw 'done (point))))
                     ((looking-at "else?if")
                      ;; statement begins at the start of the keyword
                      (throw 'done (point)))
@@ -340,6 +345,10 @@ But don't go before LIMIT."
                      (sqlind-backward-syntactic-ws)
                      (forward-sexp -1)
                      (throw 'done (point)))
+                    ((looking-at "\\$\\$")
+                     (when (eq sql-product 'postgres)
+                       (sqlind-forward-syntactic-ws)
+                       (throw 'done (point))))
                     ((sqlind-looking-at-begin-transaction)
                      ;; This is a "begin transaction" call, statement begins
                      ;; at "begin", see #66
@@ -634,11 +643,20 @@ expressions, also we don't match DECLARE directives here.
 
 See also `sqlind-beginning-of-block'"
   (when (looking-at "declare")
-    ;; a declare block is always toplevel, if it is not, its an error
-    (throw 'finished
-      (if (null sqlind-end-stmt-stack)
-         'declare-statement
-        (list 'syntax-error "nested declare block" (point) (point))))))
+
+    ;; In Postgres, a DECLARE statement can be a block, or define a cursor
+    ;; (see pr67.sql, pr92.sql for examples).  It is somewhat tricky to
+    ;; determine which is which, so we use the heuristic that a declare
+    ;; statement immediately following a $$ is a block, otherwise it is not.
+    (when (or (not (eq sql-product 'postgres))
+              (save-excursion
+                (sqlind-backward-syntactic-ws)
+                (skip-syntax-backward "_") ; note that the $$ is symbol 
constitent!
+                (looking-at "\\$\\$")))
+      (throw 'finished
+        (if (null sqlind-end-stmt-stack)
+            'declare-statement
+          (list 'syntax-error "nested declare block" (point) (point)))))))
 
 (defun sqlind-maybe-skip-create-options ()
   "Move point past any MySQL option declarations.
@@ -939,7 +957,7 @@ reverse order (a stack) and is used to skip over nested 
blocks."
   ;;
   ;; Some of these `sqlind-maybe-*` functions are specific to the
   ;; `sql-product` and are only invoked for the speficied SQL dialect.
-  
+
   (catch 'finished
     (let ((sqlind-end-stmt-stack end-statement-stack))
       (while (re-search-backward sqlind-start-block-regexp sqlind-search-limit 
'noerror)
@@ -953,7 +971,8 @@ reverse order (a stack) and is used to skip over nested 
blocks."
             (sqlind-maybe-else-statement)
             (sqlind-maybe-loop-statement)
             (sqlind-maybe-begin-statement)
-            (when (eq sql-product 'oracle) ; declare statements only start 
blocks in PL/SQL
+            (when (memq sql-product '(oracle postgres))
+              ;; declare statements only start blocks in PL/SQL and PostgresSQL
               (sqlind-maybe-declare-statement))
             (when (eq sql-product 'postgres)
               (sqlind-maybe-$$-statement))
@@ -1130,7 +1149,7 @@ statement is found."
                            (sqlind-backward-syntactic-ws)
                           (looking-at ",")))
                 (throw 'finished (cons 'select-table match-pos)))
-               
+
               ;; otherwise, we continue the table definition from the
               ;; previous line.
               (throw 'finished (cons 'select-table-continuation match-pos)))
@@ -1420,7 +1439,7 @@ not a statement-continuation POS is the same as the
   (let ((syntax (sqlind-syntax context))
         (anchor (sqlind-anchor-point context))
         (syntax-symbol (sqlind-syntax-symbol context)))
-    
+
     (goto-char pos)
 
     (cond
@@ -1472,14 +1491,28 @@ not a statement-continuation POS is the same as the
          ;; CURSOR name type IS
          (when (looking-at "cursor\\b")
            (let ((origin (point)))
-             (forward-sexp 3)
+             (forward-sexp 1)           ; skip "cursor"
+             (sqlind-forward-syntactic-ws)
+             (forward-sexp 1)
              (sqlind-forward-syntactic-ws)
-             (when (looking-at "is\\b")
-               (goto-char (match-end 0))
-               (sqlind-forward-syntactic-ws))
+             (if (looking-at "is\\b")
+                 (progn
+                   (goto-char (match-end 0))
+                   (sqlind-forward-syntactic-ws))
+               (forward-sexp 1)
+               (sqlind-forward-syntactic-ws)
+               (when (looking-at "is\\b")
+                 (goto-char (match-end 0))
+                 (sqlind-forward-syntactic-ws)))
              (unless (<= (point) pos)
                (goto-char origin))))
 
+         ;; Skip a PostgreSQL cursor declaration
+         (when (and (eq sql-product 'postgres)
+                    (looking-at 
"\\(\\(declare\\)\\|\\(cursor\\)\\|\\(for\\)\\)\\b"))
+           (when (re-search-forward 
"\\b\\(select\\|update\\|delete\\|insert\\)\\b" pos 'noerror)
+             (goto-char (match-beginning 0))))
+
          ;; skip a forall statement if it is before our point
          (when (looking-at "forall\\b")
            (when (re-search-forward 
"\\b\\(select\\|update\\|delete\\|insert\\)\\b" pos 'noerror)
@@ -1631,6 +1664,9 @@ procedure block."
                        ;; contexts
                        (or (not (looking-at "\\(create\\)\\|\\(alter\\)"))
                            (catch 'finished (sqlind-maybe-create-statement) 
nil))
+                       ;; A declare statement may or may not be a block context
+                       (or (not (looking-at "declare"))
+                           (catch 'finished (sqlind-maybe-declare-statement) 
nil))
                        (not (sqlind-looking-at-begin-transaction))))
           (goto-char pos)
           ;; if we are at the start of a statement, or the nearest statement
diff --git a/test-data/pr67-syn.eld b/test-data/pr67-syn.eld
index 0657beb..26030d1 100644
--- a/test-data/pr67-syn.eld
+++ b/test-data/pr67-syn.eld
@@ -6,518 +6,533 @@
    . 1)
   (toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 79))
- (((in-begin-block toplevel nil)
-   . 79))
- (((in-begin-block toplevel nil)
-   . 79))
- (((in-begin-block nil "")
-   . 129))
- (((in-begin-block nil "")
-   . 129))
+ ((declare-statement . 85))
+ ((declare-statement . 85))
+ (((block-start begin)
+   . 85)
+  (declare-statement . 85))
+ (((in-begin-block toplevel-block "")
+   . 145))
+ (((in-begin-block toplevel-block "")
+   . 145))
  (((in-block if "")
-   . 155))
+   . 179))
  (((in-block if "")
-   . 155))
+   . 179))
  (((block-start elsif)
-   . 155)
+   . 179)
   ((in-block if "")
-   . 155))
- ((select-clause . 231)
-  (nested-statement-continuation . 230)
-  (statement-continuation . 230))
+   . 179))
+ ((select-clause . 267)
+  (nested-statement-continuation . 266)
+  (statement-continuation . 266))
  (((in-block elsif "")
-   . 224))
+   . 260))
  (((in-block elsif "")
-   . 224))
+   . 260))
  (((block-start elsif)
-   . 224)
+   . 260)
   ((in-block elsif "")
-   . 224))
- ((select-clause . 347)
-  (nested-statement-continuation . 346)
-  (statement-continuation . 346))
- ((select-clause . 347)
-  (nested-statement-continuation . 346)
-  (statement-continuation . 346))
+   . 260))
+ ((select-clause . 399)
+  (nested-statement-continuation . 398)
+  (statement-continuation . 398))
+ ((select-clause . 399)
+  (nested-statement-continuation . 398)
+  (statement-continuation . 398))
  (((in-block elsif "")
-   . 340))
+   . 392))
  (((in-block elsif "")
-   . 340))
+   . 392))
  (((block-start elsif)
-   . 340)
+   . 392)
   ((in-block elsif "")
-   . 340))
- ((select-clause . 496)
-  (nested-statement-continuation . 495)
-  (statement-continuation . 495))
- ((select-table-continuation . 526)
-  (nested-statement-continuation . 495)
-  (statement-continuation . 495))
- ((select-table-continuation . 526)
-  (nested-statement-continuation . 495)
-  (statement-continuation . 495))
- ((select-clause . 496)
-  (nested-statement-continuation . 495)
-  (statement-continuation . 495))
- (((in-block elsif "")
-   . 489))
- (((in-block elsif "")
-   . 489))
+   . 392))
+ ((select-clause . 568)
+  (nested-statement-continuation . 567)
+  (statement-continuation . 567))
+ ((select-table-continuation . 602)
+  (nested-statement-continuation . 567)
+  (statement-continuation . 567))
+ ((select-table-continuation . 602)
+  (nested-statement-continuation . 567)
+  (statement-continuation . 567))
+ ((select-clause . 568)
+  (nested-statement-continuation . 567)
+  (statement-continuation . 567))
+ (((in-block elsif "")
+   . 561))
+ (((in-block elsif "")
+   . 561))
  (((block-start else)
-   . 489)
+   . 561)
   ((in-block elsif "")
-   . 489))
+   . 561))
  (((in-block else "")
-   . 698))
- ((statement-continuation . 709))
- ((statement-continuation . 709))
- ((statement-continuation . 709))
- ((statement-continuation . 709))
- ((statement-continuation . 709))
- ((statement-continuation . 709))
+   . 798))
+ ((statement-continuation . 813))
+ ((select-clause . 836)
+  (statement-continuation . 813))
+ ((select-table-continuation . 859)
+  (statement-continuation . 813))
+ ((select-table-continuation . 859)
+  (statement-continuation . 813))
+ ((select-table-continuation . 859)
+  (statement-continuation . 813))
+ ((select-clause . 836)
+  (statement-continuation . 813))
  (((in-block loop "")
-   . 709))
- ((statement-continuation . 877))
- ((statement-continuation . 877))
- ((statement-continuation . 877))
- ((statement-continuation . 877))
+   . 813))
+ ((statement-continuation . 1039))
+ ((statement-continuation . 1039))
+ ((statement-continuation . 1039))
+ ((statement-continuation . 1039))
  (((block-end loop "")
-   . 709)
+   . 813)
   ((in-block loop "")
-   . 709))
+   . 813))
  (((block-end if "")
-   . 155)
+   . 179)
   ((in-block else "")
-   . 698))
- (((block-end nil "")
-   . 129)
-  ((in-begin-block nil "")
-   . 129))
+   . 798))
+ (((block-end toplevel-block "")
+   . 145)
+  ((in-begin-block toplevel-block "")
+   . 145))
  ((toplevel . 1))
  ((toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 1113))
- (((in-begin-block toplevel nil)
-   . 1113))
- (((in-begin-block toplevel nil)
-   . 1113))
- (((in-begin-block toplevel nil)
-   . 1113))
- (((in-begin-block nil "")
-   . 1187))
- (((in-begin-block nil "")
-   . 1187))
- (((in-begin-block nil "")
-   . 1187))
+ ((declare-statement . 1309))
+ ((declare-statement . 1309))
+ ((declare-statement . 1309))
+ (((block-start begin)
+   . 1309)
+  (declare-statement . 1309))
+ (((in-begin-block toplevel-block "")
+   . 1399))
+ (((in-begin-block toplevel-block "")
+   . 1399))
+ (((in-begin-block toplevel-block "")
+   . 1399))
  (((in-block if "")
-   . 1237))
+   . 1461))
  (((in-block if "")
-   . 1237))
+   . 1461))
  (((block-start elsif)
-   . 1237)
+   . 1461)
   ((in-block if "")
-   . 1237))
+   . 1461))
  (((in-block elsif "")
-   . 1306))
+   . 1542))
  (((in-block elsif "")
-   . 1306))
+   . 1542))
  (((block-start elsif)
-   . 1306)
+   . 1542)
   ((in-block elsif "")
-   . 1306))
- ((select-clause . 1388)
-  (nested-statement-continuation . 1387)
-  (statement-continuation . 1387))
- ((select-clause . 1388)
-  (nested-statement-continuation . 1387)
-  (statement-continuation . 1387))
+   . 1542))
+ ((select-clause . 1636)
+  (nested-statement-continuation . 1635)
+  (statement-continuation . 1635))
+ ((select-clause . 1636)
+  (nested-statement-continuation . 1635)
+  (statement-continuation . 1635))
  (((in-select-clause "where")
-   . 1443)
-  (nested-statement-continuation . 1387)
-  (statement-continuation . 1387))
+   . 1699)
+  (nested-statement-continuation . 1635)
+  (statement-continuation . 1635))
  (((in-block elsif "")
-   . 1381))
+   . 1629))
  (((in-block elsif "")
-   . 1381))
+   . 1629))
  (((block-start elsif)
-   . 1381)
+   . 1629)
   ((in-block elsif "")
-   . 1381))
- ((select-clause . 1547)
-  (nested-statement-continuation . 1546)
-  (statement-continuation . 1546))
- ((select-table-continuation . 1577)
-  (nested-statement-continuation . 1546)
-  (statement-continuation . 1546))
- ((select-table-continuation . 1577)
-  (nested-statement-continuation . 1546)
-  (statement-continuation . 1546))
- ((select-clause . 1547)
-  (nested-statement-continuation . 1546)
-  (statement-continuation . 1546))
+   . 1629))
+ ((select-clause . 1819)
+  (nested-statement-continuation . 1818)
+  (statement-continuation . 1818))
+ ((select-table-continuation . 1853)
+  (nested-statement-continuation . 1818)
+  (statement-continuation . 1818))
+ ((select-table-continuation . 1853)
+  (nested-statement-continuation . 1818)
+  (statement-continuation . 1818))
+ ((select-clause . 1819)
+  (nested-statement-continuation . 1818)
+  (statement-continuation . 1818))
  (((in-select-clause "where")
-   . 1681)
-  (nested-statement-continuation . 1546)
-  (statement-continuation . 1546))
+   . 1969)
+  (nested-statement-continuation . 1818)
+  (statement-continuation . 1818))
  (((in-block elsif "")
-   . 1540))
+   . 1812))
  (((in-block elsif "")
-   . 1540))
+   . 1812))
  (((block-start elsif)
-   . 1540)
+   . 1812)
   ((in-block elsif "")
-   . 1540))
- ((select-clause . 1785)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
- ((select-table-continuation . 1815)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
- ((select-table-continuation . 1815)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
- ((select-table-continuation . 1815)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
- ((select-clause . 1785)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
+   . 1812))
+ ((select-clause . 2089)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
+ ((select-table-continuation . 2123)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
+ ((select-table-continuation . 2123)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
+ ((select-table-continuation . 2123)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
+ ((select-clause . 2089)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
  (((in-select-clause "where")
-   . 1959)
-  (nested-statement-continuation . 1784)
-  (statement-continuation . 1784))
+   . 2283)
+  (nested-statement-continuation . 2088)
+  (statement-continuation . 2088))
  (((in-block elsif "")
-   . 1778))
+   . 2082))
  (((in-block elsif "")
-   . 1778))
+   . 2082))
  (((block-start else)
-   . 1778)
+   . 2082)
   ((in-block elsif "")
-   . 1778))
+   . 2082))
  (((in-block else "")
-   . 2057))
- ((statement-continuation . 2068))
- ((statement-continuation . 2068))
- ((statement-continuation . 2068))
- ((statement-continuation . 2068))
- ((statement-continuation . 2068))
- ((statement-continuation . 2068))
+   . 2397))
+ ((select-clause . 2422)
+  (statement-continuation . 2412))
+ ((select-table-continuation . 2453)
+  (statement-continuation . 2412))
+ ((select-table-continuation . 2453)
+  (statement-continuation . 2412))
+ ((select-table-continuation . 2453)
+  (statement-continuation . 2412))
+ ((select-clause . 2422)
+  (statement-continuation . 2412))
+ (((in-select-clause "where")
+   . 2633)
+  (statement-continuation . 2412))
  (((in-block loop "")
-   . 2068))
- ((statement-continuation . 2249))
- ((statement-continuation . 2249))
- ((statement-continuation . 2249))
- ((statement-continuation . 2249))
+   . 2412))
+ ((statement-continuation . 2702))
+ ((statement-continuation . 2702))
+ ((statement-continuation . 2702))
+ ((statement-continuation . 2702))
  (((block-end loop "")
-   . 2068)
+   . 2412)
   ((in-block loop "")
-   . 2068))
+   . 2412))
  (((block-end if "")
-   . 1237)
+   . 1461)
   ((in-block else "")
-   . 2057))
- (((block-end nil "")
-   . 1187)
-  ((in-begin-block nil "")
-   . 1187))
+   . 2397))
+ (((block-end toplevel-block "")
+   . 1399)
+  ((in-begin-block toplevel-block "")
+   . 1399))
  ((toplevel . 1))
  ((toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 2479))
- (((in-begin-block toplevel nil)
-   . 2479))
- (((in-begin-block toplevel nil)
-   . 2479))
- (((in-begin-block nil "")
-   . 2529))
- (((in-begin-block nil "")
-   . 2529))
+ ((declare-statement . 2966))
+ ((declare-statement . 2966))
+ (((block-start begin)
+   . 2966)
+  (declare-statement . 2966))
+ (((in-begin-block toplevel-block "")
+   . 3026))
+ (((in-begin-block toplevel-block "")
+   . 3026))
  (((in-block if "")
-   . 2556))
+   . 3061))
  (((in-block if "")
-   . 2556))
+   . 3061))
  (((block-start elsif)
-   . 2556)
+   . 3061)
   ((in-block if "")
-   . 2556))
- ((select-clause . 2633)
-  (nested-statement-continuation . 2632)
-  (statement-continuation . 2632))
+   . 3061))
+ ((select-clause . 3150)
+  (nested-statement-continuation . 3149)
+  (statement-continuation . 3149))
  (((in-block elsif "")
-   . 2626))
+   . 3143))
  (((in-block elsif "")
-   . 2626))
+   . 3143))
  (((block-start elsif)
-   . 2626)
+   . 3143)
   ((in-block elsif "")
-   . 2626))
- ((select-clause . 2750)
-  (nested-statement-continuation . 2749)
-  (statement-continuation . 2749))
- ((select-table-continuation . 2780)
-  (nested-statement-continuation . 2749)
-  (statement-continuation . 2749))
- ((select-clause . 2750)
-  (nested-statement-continuation . 2749)
-  (statement-continuation . 2749))
- (((in-block elsif "")
-   . 2743))
- (((in-block elsif "")
-   . 2743))
+   . 3143))
+ ((select-clause . 3283)
+  (nested-statement-continuation . 3282)
+  (statement-continuation . 3282))
+ ((select-table-continuation . 3317)
+  (nested-statement-continuation . 3282)
+  (statement-continuation . 3282))
+ ((select-clause . 3283)
+  (nested-statement-continuation . 3282)
+  (statement-continuation . 3282))
+ (((in-block elsif "")
+   . 3276))
+ (((in-block elsif "")
+   . 3276))
  (((block-start else)
-   . 2743)
+   . 3276)
   ((in-block elsif "")
-   . 2743))
+   . 3276))
  (((in-block else "")
-   . 2913))
- ((statement-continuation . 2924))
- ((statement-continuation . 2924))
- ((statement-continuation . 2924))
- ((statement-continuation . 2924))
- ((statement-continuation . 2924))
+   . 3470))
+ ((select-clause . 3495)
+  (statement-continuation . 3485))
+ ((select-table-continuation . 3526)
+  (statement-continuation . 3485))
+ ((select-table-continuation . 3526)
+  (statement-continuation . 3485))
+ ((select-table-continuation . 3526)
+  (statement-continuation . 3485))
+ ((select-clause . 3495)
+  (statement-continuation . 3485))
  (((in-block loop "")
-   . 2924))
- ((statement-continuation . 3082))
- ((statement-continuation . 3082))
- ((statement-continuation . 3082))
- ((statement-continuation . 3082))
+   . 3485))
+ ((statement-continuation . 3737))
+ ((statement-continuation . 3737))
+ ((statement-continuation . 3737))
+ ((statement-continuation . 3737))
  (((block-end loop "")
-   . 2924)
+   . 3485)
   ((in-block loop "")
-   . 2924))
+   . 3485))
  (((block-end if "")
-   . 2556)
+   . 3061)
   ((in-block else "")
-   . 2913))
- (((block-end nil "")
-   . 2529)
-  ((in-begin-block nil "")
-   . 2529))
+   . 3470))
+ (((block-end toplevel-block "")
+   . 3026)
+  ((in-begin-block toplevel-block "")
+   . 3026))
  ((toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 3311))
- (((in-begin-block toplevel nil)
-   . 3311))
- (((in-begin-block toplevel nil)
-   . 3311))
- (((in-begin-block nil "")
-   . 3361))
- (((in-begin-block nil "")
-   . 3361))
+ ((declare-statement . 4000))
+ ((declare-statement . 4000))
+ (((block-start begin)
+   . 4000)
+  (declare-statement . 4000))
+ (((in-begin-block toplevel-block "")
+   . 4060))
+ (((in-begin-block toplevel-block "")
+   . 4060))
  (((in-block if "")
-   . 3395))
+   . 4102))
  (((in-block if "")
-   . 3395))
+   . 4102))
  (((block-start elsif)
-   . 3395)
+   . 4102)
   ((in-block if "")
-   . 3395))
- ((select-clause . 3472)
-  (nested-statement-continuation . 3471)
-  (statement-continuation . 3471))
+   . 4102))
+ ((select-clause . 4191)
+  (nested-statement-continuation . 4190)
+  (statement-continuation . 4190))
  (((in-block elsif "")
-   . 3465))
+   . 4184))
  (((in-block elsif "")
-   . 3465))
+   . 4184))
  (((block-start elsif)
-   . 3465)
+   . 4184)
   ((in-block elsif "")
-   . 3465))
- ((select-clause . 3589)
-  (nested-statement-continuation . 3588)
-  (statement-continuation . 3588))
- ((select-table-continuation . 3619)
-  (nested-statement-continuation . 3588)
-  (statement-continuation . 3588))
- ((select-clause . 3589)
-  (nested-statement-continuation . 3588)
-  (statement-continuation . 3588))
- (((in-block elsif "")
-   . 3582))
- (((in-block elsif "")
-   . 3582))
+   . 4184))
+ ((select-clause . 4324)
+  (nested-statement-continuation . 4323)
+  (statement-continuation . 4323))
+ ((select-table-continuation . 4358)
+  (nested-statement-continuation . 4323)
+  (statement-continuation . 4323))
+ ((select-clause . 4324)
+  (nested-statement-continuation . 4323)
+  (statement-continuation . 4323))
+ (((in-block elsif "")
+   . 4317))
+ (((in-block elsif "")
+   . 4317))
  (((block-start else)
-   . 3582)
+   . 4317)
   ((in-block elsif "")
-   . 3582))
+   . 4317))
  (((in-block else "")
-   . 3752))
- ((statement-continuation . 3763))
- ((statement-continuation . 3763))
- ((statement-continuation . 3763))
- ((statement-continuation . 3763))
- ((statement-continuation . 3763))
+   . 4511))
+ ((select-clause . 4536)
+  (statement-continuation . 4526))
+ ((select-table-continuation . 4567)
+  (statement-continuation . 4526))
+ ((select-table-continuation . 4567)
+  (statement-continuation . 4526))
+ ((select-table-continuation . 4567)
+  (statement-continuation . 4526))
+ ((select-clause . 4536)
+  (statement-continuation . 4526))
  (((in-block loop "")
-   . 3763))
- ((statement-continuation . 3921))
- ((statement-continuation . 3921))
- ((statement-continuation . 3921))
- ((statement-continuation . 3921))
+   . 4526))
+ ((statement-continuation . 4778))
+ ((statement-continuation . 4778))
+ ((statement-continuation . 4778))
+ ((statement-continuation . 4778))
  (((block-end loop "")
-   . 3763)
+   . 4526)
   ((in-block loop "")
-   . 3763))
+   . 4526))
  (((block-end if "")
-   . 3395)
+   . 4102)
   ((in-block else "")
-   . 3752))
- (((block-end nil "")
-   . 3361)
-  ((in-begin-block nil "")
-   . 3361))
+   . 4511))
+ (((block-end toplevel-block "")
+   . 4060)
+  ((in-begin-block toplevel-block "")
+   . 4060))
  (((block-end toplevel nil)
-   . 3311)
+   . 3994)
   ((in-begin-block toplevel nil)
-   . 3311))
+   . 3994))
  ((toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 4150))
- (((in-begin-block toplevel nil)
-   . 4150))
- (((in-begin-block toplevel nil)
-   . 4150))
- (((in-begin-block toplevel nil)
-   . 4150))
- (((in-begin-block nil "")
-   . 4226))
- (((in-begin-block nil "")
-   . 4226))
- (((in-begin-block nil "")
-   . 4226))
+ ((declare-statement . 5041))
+ ((declare-statement . 5041))
+ ((declare-statement . 5041))
+ (((block-start begin)
+   . 5041)
+  (declare-statement . 5041))
+ (((in-begin-block toplevel-block "")
+   . 5133))
+ (((in-begin-block toplevel-block "")
+   . 5133))
+ (((in-begin-block toplevel-block "")
+   . 5133))
  (((in-block if "")
-   . 4273))
+   . 5192))
  (((in-block if "")
-   . 4273))
+   . 5192))
  (((block-start elsif)
-   . 4273)
+   . 5192)
   ((in-block if "")
-   . 4273))
+   . 5192))
  (((in-block elsif "")
-   . 4343))
+   . 5274))
  (((in-block elsif "")
-   . 4343))
+   . 5274))
  (((block-start elsif)
-   . 4343)
+   . 5274)
   ((in-block elsif "")
-   . 4343))
- ((select-clause . 4426)
-  (nested-statement-continuation . 4425)
-  (statement-continuation . 4425))
+   . 5274))
+ ((select-clause . 5369)
+  (nested-statement-continuation . 5368)
+  (statement-continuation . 5368))
  (((in-select-clause "where")
-   . 4468)
-  (nested-statement-continuation . 4425)
-  (statement-continuation . 4425))
+   . 5415)
+  (nested-statement-continuation . 5368)
+  (statement-continuation . 5368))
  (((in-block elsif "")
-   . 4419))
+   . 5362))
  (((in-block elsif "")
-   . 4419))
+   . 5362))
  (((block-start else)
-   . 4419)
+   . 5362)
   ((in-block elsif "")
-   . 4419))
+   . 5362))
  (((in-block else "")
-   . 4568))
- ((statement-continuation . 4579))
- ((statement-continuation . 4579))
+   . 5531))
+ ((select-clause . 5556)
+  (statement-continuation . 5546))
+ (((in-select-clause "where")
+   . 5598)
+  (statement-continuation . 5546))
  (((in-block loop "")
-   . 4579))
- ((statement-continuation . 4670))
- ((statement-continuation . 4670))
+   . 5546))
+ ((statement-continuation . 5669))
+ ((statement-continuation . 5669))
  (((block-end loop "")
-   . 4579)
+   . 5546)
   ((in-block loop "")
-   . 4579))
+   . 5546))
  (((block-end if "")
-   . 4273)
+   . 5192)
   ((in-block else "")
-   . 4568))
- (((block-end nil "")
-   . 4226)
-  ((in-begin-block nil "")
-   . 4226))
+   . 5531))
+ (((block-end toplevel-block "")
+   . 5133)
+  ((in-begin-block toplevel-block "")
+   . 5133))
  (((block-end toplevel nil)
-   . 4150)
+   . 5035)
   ((in-begin-block toplevel nil)
-   . 4150))
+   . 5035))
  ((toplevel . 1))
  (((block-start begin)
    . 1)
   (toplevel . 1))
  ((toplevel . 1))
- (((in-begin-block toplevel nil)
-   . 4822))
- (((in-begin-block toplevel nil)
-   . 4822))
- (((in-begin-block toplevel nil)
-   . 4822))
- (((in-begin-block toplevel nil)
-   . 4822))
- (((in-begin-block toplevel nil)
-   . 4822))
- (((in-begin-block nil "")
-   . 4928))
- (((in-begin-block nil "")
-   . 4928))
- (((in-begin-block nil "")
-   . 4928))
- (((in-begin-block nil "")
-   . 4928))
- (((in-begin-block nil "")
-   . 4928))
+ ((declare-statement . 5847))
+ ((declare-statement . 5847))
+ ((declare-statement . 5847))
+ ((declare-statement . 5847))
+ (((block-start begin)
+   . 5847)
+  (declare-statement . 5847))
+ (((in-begin-block toplevel-block "")
+   . 5975))
+ (((in-begin-block toplevel-block "")
+   . 5975))
+ (((in-begin-block toplevel-block "")
+   . 5975))
+ (((in-begin-block toplevel-block "")
+   . 5975))
+ (((in-begin-block toplevel-block "")
+   . 5975))
  (((in-block if "")
-   . 5047))
+   . 6114))
  (((in-block if "")
-   . 5047))
+   . 6114))
  (((block-start elsif)
-   . 5047)
+   . 6114)
   ((in-block if "")
-   . 5047))
+   . 6114))
  (((in-block elsif "")
-   . 5117))
+   . 6196))
  (((in-block elsif "")
-   . 5117))
+   . 6196))
  (((block-start elsif)
-   . 5117)
+   . 6196)
   ((in-block elsif "")
-   . 5117))
+   . 6196))
  (((in-block elsif "")
-   . 5193))
+   . 6284))
  (((in-block elsif "")
-   . 5193))
+   . 6284))
  (((block-start else)
-   . 5193)
+   . 6284)
   ((in-block elsif "")
-   . 5193))
+   . 6284))
  (((in-block else "")
-   . 5266))
- ((nested-statement-continuation . 5303)
-  (statement-continuation . 5303))
- ((nested-statement-continuation . 5303)
-  (statement-continuation . 5303))
- ((nested-statement-continuation . 5303)
-  (statement-continuation . 5303))
- ((nested-statement-continuation . 5303)
-  (statement-continuation . 5303))
+   . 6369))
+ ((nested-statement-continuation . 6410)
+  (statement-continuation . 6410))
+ ((nested-statement-continuation . 6410)
+  (statement-continuation . 6410))
+ ((nested-statement-continuation . 6410)
+  (statement-continuation . 6410))
+ ((nested-statement-continuation . 6410)
+  (statement-continuation . 6410))
  (((in-block else "")
-   . 5266))
+   . 6369))
  (((block-end if "")
-   . 5047)
+   . 6114)
   ((in-block else "")
-   . 5266))
- (((block-end nil "")
-   . 4928)
-  ((in-begin-block nil "")
-   . 4928))
+   . 6369))
+ (((block-end toplevel-block "")
+   . 5975)
+  ((in-begin-block toplevel-block "")
+   . 5975))
  (((block-end toplevel nil)
-   . 4822)
+   . 5841)
   ((in-begin-block toplevel nil)
-   . 4822))
+   . 5841))
  ((toplevel . 1))
  ((toplevel . 1))
  (((block-start begin)
@@ -525,46 +540,50 @@
   (toplevel . 1))
  ((toplevel . 1))
  (((in-begin-block toplevel nil)
-   . 5627))
- (((in-begin-block toplevel nil)
-   . 5627))
- (((in-begin-block nil "")
-   . 5665))
- (((in-begin-block nil "")
-   . 5665))
+   . 6762))
+ ((declare-statement . 6770))
+ (((block-start begin)
+   . 6770)
+  (declare-statement . 6770))
+ (((in-begin-block toplevel-block "")
+   . 6804))
+ (((in-begin-block toplevel-block "")
+   . 6804))
  (((in-block if "")
-   . 5695))
+   . 6834))
  (((in-block if "")
-   . 5695))
+   . 6834))
  (((block-start elsif)
-   . 5695)
+   . 6834)
   ((in-block if "")
-   . 5695))
+   . 6834))
  (((in-block elsif "")
-   . 5802))
+   . 6941))
  (((in-block elsif "")
-   . 5802))
+   . 6941))
  (((in-block elsif "")
-   . 5802))
+   . 6941))
  (((block-start else)
-   . 5802)
+   . 6941)
   ((in-block elsif "")
-   . 5802))
+   . 6941))
  (((in-block else "")
-   . 5916))
+   . 7055))
  (((in-block else "")
-   . 5916))
+   . 7055))
  (((block-end if "")
-   . 5695)
+   . 6834)
   ((in-block else "")
-   . 5916))
- (((block-end nil "")
-   . 5665)
-  ((in-begin-block nil "")
-   . 5665))
+   . 7055))
+ (((block-end toplevel-block "")
+   . 6804)
+  ((in-begin-block toplevel-block "")
+   . 6804))
  (((block-end toplevel nil)
-   . 5627)
+   . 6762)
   ((in-begin-block toplevel nil)
-   . 5627))
+   . 6762))
  ((toplevel . 1))
- ((toplevel . 1)))
\ No newline at end of file
+ ((toplevel . 1)))
+ 
+ 
\ No newline at end of file
diff --git a/test-data/pr67.sql b/test-data/pr67.sql
index c5d804c..a9d4d83 100644
--- a/test-data/pr67.sql
+++ b/test-data/pr67.sql
@@ -3,235 +3,236 @@ set serveroutput on;
 
 begin transaction;
 do $$ DECLARE
-  v1 TABLE1.F1%TYPE;
-  v2 record;
-  BEGIN
-    v1 = :v_v1;
-    if v1 in (NULL, '') then
-      raise 'message1';
-      rollback;
-    elsif (select count(F1) from TABLE1
-            where F1 = v1) = 0 then
-      raise 'message2';
-      rollback;
-    elsif (select count(F2)
-             from TABLE1 natural join TABLE2
-            where F1 = v1) = 0 then
-      raise 'message3';
-      rollback;
-    elsif (select count(F3)
-             from TABLE3
-                    natural join TABLE2
-                    natural join TABLE1
-            where F1 = v1) = 0 then
-      raise 'message4';
-      rollback;
-    else
-      for v2 in 
-        select *
-        from TABLE3 
-        natural join TABLE1
-        natural join TABLE4
-        natural join TABLE2
-        where F1 = v1 loop
-        raise info 'message5',
-          v2.F3, v2.F2, v2.F4 || ' ' ||
-          v2.F9 || case when v2.F5 is NULL then '' else
-          ' ''' || v2.F5 || '''' end, v2.F6,
-          v2.F7, v2.F8;
-      end loop;
-    end if;
-  END; $$;
+        v1 TABLE1.F1%TYPE;
+        v2 record;
+      BEGIN
+        v1 = :v_v1;
+        if v1 in (NULL, '') then
+          raise 'message1';
+          rollback;
+        elsif (select count(F1) from TABLE1
+                where F1 = v1) = 0 then
+          raise 'message2';
+          rollback;
+        elsif (select count(F2)
+                 from TABLE1 natural join TABLE2
+                where F1 = v1) = 0 then
+          raise 'message3';
+          rollback;
+        elsif (select count(F3)
+                 from TABLE3
+                        natural join TABLE2
+                        natural join TABLE1
+                where F1 = v1) = 0 then
+          raise 'message4';
+          rollback;
+        else
+          for v2 in 
+            select *
+              from TABLE3 
+                     natural join TABLE1
+                     natural join TABLE4
+                     natural join TABLE2
+             where F1 = v1 loop
+            raise info 'message5',
+              v2.F3, v2.F2, v2.F4 || ' ' ||
+              v2.F9 || case when v2.F5 is NULL then '' else
+              ' ''' || v2.F5 || '''' end, v2.F6,
+              v2.F7, v2.F8;
+          end loop;
+        end if;
+      END; $$;
 commit;
 
 do $$ DECLARE
-  v1 TABLE4.F9%TYPE;
-  prev1 TABLE4.F4%TYPE;
-  v2 record;
-  BEGIN
-    v1 := :v_v1;
-    prev1 := :v_prev1;
-    if v1 in (NULL, '') then
-      raise 'message6';
-      rollback;
-    elsif prev1 in (NULL, '') then
-      raise 'message7';
-      rollback;
-    elsif (select count(F10)
-             from TABLE4
-            where F9 = v1
-              and F4 = prev1) = 0 then
-      raise 'message8';
-      rollback;
-    elsif (select count(F2)
-             from TABLE2
-                    natural join TABLE5
-                    natural join TABLE4
-            where F9 = v1
-              and F4 = prev1) = 0 then
-      raise 'message9';
-      rollback;
-    elsif (select count(F3)
-             from TABLE3
-                    natural join TABLE2
-                    natural join TABLE5
-                    natural join TABLE4
-            where F9 = v1
-              and F4 = prev1) = 0 then
-      raise 'message10';
-      rollback;
-    else
-      for v2 in select *
-        from TABLE4
-        natural join TABLE5
-        natural join TABLE3
-        natural join TABLE2
-        where F9 = v1
-        and F4 = prev1 loop
-        raise info 'message11',
-          v2.F3, v2.F2, v2.F4 || ' ' ||
-          v2.F9 || case when v2.F5 is NULL then '' else
-          ' ''' || v2.F5 || '''' end, v2.F6,
-          v2.F7, v2.F8;
-      end loop;
-    end if;
-  end; $$;
+        v1 TABLE4.F9%TYPE;
+        prev1 TABLE4.F4%TYPE;
+        v2 record;
+      BEGIN
+        v1 := :v_v1;
+        prev1 := :v_prev1;
+        if v1 in (NULL, '') then
+          raise 'message6';
+          rollback;
+        elsif prev1 in (NULL, '') then
+          raise 'message7';
+          rollback;
+        elsif (select count(F10)
+                 from TABLE4
+                where F9 = v1
+                  and F4 = prev1) = 0 then
+          raise 'message8';
+          rollback;
+        elsif (select count(F2)
+                 from TABLE2
+                        natural join TABLE5
+                        natural join TABLE4
+                where F9 = v1
+                  and F4 = prev1) = 0 then
+          raise 'message9';
+          rollback;
+        elsif (select count(F3)
+                 from TABLE3
+                        natural join TABLE2
+                        natural join TABLE5
+                        natural join TABLE4
+                where F9 = v1
+                  and F4 = prev1) = 0 then
+          raise 'message10';
+          rollback;
+        else
+          for v2 in select *
+                      from TABLE4
+                             natural join TABLE5
+                             natural join TABLE3
+                             natural join TABLE2
+                     where F9 = v1
+                       and F4 = prev1 loop
+            raise info 'message11',
+              v2.F3, v2.F2, v2.F4 || ' ' ||
+              v2.F9 || case when v2.F5 is NULL then '' else
+              ' ''' || v2.F5 || '''' end, v2.F6,
+              v2.F7, v2.F8;
+          end loop;
+        end if;
+      end; $$;
 
 
 do $$ DECLARE
-  v2 record;
-  v3 TABLE2.F6%TYPE;
-  BEGIN
-    v3 := :v_v3;
-    if v3 in ('', NULL) then
-      raise 'message12';
-      rollback;
-    elsif (select count(F6) from TABLE2
-            where F6 = v3) = 0 then
-      raise 'message13';
-      rollback;
-    elsif (select count(F3)
-             from TABLE3
-                    natural join TABLE2
-            where F6 = v3) = 0 then
-      raise 'message14';
-      rollback;
-    else
-      for v2 in select *
-        from TABLE4
-        natural join TABLE5
-        natural join TABLE3
-        natural join TABLE2
-        where F6 = v3 loop
-        raise info 'message15',
-          v2.F3, v2.F2, v2.F4 || ' ' ||
-          v2.F9 || case when v2.F5 is NULL then '' else
-          ' ''' || v2.F5 || '''' end, v2.F6,
-          v2.F7, v2.F8;
-      end loop;
-    end if;
-  END; $$;
+        v2 record;
+        v3 TABLE2.F6%TYPE;
+      BEGIN
+        v3 := :v_v3;
+        if v3 in ('', NULL) then
+          raise 'message12';
+          rollback;
+        elsif (select count(F6) from TABLE2
+                where F6 = v3) = 0 then
+          raise 'message13';
+          rollback;
+        elsif (select count(F3)
+                 from TABLE3
+                        natural join TABLE2
+                where F6 = v3) = 0 then
+          raise 'message14';
+          rollback;
+        else
+          for v2 in select *
+                      from TABLE4
+                             natural join TABLE5
+                             natural join TABLE3
+                             natural join TABLE2
+                     where F6 = v3 loop
+            raise info 'message15',
+              v2.F3, v2.F2, v2.F4 || ' ' ||
+              v2.F9 || case when v2.F5 is NULL then '' else
+              ' ''' || v2.F5 || '''' end, v2.F6,
+              v2.F7, v2.F8;
+          end loop;
+        end if;
+      END; $$;
 
 do $$ DECLARE
-  v2 record;
-  v3 TABLE2.F2%TYPE;
-  BEGIN
-    v3 := :v_ouv_titre;
-    if v3 in ('', NULL) then
-      raise 'message16';
-      rollback;
-    elsif (select count(F2) from TABLE2
-            where F2 = v3) = 0 then
-      raise 'messaeg17';
-      rollback;
-    elsif (select count(F3)
-             from TABLE3
-                    natural join TABLE2
-            where F2 = v3) = 0 then
-      raise 'message18';
-      rollback;
-    else
-      for v2 in select *
-        from TABLE4
-        natural join TABLE5
-        natural join TABLE3
-        natural join TABLE2
-        where F2 = v3 loop
-        raise info 'message19',
-          v2.F3, v2.F2, v2.F4 || ' ' ||
-          v2.F9 || case when v2.F5 is NULL then '' else
-          ' ''' || v2.F5 || '''' end, v2.F6,
-          v2.F7, v2.F8;
-      end loop;
-    end if;
-  END;
+        v2 record;
+        v3 TABLE2.F2%TYPE;
+      BEGIN
+        v3 := :v_ouv_titre;
+        if v3 in ('', NULL) then
+          raise 'message16';
+          rollback;
+        elsif (select count(F2) from TABLE2
+                where F2 = v3) = 0 then
+          raise 'messaeg17';
+          rollback;
+        elsif (select count(F3)
+                 from TABLE3
+                        natural join TABLE2
+                where F2 = v3) = 0 then
+          raise 'message18';
+          rollback;
+        else
+          for v2 in select *
+                      from TABLE4
+                             natural join TABLE5
+                             natural join TABLE3
+                             natural join TABLE2
+                     where F2 = v3 loop
+            raise info 'message19',
+              v2.F3, v2.F2, v2.F4 || ' ' ||
+              v2.F9 || case when v2.F5 is NULL then '' else
+              ' ''' || v2.F5 || '''' end, v2.F6,
+              v2.F7, v2.F8;
+          end loop;
+        end if;
+      END;
 $$;
 
 do $$ DECLARE
-  v1 TABLE6.F12%TYPE;
-  prev1 TABLE6.F13%TYPE;
-  v2 record;
-  BEGIN
-    v1 := :v_v1;
-    prev1 := :v_v2;
-    if v1 in ('', NULL) then
-      raise 'message20';
-      rollback;
-    elsif prev1 in ('', NULL) then
-      raise 'message21';
-      rollback;
-    elsif (select count(F23) from TABLE6
-            where F12 = v1
-              and F13 = prev1) = 0 then
-      raise 'message22';
-      rollback;
-    else
-      for v2 in select * from TABLE6
-        where F12 = v1
-        and F13 = prev1 loop
-        raise info 'message23',
-          v2.F23, v2.F13 || ' ' || v2.F12,
-          v2.F27, v2.F28;
-      end loop;
-    end if;
-  END;
+        v1 TABLE6.F12%TYPE;
+        prev1 TABLE6.F13%TYPE;
+        v2 record;
+      BEGIN
+        v1 := :v_v1;
+        prev1 := :v_v2;
+        if v1 in ('', NULL) then
+          raise 'message20';
+          rollback;
+        elsif prev1 in ('', NULL) then
+          raise 'message21';
+          rollback;
+        elsif (select count(F23) from TABLE6
+                where F12 = v1
+                  and F13 = prev1) = 0 then
+          raise 'message22';
+          rollback;
+        else
+          for v2 in select * from TABLE6
+                     where F12 = v1
+                       and F13 = prev1 loop
+            raise info 'message23',
+              v2.F23, v2.F13 || ' ' || v2.F12,
+              v2.F27, v2.F28;
+          end loop;
+        end if;
+      END;
 $$;
 
 begin transaction;
 do $$ DECLARE
-  v1 TABLE6.F23%TYPE;
-  v1 TABLE6.F12%TYPE;
-  prev1 TABLE6.F13%TYPE;
-  v9 TABLE6.V2%TYPE;
-  BEGIN
-    select max(v2_id)+1 into v1 from t_v2ent;
-    v1 := :v_v2_c2;
-    prev1 := :v_v2_c8;
-    v9 := :v_v2_c9;
-    if v1 in ('', NULL) then
-      raise 'message24';
-      rollback;
-    elsif prev1 in ('', NULL) then
-      raise 'message25';
-      rollback;
-    elsif v9 in ('', NULL) then
-      raise 'message26';
-      rollback;
-    else
-      insert into TABLE6 values (v1, :v19, timestamp 'now',
-                                 v1, prev1, :v_v2_v8,
-                                 :v_v2_c7, :v_v2_v9,
-                                 :v_v2_c8, :v_v2_v10,
-                                 :v_v2_c9, v9);
-      raise notice 'message27', v1;
-    end if;
-  END;
+        v1 TABLE6.F23%TYPE;
+        v1 TABLE6.F12%TYPE;
+        prev1 TABLE6.F13%TYPE;
+        v9 TABLE6.V2%TYPE;
+      BEGIN
+        select max(v2_id)+1 into v1 from t_v2ent;
+        v1 := :v_v2_c2;
+        prev1 := :v_v2_c8;
+        v9 := :v_v2_c9;
+        if v1 in ('', NULL) then
+          raise 'message24';
+          rollback;
+        elsif prev1 in ('', NULL) then
+          raise 'message25';
+          rollback;
+        elsif v9 in ('', NULL) then
+          raise 'message26';
+          rollback;
+        else
+          insert into TABLE6 values (v1, :v19, timestamp 'now',
+                                     v1, prev1, :v_v2_v8,
+                                     :v_v2_c7, :v_v2_v9,
+                                     :v_v2_c8, :v_v2_v10,
+                                     :v_v2_c9, v9);
+          raise notice 'message27', v1;
+        end if;
+      END;
 $$;
 commit;
 
 begin transaction;
-do $$ DECLARE
-  v1 TABLE6.F23%TYPE;
+do $$
+  DECLARE
+    v1 TABLE6.F23%TYPE;
   BEGIN
     v1 := :v_v2_id;
     if (select count(F23) from TABLE6 where F23 = v2_id) = 0 then
diff --git a/test-data/pr88-syn.eld b/test-data/pr88-syn.eld
index 67e31d7..d1debd9 100644
--- a/test-data/pr88-syn.eld
+++ b/test-data/pr88-syn.eld
@@ -23,33 +23,38 @@
    . 159))
  (((create-statement trigger "t1")
    . 159))
- ((statement-continuation . 213))
+ (((create-statement trigger "t1")
+   . 159))
  ((toplevel . 1))
  ((toplevel . 1))
  (((create-statement trigger "t2")
-   . 254))
+   . 252))
+ (((create-statement trigger "t2")
+   . 252))
  (((create-statement trigger "t2")
-   . 254))
+   . 252))
  (((create-statement trigger "t2")
-   . 254))
- ((statement-continuation . 308))
+   . 252))
  ((toplevel . 1))
  ((toplevel . 1))
  (((create-statement trigger "t3")
-   . 354))
+   . 350))
  (((create-statement trigger "t3")
-   . 354))
+   . 350))
  (((create-statement trigger "t3")
-   . 354))
- ((statement-continuation . 408))
+   . 350))
+ (((create-statement trigger "t3")
+   . 350))
  ((toplevel . 1))
  ((toplevel . 1))
  (((create-statement trigger "t4")
-   . 455))
+   . 449))
+ (((create-statement trigger "t4")
+   . 449))
  (((create-statement trigger "t4")
-   . 455))
+   . 449))
  (((create-statement trigger "t4")
-   . 455))
- ((statement-continuation . 509))
+   . 449))
  ((toplevel . 1)))
 
+
diff --git a/test-data/pr89-syn.eld b/test-data/pr89-syn.eld
index 2f0a245..93e18e6 100644
--- a/test-data/pr89-syn.eld
+++ b/test-data/pr89-syn.eld
@@ -1,7 +1,8 @@
 (((comment-start . 1)
   (toplevel . 1))
  ((toplevel . 1))
- ((statement-continuation . 46))
+ (((in-begin-block toplevel nil)
+   . 46))
  (((in-begin-block nil "")
    . 54))
  (((block-end nil "")
@@ -14,7 +15,8 @@
    . 46))
  ((toplevel . 1))
  ((toplevel . 1))
- ((statement-continuation . 111))
+ (((in-begin-block toplevel nil)
+   . 111))
  (((in-begin-block nil "")
    . 119))
  (((create-statement table "t")
@@ -29,7 +31,8 @@
    . 111))
  ((toplevel . 1))
  ((toplevel . 1))
- ((statement-continuation . 199))
+ (((in-begin-block toplevel nil)
+   . 199))
  (((in-begin-block nil "")
    . 207))
  (((create-statement view "t")
@@ -47,7 +50,8 @@
    . 199))
  ((toplevel . 1))
  ((toplevel . 1))
- ((statement-continuation . 295))
+ (((in-begin-block toplevel nil)
+   . 295))
  (((in-begin-block nil "")
    . 303))
  (((block-end nil "")
diff --git a/test-data/pr92-syn.eld b/test-data/pr92-syn.eld
new file mode 100644
index 0000000..41d3581
--- /dev/null
+++ b/test-data/pr92-syn.eld
@@ -0,0 +1,54 @@
+(((comment-start . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block defun "less_than")
+   . 46))
+ ((declare-statement . 112))
+ ((declare-statement . 112))
+ (((block-start begin)
+   . 112)
+  (declare-statement . 112))
+ (((in-begin-block toplevel-block "")
+   . 168))
+ (((block-end toplevel-block "")
+   . 168)
+  ((in-begin-block toplevel-block "")
+   . 168))
+ (((block-end defun "less_than")
+   . 46)
+  ((in-begin-block defun "less_than")
+   . 46))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((statement-continuation . 233))
+ ((statement-continuation . 233))
+ ((statement-continuation . 233))
+ ((select-clause . 266)
+  (statement-continuation . 233))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block defun "less_than")
+   . 292))
+ ((declare-statement . 358))
+ ((declare-statement . 358))
+ ((declare-statement . 358))
+ ((statement-continuation . 416))
+ ((select-clause . 460)
+  (statement-continuation . 416))
+ (((block-start begin)
+   . 358)
+  (declare-statement . 358))
+ (((in-begin-block toplevel-block "")
+   . 491))
+ (((block-end toplevel-block "")
+   . 491)
+  ((in-begin-block toplevel-block "")
+   . 491))
+ (((block-end defun "less_than")
+   . 292)
+  ((in-begin-block defun "less_than")
+   . 292))
+ ((toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((toplevel . 1)))
diff --git a/test-data/pr92.sql b/test-data/pr92.sql
new file mode 100644
index 0000000..1a0e02b
--- /dev/null
+++ b/test-data/pr92.sql
@@ -0,0 +1,29 @@
+-- -*- mode: sql; sql-product: postgres; -*-
+create function less_than(a text, b text) returns boolean as $$
+  declare
+    local_a text := a;
+    local_b text := b;
+  begin
+    return local_a < local_b;
+  end;
+$$ language plpgsql;
+
+declare
+  liahona
+  cursor for
+  select *
+    from films;
+
+create function less_than(a text, b text) returns boolean as $$
+  declare
+    local_a text := a;
+    local_b text := b;
+    declare c binary cursor with hold for
+      select *
+        from films;
+  begin
+    return local_a < local_b;
+  end;
+$$ language plpgsql;
+
+-- this line should be toplevel
diff --git a/test-data/pr92a-syn.eld b/test-data/pr92a-syn.eld
new file mode 100644
index 0000000..33217db
--- /dev/null
+++ b/test-data/pr92a-syn.eld
@@ -0,0 +1,13 @@
+(((comment-start . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((statement-continuation . 45))
+ ((select-clause . 61)
+  (statement-continuation . 45))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((statement-continuation . 87))
+ ((select-clause . 107)
+  (statement-continuation . 87))
+ ((toplevel . 1)))
diff --git a/test-data/pr92a.sql b/test-data/pr92a.sql
new file mode 100644
index 0000000..57fedae
--- /dev/null
+++ b/test-data/pr92a.sql
@@ -0,0 +1,9 @@
+-- -*- mode: sql; sql-product: oracle; -*-
+
+cursor foo is
+  select *
+    from films;
+
+cursor foo int is
+  select *
+    from films;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]