热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

扩展崇高的文本3的sql语法-extendsublimetext3'ssqlsyntax

ThisSOquestioncoversthesamegeneralproblemIhaveexceptthatitsanswerisnotdetailede

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文件之后,我得到了这个(注意“创建过程”这个词没有突出显示):

enter image description here

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中似乎不起作用。所有的菜单选项都是灰色的。

1 个解决方案

#1


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模式添加了过程。


推荐阅读
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了Perl的测试框架Test::Base,它是一个数据驱动的测试框架,可以自动进行单元测试,省去手工编写测试程序的麻烦。与Test::More完全兼容,使用方法简单。以plural函数为例,展示了Test::Base的使用方法。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了Linux Shell中括号和整数扩展的使用方法,包括命令组、命令替换、初始化数组以及算术表达式和逻辑判断的相关内容。括号中的命令将会在新开的子shell中顺序执行,括号中的变量不能被脚本余下的部分使用。命令替换可以用于将命令的标准输出作为另一个命令的输入。括号中的运算符和表达式符合C语言运算规则,可以用在整数扩展中进行算术计算和逻辑判断。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 延迟注入工具(python)的SQL脚本
    本文介绍了一个延迟注入工具(python)的SQL脚本,包括使用urllib2、time、socket、threading、requests等模块实现延迟注入的方法。该工具可以通过构造特定的URL来进行注入测试,并通过延迟时间来判断注入是否成功。 ... [详细]
  • 本文介绍了在Windows系统上使用C语言命令行参数启动程序并传递参数的方法,包括接收参数程序的代码和bat文件的编写方法,同时给出了程序运行的结果。 ... [详细]
  • 本文详细介绍了git常用命令及其操作方法,包括查看、添加、提交、删除、找回等操作,以及如何重置修改文件、抛弃工作区修改、将工作文件提交到本地暂存区、从版本库中删除文件等。同时还介绍了如何从暂存区恢复到工作文件、恢复最近一次提交过的状态,以及如何合并多个操作等。 ... [详细]
  • 基于Socket的多个客户端之间的聊天功能实现方法
    本文介绍了基于Socket的多个客户端之间实现聊天功能的方法,包括服务器端的实现和客户端的实现。服务器端通过每个用户的输出流向特定用户发送消息,而客户端通过输入流接收消息。同时,还介绍了相关的实体类和Socket的基本概念。 ... [详细]
author-avatar
du-qhy
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有