branch: externals/sql-indent commit d9442ed6a9212c5c2b4788952c02f6b89ad7a32b Author: Alex Harsányi <alex-...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
Recognize FULL JOIN, UNION ALL and EXCEPT keywords #73 (#74) * sql-indent.el (sqlind-select-clauses-regexp): match "UNION ALL" and "EXCEPT" as select clauses. (sqlind-select-join-regexp): match FULL JOIN keywords (sqlind-lineup-joins-to-anchor): use `sqlind-select-join-regexp` to match all join keywords. --- sql-indent-test.el | 3 +++ sql-indent.el | 6 +++--- test-data/pr73-syn.eld | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ test-data/pr73.sql | 34 +++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) diff --git a/sql-indent-test.el b/sql-indent-test.el index ef5d050..8912daf 100644 --- a/sql-indent-test.el +++ b/sql-indent-test.el @@ -384,4 +384,7 @@ information read from DATA-FILE (as generated by (ert-deftest sqlind-ert-pr70 () (sqlind-ert-check-file-syntax "test-data/pr70.sql" "test-data/pr70-syn.eld")) +(ert-deftest sqlind-ert-pr73 () + (sqlind-ert-check-file-syntax "test-data/pr73.sql" "test-data/pr73-syn.eld")) + ;;; sql-indent-test.el ends here diff --git a/sql-indent.el b/sql-indent.el index 4e0fd34..b2c03e3 100644 --- a/sql-indent.el +++ b/sql-indent.el @@ -948,7 +948,7 @@ reverse order (a stack) and is used to skip over nested blocks." (defconst sqlind-select-clauses-regexp (concat "\\_<\\(" - "\\(union\\|intersect\\|minus\\)?[ \t\r\n\f]*select\\|" + "\\(\\(union\\(\\s-+all\\)?\\)\\|intersect\\|minus\\|except\\)?[ \t\r\n\f]*select\\|" "\\(bulk[ \t\r\n\f]+collect[ \t\r\n\f]+\\)?into\\|" "from\\|" "where\\|" @@ -961,7 +961,7 @@ reverse order (a stack) and is used to skip over nested blocks." "\\)\\_>")) (defconst sqlind-select-join-regexp - (regexp-opt '("inner" "left" "right" "natural" "cross") 'symbols)) + (regexp-opt '("inner" "left" "right" "natural" "cross" "full") 'symbols)) (defconst sqlind-join-condition-regexp (regexp-opt '("on" "using" "and" "or") 'symbols)) @@ -2180,7 +2180,7 @@ it will indent lines starting with JOIN keywords to line up with the FROM keyword." (save-excursion (back-to-indentation) - (if (looking-at "\\b\\(\\(inner\\|outer\\|cross\\)\\s-+\\)?join\\b") + (if (looking-at (concat "\\b\\(" sqlind-select-join-regexp "\\s-+\\)?join\\b")) (sqlind-lineup-to-anchor syntax base-indentation) base-indentation))) diff --git a/test-data/pr73-syn.eld b/test-data/pr73-syn.eld new file mode 100644 index 0000000..330bff7 --- /dev/null +++ b/test-data/pr73-syn.eld @@ -0,0 +1,58 @@ +(((toplevel . 1)) + ((select-clause . 1) + (statement-continuation . 1)) + ((select-table-continuation . 12) + (statement-continuation . 1)) + ((select-join-condition . 30) + (statement-continuation . 1)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 76) + (statement-continuation . 76)) + ((select-clause . 76) + (statement-continuation . 76)) + ((select-clause . 76) + (statement-continuation . 76)) + ((select-clause . 76) + (statement-continuation . 76)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 127) + (statement-continuation . 127)) + ((select-clause . 127) + (statement-continuation . 127)) + ((select-clause . 127) + (statement-continuation . 127)) + ((select-clause . 127) + (statement-continuation . 127)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 178) + (statement-continuation . 178)) + ((select-clause . 178) + (statement-continuation . 178)) + ((select-clause . 178) + (statement-continuation . 178)) + ((select-clause . 178) + (statement-continuation . 178)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 233) + (statement-continuation . 233)) + ((select-clause . 233) + (statement-continuation . 233)) + ((select-clause . 233) + (statement-continuation . 233)) + ((select-clause . 233) + (statement-continuation . 233)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-clause . 284) + (statement-continuation . 284)) + ((select-clause . 284) + (statement-continuation . 284)) + ((select-clause . 284) + (statement-continuation . 284)) + ((select-clause . 284) + (statement-continuation . 284)) + ((toplevel . 1))) \ No newline at end of file diff --git a/test-data/pr73.sql b/test-data/pr73.sql new file mode 100644 index 0000000..aa4cda7 --- /dev/null +++ b/test-data/pr73.sql @@ -0,0 +1,34 @@ +select * + from foo + full join bar + on foo.k = bar.k; + +select id + from foo +except +select id + from bar; + +select id + from foo + union +select id + from bar; + +select id + from foo + union all +select id + from bar; + +select id + from foo + minus +select id + from bar; + +select id + from foo +intersect +select id + from bar;