[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/sql-indent dc59fdc 1/4: recognize implicit JOIN clauses
From: |
Stefan Monnier |
Subject: |
[elpa] externals/sql-indent dc59fdc 1/4: recognize implicit JOIN clauses (fixes #64) (#65) |
Date: |
Thu, 25 Oct 2018 08:37:07 -0400 (EDT) |
branch: externals/sql-indent
commit dc59fdce5b72dfd2ff7cbd6b0460ab71f4a51768
Author: Alex Harsányi <address@hidden>
Commit: GitHub <address@hidden>
recognize implicit JOIN clauses (fixes #64) (#65)
... these are JOIN clauses without an explicit INNER, LEFT, RIGHT, etc.
---
sql-indent-test.el | 3 ++
sql-indent.el | 43 ++++++++++++-----------
test-data/pr64-syn.eld | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++
test-data/pr64.sql | 53 ++++++++++++++++++++++++++++
4 files changed, 172 insertions(+), 20 deletions(-)
diff --git a/sql-indent-test.el b/sql-indent-test.el
index 4152c0a..0cc3be1 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -369,4 +369,7 @@ information read from DATA-FILE (as generated by
(ert-deftest sqlind-ert-pr60 ()
(sqlind-ert-check-file-syntax "test-data/pr60.sql" "test-data/pr60-syn.eld"))
+(ert-deftest sqlind-ert-pr64 ()
+ (sqlind-ert-check-file-syntax "test-data/pr64.sql" "test-data/pr64-syn.eld"))
+
;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index cca9c85..a928310 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -939,10 +939,7 @@ reverse order (a stack) and is used to skip over nested
blocks."
"\\)\\_>"))
(defconst sqlind-select-join-regexp
- (concat "\\b"
- (regexp-opt '("inner" "left" "right" "natural" "cross") t)
- "[ \t\r\n\f]*join"
- "\\b"))
+ (regexp-opt '("inner" "left" "right" "natural" "cross") 'symbols))
(defun sqlind-syntax-in-select (pos start)
"Return the syntax ar POS which is inside a \"select\" statement at START."
@@ -991,22 +988,28 @@ reverse order (a stack) and is used to skip over nested
blocks."
(when (or (looking-at "on")
(progn (forward-word -1) (looking-at "on")))
;; look for the join start, that will be the anchor
- (when (sqlind-search-backward (point)
sqlind-select-join-regexp start)
- (throw 'finished
- (cons 'select-join-condition (point))))))
-
- ;; if this line starts with a ',' or the previous
- ;; line starts with a ',', we have a new table
- (goto-char pos)
- (when (or (looking-at ",")
- (progn
- (sqlind-backward-syntactic-ws)
- (looking-at ",")))
- (throw 'finished (cons 'select-table match-pos)))
-
- ;; otherwise, we continue the table definition from
- ;; the previous line.
- (throw 'finished (cons 'select-table-continuation match-pos)))
+ (when (sqlind-search-backward (point) "\\bjoin\\b" start)
+ (let ((candidate (point)))
+ (forward-char -1)
+ (sqlind-backward-syntactic-ws)
+ (backward-word)
+ (throw 'finished
+ (if (looking-at sqlind-select-join-regexp)
+ (cons 'select-join-condition (point))
+ (cons 'select-join-condition candidate)))))))
+
+ ;; if this line starts with a ',' or the previous line starts
+ ;; with a ',', we have a new table
+ (goto-char pos)
+ (when (or (looking-at ",")
+ (progn
+ (sqlind-backward-syntactic-ws)
+ (looking-at ",")))
+ (throw 'finished (cons 'select-table match-pos)))
+
+ ;; otherwise, we continue the table definition from the
+ ;; previous line.
+ (throw 'finished (cons 'select-table-continuation match-pos)))
(t
(throw 'finished
diff --git a/test-data/pr64-syn.eld b/test-data/pr64-syn.eld
new file mode 100644
index 0000000..9b77dc5
--- /dev/null
+++ b/test-data/pr64-syn.eld
@@ -0,0 +1,93 @@
+(((toplevel . 1))
+ ((select-clause . 1)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 29)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 70)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 111)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 151)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 192)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 233)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((select-join-condition . 276)
+ (statement-continuation . 1))
+ ((select-table-continuation . 12)
+ (statement-continuation . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 314)
+ (statement-continuation . 314))
+ ((select-table-continuation . 325)
+ (statement-continuation . 314))
+ ((select-join-condition . 342)
+ (statement-continuation . 314))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 376)
+ (statement-continuation . 376))
+ ((select-table-continuation . 387)
+ (statement-continuation . 376))
+ ((select-join-condition . 404)
+ (statement-continuation . 376))
+ ((select-table-continuation . 387)
+ (statement-continuation . 376))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 447)
+ (statement-continuation . 447))
+ ((select-table-continuation . 458)
+ (statement-continuation . 447))
+ ((select-join-condition . 475)
+ (statement-continuation . 447))
+ ((select-table-continuation . 458)
+ (statement-continuation . 447))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 519)
+ (statement-continuation . 519))
+ ((select-table-continuation . 530)
+ (statement-continuation . 519))
+ ((select-join-condition . 547)
+ (statement-continuation . 519))
+ ((select-table-continuation . 530)
+ (statement-continuation . 519))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 591)
+ (statement-continuation . 591))
+ ((select-table-continuation . 602)
+ (statement-continuation . 591))
+ ((select-join-condition . 619)
+ (statement-continuation . 591))
+ ((select-table-continuation . 602)
+ (statement-continuation . 591))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((select-clause . 666)
+ (statement-continuation . 666))
+ ((select-table-continuation . 677)
+ (statement-continuation . 666))
+ ((select-join-condition . 694)
+ (statement-continuation . 666))
+ ((select-table-continuation . 677)
+ (statement-continuation . 666))
+ ((toplevel . 1)))
\ No newline at end of file
diff --git a/test-data/pr64.sql b/test-data/pr64.sql
new file mode 100644
index 0000000..b69c90d
--- /dev/null
+++ b/test-data/pr64.sql
@@ -0,0 +1,53 @@
+select *
+ from T1
+ inner join T2
+ on a
+ cross join T3
+ on b
+ left join T4
+ on c
+ right join T5
+ on d
+ cross join T6
+ on e
+ natural join T7
+ on f
+ join T8
+ on g
+ ;
+
+select *
+ from T1
+ inner join T2
+ on a;
+
+select *
+ from T1
+ left join T2
+ on a
+ ;
+
+select *
+ from T1
+ right join T2
+ on a
+ ;
+
+select *
+ from T1
+ cross join T2
+ on a
+ ;
+
+select *
+ from T1
+ natural join T2
+ on a
+ ;
+
+
+select *
+ from T1
+ join T2
+ on a
+ ;