This SO question covers the same general problem I have ... except that its answer is not detailed enough for me to understand what I must be doing wrong.
这个问题涵盖了我的一般问题……除了它的答案不够详细,我不能理解我做错了什么。
I am wanting to have sql files highlight any "CREATE PROCEDURE" commands.
我想让sql文件高亮显示任何“创建过程”命令。
I have the following file called sql-extension.tmLanguage
in Packages\User\
:
我有一个叫做sql-extension的文件。tmLanguage包\ \用户:
fileTypes
sql
name
XYZ
patterns
captures
1
name
keyword.other.create.sql
2
name
keyword.other.sql
5
name
entity.name.function.sql
match
(?i:^\s*(create)\s+(procedure)\s+)(['"`]?)(\w+)\4
name
meta.create.sql
include
#SQL
scopeName
source.sql
uuid
158e3bda-c76d-439e-b8ea-cb640f0a911c
I copied this information from the SQL.tmLanguage
file in the SQL
package for ST3. Its content is this:
我从SQL中复制了这些信息。ST3的SQL包中的tmLanguage文件。它的内容是这样的:
fileTypes
sql
ddl
dml
foldingStartMarker
\s*\(\s*$
foldingStopMarker
^\s*\)
keyEquivalent
^~S
name
SQL
patterns
include
#comments
captures
1
name
keyword.other.create.sql
2
name
keyword.other.sql
5
name
entity.name.function.sql
match
(?i:^\s*(create)\s+(aggregate|conversion|database|domain|function|group|(unique\s+)?index|language|operator class|operator|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)(['"`]?)(\w+)\4
name
meta.create.sql
captures
1
name
keyword.other.create.sql
2
name
keyword.other.sql
match
(?i:^\s*(drop)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|rule|schema|sequence|table|tablespace|trigger|type|user|view))
name
meta.drop.sql
captures
1
name
keyword.other.create.sql
2
name
keyword.other.table.sql
3
name
entity.name.function.sql
4
name
keyword.other.cascade.sql
match
(?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b)
name
meta.drop.sql
captures
1
name
keyword.other.create.sql
2
name
keyword.other.table.sql
match
(?i:^\s*(alter)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)
name
meta.alter.sql
captures
1
name
storage.type.sql
10
name
constant.numeric.sql
11
name
storage.type.sql
12
name
storage.type.sql
13
name
storage.type.sql
14
name
constant.numeric.sql
15
name
storage.type.sql
2
name
storage.type.sql
3
name
constant.numeric.sql
4
name
storage.type.sql
5
name
constant.numeric.sql
6
name
storage.type.sql
7
name
constant.numeric.sql
8
name
constant.numeric.sql
9
name
storage.type.sql
match
(?xi)
# normal stuff, capture 1
\b(bigint|bigserial|bit|boolean|box|bytea|cidr|circle|date|double\sprecision|inet|int|integer|line|lseg|macaddr|money|oid|path|point|polygon|real|serial|smallint|sysdate|text)\b
# numeric suffix, capture 2 + 3i
|\b(bit\svarying|character\s(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\)
# optional numeric suffix, capture 4 + 5i
|\b(char|number|varchar\d?)\b(?:\((\d+)\))?
# special case, capture 6 + 7i + 8i
|\b(numeric)\b(?:\((\d+),(\d+)\))?
# special case, captures 9, 10i, 11
|\b(times)(?:\((\d+)\))(\swithoutstimeszone\b)?
# special case, captures 12, 13, 14i, 15
|\b(timestamp)(?:(s)\((\d+)\)(\swithoutstimeszone\b)?)?
match
(?i:\b((?:primary|foreign)\s+key|references|on\sdelete(\s+cascade)?|check|constraint)\b)
name
storage.modifier.sql
match
\b\d+\b
name
constant.numeric.sql
match
(?i:\b(select(\s+distinct)?|insert\s+(ignore\s+)?into|update|delete|from|set|where|group\sby|or|like|and|union(\s+all)?|having|order\sby|limit|(inner|cross)\s+join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b)
name
keyword.other.DML.sql
match
(?i:\b(on|((is\s+)?not\s+)?null)\b)
name
keyword.other.DDL.create.II.sql
match
(?i:\bvalues\b)
name
keyword.other.DML.II.sql
match
(?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b)
name
keyword.other.LUW.sql
match
(?i:\b(grant(\swith\sgrant\soption)?|revoke)\b)
name
keyword.other.authorization.sql
match
(?i:\bin\b)
name
keyword.other.data-integrity.sql
match
(?i:^\s*(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+)
name
keyword.other.object-comments.sql
match
(?i)\bAS\b
name
keyword.other.alias.sql
match
(?i)\b(DESC|ASC)\b
name
keyword.other.order.sql
match
\*
name
keyword.operator.star.sql
match
[!<>]?=|<>|<|>
name
keyword.operator.comparison.sql
match
-|\+|/
name
keyword.operator.math.sql
match
\|\|
name
keyword.operator.concatenator.sql
comment
List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html
match
(?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b
name
support.function.scalar.sql
comment
List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html
match
(?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\()
name
support.function.aggregate.sql
match
(?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b
name
support.function.string.sql
captures
1
name
constant.other.database-name.sql
2
name
constant.other.table-name.sql
match
\b(\w+?)\.(\w+)\b
include
#strings
include
#regexps
repository
comments
patterns
captures
1
name
punctuation.definition.comment.sql
match
(--).*$\n?
name
comment.line.double-dash.sql
captures
1
name
punctuation.definition.comment.sql
match
(#).*$\n?
name
comment.line.number-sign.sql
begin
/\*
captures
0
name
punctuation.definition.comment.sql
end
\*/
name
comment.block.c
regexps
patterns
begin
/(?=\S.*/)
beginCaptures
0
name
punctuation.definition.string.begin.sql
end
/
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.regexp.sql
patterns
include
#string_interpolation
match
\\/
name
constant.character.escape.slash.sql
begin
%r\{
beginCaptures
0
name
punctuation.definition.string.begin.sql
comment
We should probably handle nested bracket pairs!?! -- Allan
end
\}
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.regexp.modr.sql
patterns
include
#string_interpolation
string_escape
match
\\.
name
constant.character.escape.sql
string_interpolation
captures
1
name
punctuation.definition.string.end.sql
match
(#\{)([^\}]*)(\})
name
string.interpolated.sql
strings
patterns
captures
1
name
punctuation.definition.string.begin.sql
3
name
punctuation.definition.string.end.sql
comment
this is faster than the next begin/end rule since sub-pattern will match till end-of-line and SQL files tend to have very long lines.
match
(')[^'\\]*(')
name
string.quoted.single.sql
begin
'
beginCaptures
0
name
punctuation.definition.string.begin.sql
end
'
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.quoted.single.sql
patterns
include
#string_escape
captures
1
name
punctuation.definition.string.begin.sql
3
name
punctuation.definition.string.end.sql
comment
this is faster than the next begin/end rule since sub-pattern will match till end-of-line and SQL files tend to have very long lines.
match
(`)[^`\\]*(`)
name
string.quoted.other.backtick.sql
begin
`
beginCaptures
0
name
punctuation.definition.string.begin.sql
end
`
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.quoted.other.backtick.sql
patterns
include
#string_escape
captures
1
name
punctuation.definition.string.begin.sql
3
name
punctuation.definition.string.end.sql
comment
this is faster than the next begin/end rule since sub-pattern will match till end-of-line and SQL files tend to have very long lines.
match
(")[^"#]*(")
name
string.quoted.double.sql
begin
"
beginCaptures
0
name
punctuation.definition.string.begin.sql
end
"
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.quoted.double.sql
patterns
include
#string_interpolation
begin
%\{
beginCaptures
0
name
punctuation.definition.string.begin.sql
end
\}
endCaptures
0
name
punctuation.definition.string.end.sql
name
string.other.quoted.brackets.sql
patterns
include
#string_interpolation
scopeName
source.sql
uuid
C49120AC-6ECC-11D9-ACC8-000D93589AF6
I got the uuid from typing the following in the console:
我通过在控制台输入以下内容获得uuid:
import uuid
u = uuid.uuid4()
and then copy/pasting the UUID created into the file.
然后将创建的UUID复制/粘贴到文件中。
After saving the file and viewing a sql file, I get this (notice that the words "CREATE PROCEDURE" are not highlighted):
保存文件并查看sql文件之后,我得到了这个(注意“创建过程”这个词没有突出显示):
So what am I doing wrong?
我做错了什么?
EXTRA NOTE:
额外的注意:
the AAAPackageDev package does not seem to work in ST3. All the menu options are greyed out.
AAAPackageDev包在ST3中似乎不起作用。所有的菜单选项都是灰色的。
3
For the following, I'm guessing you are using Windows, but if you aren't let me know (or find the command yourself). First, for the sake of demonstration, place the cursor over TABLE
. Then press ctrl+alt+shift+p
. In the status bar you will notice some text appear (something like source.sql meta.create.sql keyword.other.sql
). This is the scope being applied to that word. The scope, along with your tmTheme file, define how it will be colored. Now place the cursor over PROCEDURE
and repeat. You should see something similar to the scopes previously seen. If not, there is likely something wrong with your regular expression.
下面,我猜您正在使用Windows,但是如果您不让我知道(或者您自己找到命令)。首先,为了演示,将光标放在表上。然后按ctrl + alt + shift + p。在状态栏中,您将注意到出现了一些文本(类似于source)。sql meta.create。sql keyword.other.sql)。这就是这个词的作用域。作用域和tmTheme文件一起定义它的颜色。现在将光标放在过程上并重复。您应该看到与前面看到的范围类似的内容。如果不是,你的正则表达式可能有问题。
Oh, I would also add SQL to your ignored_packages
setting if you haven't already. This will ensure that your syntax file is being used, not the built in one. You will probably want to copy out the contents of that package too as they probably provide some additional functionality.
哦,如果还没有的话,我还会向ignored_packages设置添加SQL。这将确保使用的是语法文件,而不是内置文件。您可能也希望复制该包的内容,因为它们可能提供一些附加功能。
AAAPackageDev is not compatible with ST3. ST3 uses Python3, whereas ST2 used Python2. So I wouldn't blindly expect a plugin to be compatible with both. Anyways, I'll try to provide some guidance on syntax highlighting (I'm no expert though). The first thing worth checking is that your regular expressions are correct. That is, you need to ensure the proper scopes are being applied to CREATE PROCEDURE
.
AAAPackageDev与ST3不兼容。ST3使用Python3,而ST2使用Python2。所以我不会盲目地期望一个插件同时兼容这两个。无论如何,我将尝试提供一些语法高亮的指导(尽管我不是专家)。首先值得检查的是正则表达式是正确的。也就是说,您需要确保应用了适当的作用域来创建过程。
In case you like to work in JSON rather than XML, take a look at PlistJsonConverter. It is compatible with ST3, though you will need to use the ST3 branch of it.
如果您喜欢使用JSON而不是XML,请查看PlistJsonConverter。它与ST3兼容,但是您需要使用它的ST3分支。
Edit Leads me to believe there is something wrong with your regex. Is there any reason you don't just change
编辑让我相信你的正则表达式有问题。你有什么理由不去改变吗
(?i:^\s*(create)\s+(aggregate|conversion|database|domain|function|group|(unique\s+)?index|language|operator class|operator|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)(['"`]?)(\w+)\4
to
来
(?i:^\s*(create)\s+(aggregate|conversion|database|domain|function|group|(unique\s+)?index|language|operator class|operator|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)(['"`]?)(\w+)\4
I simply added procedure
to an existing regex pattern.
我只是向现有的regex模式添加了过程。