branch: externals/sql-indent commit 19745645855fefa8f2ffd7e70b41495b36a79fd2 Author: Alex Harsanyi <alexharsa...@gmail.com> Commit: Alex Harsányi <alex-...@users.noreply.github.com>
recognize elseif in addition to elif #81 --- sql-indent-test.el | 5 +++++ sql-indent.el | 16 ++++++++-------- test-data/pr81-syn.eld | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ test-data/pr81.sql | 17 +++++++++++++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/sql-indent-test.el b/sql-indent-test.el index 00048e0..c95590d 100644 --- a/sql-indent-test.el +++ b/sql-indent-test.el @@ -402,4 +402,9 @@ information read from DATA-FILE (as generated by "test-data/pr80.sql" "test-data/pr80-syn.eld")) +(ert-deftest sqlind-ert-pr81 () + (sqlind-ert-check-file-syntax + "test-data/pr81.sql" + "test-data/pr81-syn.eld")) + ;;; sql-indent-test.el ends here diff --git a/sql-indent.el b/sql-indent.el index b525474..d9d27af 100644 --- a/sql-indent.el +++ b/sql-indent.el @@ -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\\)\\_>\\|)" + ";\\|:=\\|\\_<\\(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))) @@ -321,6 +321,9 @@ But don't go before LIMIT." ((looking-at "cursor\\|for\\|while") ;; statement begins at the start of the keyword (throw 'done (point))) + ((looking-at "else?if") + ;; statement begins at the start of the keyword + (throw 'done (point))) ((looking-at "then\\|else") ;; then and else start statements when they are inside ;; blocks, not expressions. @@ -328,9 +331,6 @@ But don't go before LIMIT." (when (looking-at ";") ;; Statement begins after the keyword (throw 'done candidate-pos))) - ((looking-at "elsif") - ;; statement begins at the start of the keyword - (throw 'done (point))) ((looking-at "if") (when (sqlind-good-if-candidate) ;; statement begins at the start of the keyword @@ -886,7 +886,7 @@ See also `sqlind-beginning-of-block'" (defconst sqlind-start-block-regexp (concat "\\(\\_<" - (regexp-opt '("if" "then" "else" "elsif" "loop" + (regexp-opt '("if" "then" "else" "elsif" "elseif" "loop" "begin" "declare" "create" "alter" "exception" "procedure" "function" "end" "case") t) "\\_>\\)\\|)\\|\\$\\$") @@ -1310,7 +1310,7 @@ KIND is the symbol determining the type of the block ('if, 'loop, (list 'block-end start-kind start-label))) anchor)))) - ((memq block-kind '(else elsif)) + ((memq block-kind '(else elsif elseif)) ;; search the enclosing then context and refine form there. The ;; `cdr' in sqlind-syntax-of-line is used to remove the ;; block-start context for the else clause @@ -1493,8 +1493,8 @@ not a statement-continuation POS is the same as the ;; create block start syntax if needed ((and (eq syntax-symbol 'in-block) - (memq (nth 1 syntax) '(if elsif then case)) - (looking-at "\\(then\\|\\(els\\(e\\|if\\)\\)\\)\\_>")) + (memq (nth 1 syntax) '(if elsif elseif then case)) + (looking-at "\\(then\\|\\(els\\(e\\|e?if\\)\\)\\)\\_>")) (let ((what (intern (sqlind-match-string 0)))) ;; the only invalid combination is a then statement in ;; an (in-block "then") context diff --git a/test-data/pr81-syn.eld b/test-data/pr81-syn.eld new file mode 100644 index 0000000..8e8abac --- /dev/null +++ b/test-data/pr81-syn.eld @@ -0,0 +1,48 @@ +(((toplevel . 1)) + ((select-clause . 5) + (nested-statement-continuation . 4) + (statement-continuation . 4)) + ((select-clause . 5) + (nested-statement-continuation . 4) + (statement-continuation . 4)) + (((block-start then) + . 1) + ((in-block if "") + . 1)) + (((in-block then "") + . 70)) + (((block-start elsif) + . 70) + ((in-block then "") + . 70)) + (((in-block elsif "") + . 97)) + (((block-end if "") + . 70) + ((in-block elsif "") + . 97)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 139) + (nested-statement-continuation . 138) + (statement-continuation . 138)) + ((select-clause . 139) + (nested-statement-continuation . 138) + (statement-continuation . 138)) + (((block-start then) + . 135) + ((in-block if "") + . 135)) + (((in-block then "") + . 204)) + (((block-start elseif) + . 204) + ((in-block then "") + . 204)) + (((in-block else "") + . 231)) + (((block-end if "") + . 204) + ((in-block else "") + . 231)) + ((toplevel . 1))) \ No newline at end of file diff --git a/test-data/pr81.sql b/test-data/pr81.sql new file mode 100644 index 0000000..b554be0 --- /dev/null +++ b/test-data/pr81.sql @@ -0,0 +1,17 @@ +IF (SELECT ID + FROM SomeTable + WHERE SomeField > 0) IS NULL +THEN + SET SomeVar = TRUE; +ELSIF + SET SomeVar = FALSE; +END IF; + +IF (SELECT ID + FROM SomeTable + WHERE SomeField > 0) IS NULL +THEN + SET SomeVar = TRUE; +ELSEIF + SET SomeVar = FALSE; +END IF;