-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mode refinements in recognizing declare statements (#92)
* sql-indent.el (sqlind-maybe-declare-statement): recognize declare statements in begin blocks, then and else blocks. (sqlind-refine-syntax): don't nest declare statements
- Loading branch information
Showing
5 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(((comment-start . 1) | ||
(toplevel . 1)) | ||
((toplevel . 1)) | ||
((toplevel . 1)) | ||
(((in-begin-block defun "less_than") | ||
. 47)) | ||
(((in-begin-block defun "less_than") | ||
. 47)) | ||
(((in-begin-block defun "less_than") | ||
. 47)) | ||
((statement-continuation . 171)) | ||
((declare-statement . 113)) | ||
(((block-start begin) | ||
. 113) | ||
(declare-statement . 113)) | ||
(((in-begin-block toplevel-block "") | ||
. 227)) | ||
(((block-end toplevel-block "") | ||
. 227) | ||
((in-begin-block toplevel-block "") | ||
. 227)) | ||
(((block-end defun "less_than") | ||
. 47) | ||
((in-begin-block defun "less_than") | ||
. 47)) | ||
((toplevel . 1)) | ||
((toplevel . 1)) | ||
(((in-begin-block defun "less_than") | ||
. 292)) | ||
(((in-begin-block nil "") | ||
. 358)) | ||
((declare-statement . 368)) | ||
((declare-statement . 368)) | ||
(((block-start begin) | ||
. 368) | ||
(declare-statement . 368)) | ||
(((in-begin-block toplevel-block "") | ||
. 430)) | ||
(((block-end toplevel-block "") | ||
. 430) | ||
((in-begin-block toplevel-block "") | ||
. 430)) | ||
(((block-end nil "") | ||
. 358) | ||
((in-begin-block nil "") | ||
. 358)) | ||
(((block-end defun "less_than") | ||
. 292) | ||
((in-begin-block defun "less_than") | ||
. 292)) | ||
((toplevel . 1)) | ||
((toplevel . 1)) | ||
(((in-begin-block defun "less_than") | ||
. 506)) | ||
(((in-begin-block nil "") | ||
. 572)) | ||
(((in-block if "") | ||
. 582)) | ||
((declare-statement . 606)) | ||
(((block-start begin) | ||
. 606) | ||
(declare-statement . 606)) | ||
(((in-begin-block toplevel-block "") | ||
. 645)) | ||
(((block-end toplevel-block "") | ||
. 645) | ||
((in-begin-block toplevel-block "") | ||
. 645)) | ||
(((block-start else) | ||
. 582) | ||
((in-block if "") | ||
. 582)) | ||
(((in-block else "") | ||
. 688)) | ||
((declare-statement . 699)) | ||
((declare-statement . 699)) | ||
(((block-start begin) | ||
. 699) | ||
(declare-statement . 699)) | ||
(((in-begin-block toplevel-block "") | ||
. 767)) | ||
(((block-end toplevel-block "") | ||
. 767) | ||
((in-begin-block toplevel-block "") | ||
. 767)) | ||
(((block-end if "") | ||
. 582) | ||
((in-block else "") | ||
. 688)) | ||
(((block-end nil "") | ||
. 572) | ||
((in-begin-block nil "") | ||
. 572)) | ||
(((block-end defun "less_than") | ||
. 506) | ||
((in-begin-block defun "less_than") | ||
. 506)) | ||
((toplevel . 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- -*- mode: sql; sql-product: postgres; -*- | ||
|
||
create function less_than(a text, b text) returns boolean as $$ | ||
declare local_a text := a; | ||
declare local_b text := b; | ||
declare | ||
local_d text := d; | ||
local_c text := c; | ||
begin | ||
return local_a < local_b; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create function less_than(a text, b text) returns boolean as $$ | ||
begin | ||
declare | ||
local_a text := a; | ||
local_b text := b; | ||
begin | ||
return local_a < local_b; | ||
end; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create function less_than(a text, b text) returns boolean as $$ | ||
begin | ||
if a is null then | ||
declare | ||
local_a text: a; | ||
begin | ||
return false; | ||
end; | ||
else | ||
declare | ||
local_a text := a; | ||
local_b text := b; | ||
begin | ||
return local_a < local_b; | ||
end; | ||
end if; | ||
end; | ||
$$ language plpgsql; |
Unfortunately, detecting the previous token is kind of a hack. It isn’t robust against all the places a
DECLARE
+BEGIN
can show up, which is basically anywhere:This is why I suggested that you might need some kind of
sqlind-in-function
orsqlind-in-declare
to determine when you are actually in a declare block?cc: #92