branch: externals/sql-indent
commit 84581e36d263ec5cdc5bd4ae381f25806b0ebde0
Author: Pierre Téchoueyres <[email protected]>
Commit: Alex Harsányi <[email protected]>

    Allow detection of user name in package, procedure or function. (#37)
    
    * Allow detection of user name in package, procedure or function.
    
    Avoid `mismatched end label for package (1 104)` message whith and sql
    of this form:
    
    ```sql
    create or replace package my_user.my_wonderfull_package as
      function my_amazing_func return number;
    end my_wonderfull_package;
    /
    ```
    
    * Add tests to PR #37.
---
 sql-indent-test.el         |  7 +++++++
 sql-indent.el              |  8 ++++++--
 test-data/pr37-io-left.eld |  1 +
 test-data/pr37-syn.eld     | 24 ++++++++++++++++++++++++
 test-data/pr37.sql         | 12 ++++++++++++
 5 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 046ca07..71afea4 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -326,4 +326,11 @@ information read from DATA-FILE (as generated by
   (sqlind-ert-check-file-indentation "test-data/pr36.sql" 
"test-data/pr36-io-left.eld"
    sqlind-indentation-left-offsets-alist 2))
 
+(ert-deftest sqlind-ert-pr37 ()
+  (sqlind-ert-check-file-syntax "test-data/pr37.sql" "test-data/pr37-syn.eld"))
+
+(ert-deftest sqlind-ert-pr37-io-left ()
+  (sqlind-ert-check-file-indentation "test-data/pr37.sql" 
"test-data/pr37-io-left.eld"
+   sqlind-indentation-left-offsets-alist 2))
+
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index d374d43..fc9a038 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -644,7 +644,11 @@ See also `sqlind-beginning-of-block'"
                         (progn (skip-syntax-forward "w_") (point))))))
 
          (if (memq what '(procedure function package package-body))
-           (if (null sqlind-end-stmt-stack)
+             ;; check is name is in the form user.name, if so then suppress 
user part.
+             (progn
+               (when (string-match "\\(?:.*\\.\\)?\\(.*\\)" name)
+                 (setq name (match-string 1 name)))
+               (if (null sqlind-end-stmt-stack)
                (throw 'finished
                  (list (if (memq what '(procedure function)) 'defun-start what)
                        name))
@@ -656,7 +660,7 @@ See also `sqlind-beginning-of-block'"
                  (unless (sqlind-labels-match label name)
                    (throw 'finished
                      (list 'syntax-error
-                           "label mismatch in create block" (point) pos)))))
+                           "label mismatch in create block" (point) pos))))))
            ;; we are creating a non-code block thing: table, view,
            ;; index, etc.  These things only exist at toplevel.
            (unless (null sqlind-end-stmt-stack)
diff --git a/test-data/pr37-io-left.eld b/test-data/pr37-io-left.eld
new file mode 100644
index 0000000..62efb46
--- /dev/null
+++ b/test-data/pr37-io-left.eld
@@ -0,0 +1 @@
+(0 2 0 0 0 0 0 0 0 0 0 0 0)
\ No newline at end of file
diff --git a/test-data/pr37-syn.eld b/test-data/pr37-syn.eld
new file mode 100644
index 0000000..5f36692
--- /dev/null
+++ b/test-data/pr37-syn.eld
@@ -0,0 +1,24 @@
+(((toplevel . 1))
+ (((package "my_wonderfull_package")
+   . 1))
+ (((block-end package "my_wonderfull_package")
+   . 1)
+  ((package "my_wonderfull_package")
+   . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((comment-start . 1)
+  (toplevel . 1))
+ ((toplevel . 1)))
diff --git a/test-data/pr37.sql b/test-data/pr37.sql
new file mode 100644
index 0000000..640d54a
--- /dev/null
+++ b/test-data/pr37.sql
@@ -0,0 +1,12 @@
+create or replace package my_user.my_wonderfull_package as
+  function my_amazing_func return number;
+end my_wonderfull_package;
+/
+
+-- Local Variables:
+-- mode: sql
+-- mode: sqlind-minor
+-- tab-width: 2
+-- indent-tabs-mode: nil
+-- sql-product: oracle
+-- End:

Reply via email to