[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/sql-indent f75d7a7 3/9: Fixes to function and procedure
From: |
Alex Harsanyi |
Subject: |
[elpa] externals/sql-indent f75d7a7 3/9: Fixes to function and procedure block detection (#88, #90) |
Date: |
Fri, 20 Mar 2020 19:08:02 -0400 (EDT) |
branch: externals/sql-indent
commit f75d7a7f2a51bbc0622f17bcfe667caaf1b26922
Author: Alex Harsanyi <address@hidden>
Commit: Alex Harsanyi <address@hidden>
Fixes to function and procedure block detection (#88, #90)
* sql-indent.el (sqlind-maybe-defun-statement): accept defun names which
contain the schema part and don't treat "comment on" statements as function
definitions.
---
sql-indent-test.el | 10 +++++++++
sql-indent.el | 14 ++++++++++---
test-data/pr88-syn.eld | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
test-data/pr88.sql | 31 ++++++++++++++++++++++++++++
test-data/pr90-syn.eld | 8 ++++++++
test-data/pr90.sql | 5 +++++
6 files changed, 120 insertions(+), 3 deletions(-)
diff --git a/sql-indent-test.el b/sql-indent-test.el
index 38af1c0..07d79d3 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -427,9 +427,19 @@ information read from DATA-FILE (as generated by
"test-data/pr87.sql"
"test-data/pr87-syn.eld"))
+(ert-deftest sqlind-ert-pr88 ()
+ (sqlind-ert-check-file-syntax
+ "test-data/pr88.sql"
+ "test-data/pr88-syn.eld"))
+
(ert-deftest sqlind-ert-pr89 ()
(sqlind-ert-check-file-syntax
"test-data/pr89.sql"
"test-data/pr89-syn.eld"))
+(ert-deftest sqlind-ert-pr90 ()
+ (sqlind-ert-check-file-syntax
+ "test-data/pr90.sql"
+ "test-data/pr90-syn.eld"))
+
;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 0496a53..983991d 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -793,7 +793,7 @@ argument is t"
"If (point) is on a procedure definition statement, report its syntax.
See also `sqlind-beginning-of-block'"
(catch 'exit
- (when (looking-at "\\(procedure\\|function\\)\\(?:[
\t\n\r\f]+\\)\\([a-z0-9_]+\\)")
+ (when (looking-at "\\(procedure\\|function\\)\\(?:[
\t\n\r\f]+\\)\\(?:[a-z0-9_]+\\.\\)?\\([a-z0-9_]+\\)")
(prog1 t ; make sure we return t
(let ((proc-name (sqlind-match-string 2)))
;; need to find out if this is a procedure/function
@@ -812,13 +812,21 @@ See also `sqlind-beginning-of-block'"
;; not a procedure after all.
(throw 'exit nil)))
- ;; Find out if it is a drop procedure or function statement
(save-excursion
(sqlind-backward-syntactic-ws)
+ ;; Find out if it is a drop procedure or function statement
(forward-word -1)
(when (looking-at "drop")
;; not a procedure after all
- (throw 'exit nil)))
+ (throw 'exit nil))
+ ;; Find out if it is a "comment on" statement (postgres only)
+ (when (and (eq sql-product 'postgres)
+ (looking-at "on"))
+ (sqlind-backward-syntactic-ws)
+ (forward-word -1)
+ (when (looking-at "comment")
+ ;; not a procedure after all.
+ (throw 'exit nil))))
;; so it is a definition
diff --git a/test-data/pr88-syn.eld b/test-data/pr88-syn.eld
new file mode 100644
index 0000000..67e31d7
--- /dev/null
+++ b/test-data/pr88-syn.eld
@@ -0,0 +1,55 @@
+(((comment-start . 1)
+ (toplevel . 1))
+ ((toplevel . 1))
+ (((defun-start "noop")
+ . 46))
+ (((in-begin-block defun "noop")
+ . 46))
+ (((in-begin-block nil "")
+ . 108))
+ (((block-end nil "")
+ . 108)
+ ((in-begin-block nil "")
+ . 108))
+ (((block-end defun "noop")
+ . 46)
+ ((in-begin-block defun "noop")
+ . 46))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((create-statement trigger "t1")
+ . 159))
+ (((create-statement trigger "t1")
+ . 159))
+ (((create-statement trigger "t1")
+ . 159))
+ ((statement-continuation . 213))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((create-statement trigger "t2")
+ . 254))
+ (((create-statement trigger "t2")
+ . 254))
+ (((create-statement trigger "t2")
+ . 254))
+ ((statement-continuation . 308))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((create-statement trigger "t3")
+ . 354))
+ (((create-statement trigger "t3")
+ . 354))
+ (((create-statement trigger "t3")
+ . 354))
+ ((statement-continuation . 408))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((create-statement trigger "t4")
+ . 455))
+ (((create-statement trigger "t4")
+ . 455))
+ (((create-statement trigger "t4")
+ . 455))
+ ((statement-continuation . 509))
+ ((toplevel . 1)))
+
diff --git a/test-data/pr88.sql b/test-data/pr88.sql
new file mode 100644
index 0000000..2de4643
--- /dev/null
+++ b/test-data/pr88.sql
@@ -0,0 +1,31 @@
+-- -*- mode: sql; sql-product: postgres; -*-
+create or replace function s.noop()
+ returns trigger as $$
+ begin
+ return new;
+ end;
+$$ language plpgsql;
+
+create trigger t1
+ after insert or update
+ on tbl
+ for row
+ execute procedure s.noop();
+
+create trigger t2
+ after insert or update
+ on tbl
+ for each row
+ execute procedure s.noop();
+
+create trigger t3
+ after insert or update
+ on tbl
+ for statement
+ execute procedure s.noop();
+
+create trigger t4
+ after insert or update
+ on tbl
+ for each statement
+ execute procedure s.noop();
diff --git a/test-data/pr90-syn.eld b/test-data/pr90-syn.eld
new file mode 100644
index 0000000..72aaa01
--- /dev/null
+++ b/test-data/pr90-syn.eld
@@ -0,0 +1,8 @@
+(((comment-start . 1)
+ (toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((statement-continuation . 148))
+ ((toplevel . 1)))
+
\ No newline at end of file
diff --git a/test-data/pr90.sql b/test-data/pr90.sql
new file mode 100644
index 0000000..9f02a9b
--- /dev/null
+++ b/test-data/pr90.sql
@@ -0,0 +1,5 @@
+-- -*- mode: sql; sql-product: postgres; -*-
+comment on function hello is 'returns a greeting.';
+comment on procedure world is 'creates a world.';
+comment -- this is a comment
+ on function hello is 'returns a greeting.';
- [elpa] externals/sql-indent updated (08f0417 -> dad9605), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent 7f649aa 1/9: Fix indentation for create schema if not exists (fixes #87), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent b694078 2/9: CREATE TABLE, VIEW and INDEX does not start a block (#89), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent 56be397 4/9: Create GH Action for build and test (#91), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent f75d7a7 3/9: Fixes to function and procedure block detection (#88, #90),
Alex Harsanyi <=
- [elpa] externals/sql-indent e7795c7 6/9: Mode refinements in recognizing declare statements (#92), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent dad9605 9/9: Release 1.5, remove Travis, add GitHub Actions status badge, Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent 5656cfb 8/9: Document limitations of recognizing DECLARE statements (#92), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent 7edd915 7/9: fixups for indenting where clauses (#93), Alex Harsanyi, 2020/03/20
- [elpa] externals/sql-indent 1bb06f8 5/9: Fix detection of DECLARE blocks in PostgresSQL (#92), Alex Harsanyi, 2020/03/20