branch: externals/sql-indent
commit a3cc34139c9f85f14bfd35da783b3ce90908bbc7
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>
Fix exception being a type as well as a keyword (#28)
"exception" is both a keyword and a datatype. Add code to differentiate
between the two. Only the keyword is a block start. Updated test files to
reflect that.
---
sql-indent.el | 10 +++++-
test-data/pr28-syn.eld | 92 +++++++++++++++++++++++++++++++++-----------------
test-data/pr28.sql | 15 ++++++--
3 files changed, 82 insertions(+), 35 deletions(-)
diff --git a/sql-indent.el b/sql-indent.el
index e867416..c9d28d6 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -684,7 +684,15 @@ See also `sqlind-beginning-of-block'"
See also `sqlind-beginning-of-block'"
(when (and (looking-at "exception")
(null sqlind-end-stmt-stack))
- (throw 'finished (list 'in-block 'exception))))
+ ;; Exception is both a keyword and a type. We need to only stop on the
+ ;; keyword. We detect that if the previous token is either ";" or
+ ;; "BEGIN".
+ (save-excursion
+ (forward-char -1)
+ (sqlind-backward-syntactic-ws)
+ (when (or (looking-at ";")
+ (progn (forward-word -1) (looking-at "\\<_begin\\_>")))
+ (throw 'finished (list 'in-block 'exception))))))
(defconst sqlind-start-block-regexp
(concat "\\(\\b"
diff --git a/test-data/pr28-syn.eld b/test-data/pr28-syn.eld
index 5ac3da2..a993d4b 100644
--- a/test-data/pr28-syn.eld
+++ b/test-data/pr28-syn.eld
@@ -1,64 +1,93 @@
(((toplevel . 1))
((declare-statement . 1))
+ ((declare-statement . 1))
(((block-start begin)
. 1)
(declare-statement . 1))
(((in-begin-block toplevel-block "")
- . 25))
+ . 62))
(((in-begin-block nil "")
- . 33))
+ . 70))
(((in-block if "")
- . 43))
+ . 80))
(((in-block if "")
- . 43))
- (((block-start else)
- . 43)
+ . 80))
+ (((block-start elsif)
+ . 80)
((in-block if "")
- . 43))
- (((in-block else "")
- . 87))
+ . 80))
+ (((in-block elsif "")
+ . 124))
+ (((in-block elsif "")
+ . 124))
+ (((block-start else)
+ . 124)
+ ((in-block elsif "")
+ . 124))
(((in-block else "")
- . 87))
+ . 166))
(((block-end if "")
- . 43)
+ . 80)
+ ((in-block else "")
+ . 166))
+ (((in-begin-block nil "")
+ . 70))
+ (((block-start when)
+ . 215)
+ ((in-block case "")
+ . 215))
+ (((block-start when)
+ . 228)
+ ((in-block case "")
+ . 228))
+ (((block-start when)
+ . 228)
+ ((in-block case "")
+ . 228))
+ (((block-start else)
+ . 228)
+ ((in-block case "")
+ . 228))
+ (((block-end case "")
+ . 228)
((in-block else "")
- . 87))
+ . 325))
(((block-start exception)
- . 33)
+ . 70)
((in-begin-block nil "")
- . 33))
+ . 70))
(((in-block exception)
- . 132))
+ . 364))
(((in-block exception-handler)
- . 146)
+ . 378)
((in-block exception "")
- . 132))
+ . 364))
(((in-block exception-handler)
- . 146)
+ . 378)
((in-block exception "")
- . 132))
+ . 364))
(((in-block exception "")
- . 132))
+ . 364))
(((in-block exception-handler "")
- . 200)
- (statement-continuation . 200))
+ . 432)
+ (statement-continuation . 432))
(((in-block exception-handler)
- . 200)
+ . 432)
((in-block exception "")
- . 132))
+ . 364))
(((in-block exception "")
- . 132))
+ . 364))
(((in-block exception-handler "")
- . 254)
- (statement-continuation . 254))
+ . 486)
+ (statement-continuation . 486))
(((in-block exception-handler)
- . 254)
+ . 486)
((in-block exception "")
- . 132))
+ . 364))
(((block-end toplevel-block "")
- . 25)
+ . 62)
((in-begin-block toplevel-block "")
- . 25))
+ . 62))
((toplevel . 1))
((comment-start . 1)
(toplevel . 1))
@@ -67,3 +96,4 @@
((comment-start . 1)
(toplevel . 1))
((toplevel . 1)))
+
diff --git a/test-data/pr28.sql b/test-data/pr28.sql
index cf8b88c..b8c3610 100644
--- a/test-data/pr28.sql
+++ b/test-data/pr28.sql
@@ -1,14 +1,23 @@
declare
- dummy number;
+ dummy number;
+ e_stop_program exception;
begin
begin
if 1 = 1 then
proc1;
proc2;
- else
+ elsif 1 = 2
proc3;
proc4;
+ else
+ raise e_stop_program;
end if;
+ case ind
+ when 1 then dummy := 'Guy';
+ when 2 then dummy := 'Abc';
+ when 3 then dummy := 'Def';
+ else dummy := 'World';
+ end case;
exception
when no_data_found then
proc1;
@@ -18,7 +27,7 @@ begin
proc4;
when others then
proc5;
- end;
+ end;
end;
/
-- Local Variables: