Skip to content

Commit 0446f28

Browse files
committed
highlight sqlplus define variables as preprocessor. Add examples to test file
1 parent d45635a commit 0446f28

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ describes how I came to create this repository.
3535

3636
## plsql.vim syntax file
3737

38-
The syntax file replaces the functionality of the *plsql.vim* file that ships with vim (it was last updated
38+
The syntax file replaces the functionality of the *plsql.vim* file that ships with vim versions 8 and earlier (it was last updated
3939
for Oracle 9).
4040

41-
> Release v20220503_1.3 (tag r1.3) of this syntax file was submitted to the *vim* maintainers for inclusion in *vim* version 9.
42-
4341
> Release v20220821_1.4 (tag r1.4) of this syntax file was submitted to the *vim* maintainers for inclusion in *vim* version 9.
4442
43+
> Release v20220924_1.5 (tag r1.5) of this syntax file was submitted to the *vim* maintainers for inclusion in *vim* verison 9.
44+
4545
Relative to the original *plsql.vim*, this update adds keywords and syntax through Oracle version 19c.
4646
It fixes Q-quote operator syntax, exponential notation and assorted oddities, plus
4747
adds optional folding.
@@ -55,6 +55,7 @@ original behavior, add the following to your *.vimrc* file:
5555
```vim
5656
let plsql_legacy_sql_keywords = 1
5757
```
58+
We also added highlighting for some *SqlPlus* commands and define variables.
5859

5960
### Folding
6061

syntax/plsql.vim

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ syn case ignore
5757

5858
syn match plsqlGarbage "[^ \t()]"
5959
syn match plsqlIdentifier "[a-z][a-z0-9$_#]*"
60+
syn match plsqlSqlPlusDefine "&&\?[a-z][a-z0-9$_#]*\.\?"
6061
syn match plsqlHostIdentifier ":[a-z][a-z0-9$_#]*"
6162

6263
" The Non-Breaking is often accidentally typed (Mac User: Opt+Space, after typing the "|", Opt+7);
@@ -86,7 +87,6 @@ syn match plsqlOperator "\<IS\\_s\+\(NOT\_s\+\)\?NULL\>"
8687
"
8788
" conditional compilation Preprocessor directives and sqlplus define sigil
8889
syn match plsqlPseudo "$[$a-z][a-z0-9$_#]*"
89-
syn match plsqlPseudo "&"
9090

9191
syn match plsqlReserved "\<\(CREATE\|THEN\|UPDATE\|INSERT\|SET\)\>"
9292
syn match plsqlKeyword "\<\(REPLACE\|PACKAGE\|FUNCTION\|PROCEDURE\|TYPE|BODY\|WHEN\|MATCHED\)\>"
@@ -591,18 +591,18 @@ syn match plsqlEND "\<END\>"
591591
syn match plsqlISAS "\<\(IS\|AS\)\>"
592592

593593
" Various types of comments.
594-
syntax region plsqlCommentL start="--" skip="\\$" end="$" keepend extend contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace
594+
syntax region plsqlCommentL start="--" skip="\\$" end="$" keepend extend contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
595595
if get(g:,"plsql_fold",0) == 1
596596
syntax region plsqlComment
597597
\ start="/\*" end="\*/"
598598
\ extend
599-
\ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace
599+
\ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
600600
\ fold
601601
else
602602
syntax region plsqlComment
603603
\ start="/\*" end="\*/"
604604
\ extend
605-
\ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace
605+
\ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
606606
endif
607607
syn cluster plsqlCommentAll contains=plsqlCommentL,plsqlComment
608608

@@ -625,23 +625,23 @@ syn match plsqlFloatLiteral contained "\.\(\d\+\([eE][+-]\?\d\+\)\?\)[fd]\?"
625625
" double quoted strings in SQL are database object names. Should be a subgroup of Normal.
626626
" We will use Character group as a proxy for that so color can be chosen close to Normal
627627
syn region plsqlQuotedIdentifier matchgroup=plsqlOperator start=+n\?"+ end=+"+ keepend extend
628-
syn cluster plsqlIdentifiers contains=plsqlIdentifier,plsqlQuotedIdentifier
628+
syn cluster plsqlIdentifiers contains=plsqlIdentifier,plsqlQuotedIdentifier,plsqlSqlPlusDefine
629629

630630
" quoted string literals
631631
if get(g:,"plsql_fold",0) == 1
632-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?'+ skip=+''+ end=+'+ fold keepend extend
633-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\z([^[(<{]\)+ end=+\z1'+ fold keepend extend
634-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'<+ end=+>'+ fold keepend extend
635-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'{+ end=+}'+ fold keepend extend
636-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'(+ end=+)'+ fold keepend extend
637-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\[+ end=+]'+ fold keepend extend
632+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?'+ skip=+''+ end=+'+ contains=plsqlSqlplusDefine fold keepend extend
633+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\z([^[(<{]\)+ end=+\z1'+ contains=plsqlSqlplusDefine fold keepend extend
634+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'<+ end=+>'+ contains=plsqlSqlplusDefine fold keepend extend
635+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'{+ end=+}'+ contains=plsqlSqlplusDefine fold keepend extend
636+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'(+ end=+)'+ contains=plsqlSqlplusDefine fold keepend extend
637+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\[+ end=+]'+ contains=plsqlSqlplusDefine fold keepend extend
638638
else
639-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?'+ skip=+''+ end=+'+
640-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\z([^[(<{]\)+ end=+\z1'+
641-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'<+ end=+>'+
642-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'{+ end=+}'+
643-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'(+ end=+)'+
644-
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\[+ end=+]'+
639+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?'+ skip=+''+ end=+'+ contains=plsqlSqlplusDefine
640+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\z([^[(<{]\)+ end=+\z1'+ contains=plsqlSqlplusDefine
641+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'<+ end=+>'+ contains=plsqlSqlplusDefine
642+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'{+ end=+}'+ contains=plsqlSqlplusDefine
643+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'(+ end=+)'+ contains=plsqlSqlplusDefine
644+
syn region plsqlStringLiteral matchgroup=plsqlOperator start=+n\?q'\[+ end=+]'+ contains=plsqlSqlplusDefine
645645
endif
646646

647647
syn keyword plsqlBooleanLiteral TRUE FALSE
@@ -839,6 +839,7 @@ hi def link plsqlTypeAttribute StorageClass
839839
hi def link plsqlTodo Todo
840840

841841
hi def link plsqlIllegalSpace Error
842+
hi def link plsqlSqlPlusDefine PreProc
842843
hi def link plsqlSqlPlusCommand PreProc
843844
hi def link plsqlSqlPlusRunFile Include
844845
hi def link plsqlSqlPlusCommentL Comment

test/plsql.pls

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
REM a sqlplus comment
2+
prompt set this to anything you want
3+
define literal_keyword="whatever dude"
4+
whenever sqlerror then failure
15
().,;
2-
SELECT e.first_name AS "First Name", e.last_name AS "Last Name"
6+
SELECT
7+
e.first_name AS "First Name", e.last_name AS "Last Name"
38
, d.department_name AS "Department
49
Name"
5-
, 'a string with embedded quote ('')' as regq, q'{a string with embedded quote (')}' as qquote
10+
, 'a &literal_keyword string with embedded quote ('')' as regq, q'{a &&literal_keyword. string with embedded quote (')}' as qquote
611
, 'a string ending in a quote ''' as "regq_end_quote XXX", 'xxx' AS XXX
712
, 123 AS "integer val" , .7 as "trailing dec", 123. as "really an int but classified float"
813
, 123.456 as "float" , 1.27E-2 as "exp not"
@@ -12,8 +17,8 @@ Name"
1217
, +123 AS "p integer val" , +.7 as "p trailing dec", +123.F as "p really an int but classified float"
1318
, +123.456f as "p float", -123.456d as "p_double" , +1.27E2D as "p exp not double"
1419
-- TODO XXX DEBUG NOTE FIXME
15-
FROM hr.employees e
16-
JOIN hr.departments d
20+
FROM &hr_schema..employees e
21+
JOIN &&hr_schema..departments d
1722
ON e.department_id = d.department_id
1823
WHERE e.first_name = 'Bruce' AND e.last_name = 'Lee'
1924
ORDER BY d.department_name;

0 commit comments

Comments
 (0)