This was my first stab at editing a language definition. I tried to add "COPY" support as well, but couldn't get it to work for whatever reason. This version supports most keywords in the spec. I'll try and add better stored procedure/function support as well as get copy working and respam.
'njoy, Mark
{ scopeName = "source.sql"; fileTypes = ( "sql", "ddl", "dml" ); foldingStartMarker = "\s*\(\s*$"; foldingStopMarker = "^\s*\)"; patterns = ( { name = "declaration.create.sql"; match = "(?i:^\s*(create)\s+(aggregate|conversion|database|domain|function|group|(unique\s+)?index|language|operator|operator class|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)(\w+)"; captures = { 1 = { name = "keyword.function.create.sql"; }; 2 = { name = "keyword.other.sql"; }; 4 = { name = "entity.name.function.sql"; }; }; }, { name = "keyword.other.DDL.create.II.sql"; match = "(?i:\s+(on\s+|(not\s+)?null)\b)"; }, { name = "declaration.drop.sql"; match = "(?i:^\s*(drop)\s+(aggregate|conversion|database|domain|function|group|index|language|operator|operator class|rule|schema|sequence|table|tablespace|trigger|type|user|view))"; captures = { 1 = { name = "support.function.create.sql"; }; 2 = { name = "keyword.other.sql"; }; }; }, { name = "declaration.drop.sql"; match = "(?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b)"; captures = { 1 = { name = "support.function.create.sql"; }; 2 = { name = "keyword.other.table.sql"; }; 3 = { name = "entity.name.function.sql"; }; 4 = { name = "keyword.other.cascade.sql"; }; }; }, { name = "declaration.alter.sql"; match = "(?i:^\s*(alter)\s+(aggregate|conversion|database|domain|function|group|index|language|operator|operator class|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+)"; captures = { 1 = { name = "support.function.create.sql"; }; 2 = { name = "keyword.other.table.sql"; }; }; }, { name = "keyword.other.DML.sql"; match = "(?i:^\s*([\(]{0,}select(\s+distinct)?|insert\s+into|update|delete|from|where|group\sby|and|union(\s+all)?|having|order\sby)\b)"; }, { name = "keyword.other.DML.II.sql"; match = "(?i:\s+values\s+)"; }, { name = "keyword.other.sql.LUW.sql"; match = "(?i:(begin(\s+work)?|commit(\s+work)?|rollback(\s+work)?))"; }, { name = "keyword.other.authorization.sql"; match = "(?i:(grant(\swith\sgrant\soption)?|revoke))"; }, { name = "storage.type.sql"; match = "(?i:^\s*([A-Za-z0-9'_])+\s+(bigint|bigserial|bit|bit\svarying\(\d+\)|boolean|box|bytea|character\s(varying)?\(\d+\)|char\(\d+\)|var\schar\(\d+\)|cidr|circle|date|double\sprecision|inet|int|integer|interval\(\d+\)|line|lseg|macaddr|money|numeric(\(\d+,\d+\))?|oid|path|point|polygon|real|smallint|serial|text|times(\(\d+\))(\swithoutstimeszone)?|timestamp(s(\(\d+\))(\swithoutstimeszone)?)?|varchar(\(\d+\))?)\s*)"; }, { name = "storage.modifier.sql"; match = "(?i:\b(primary\s+key|references|on\sdelete(\s+cascade)?|check)\b)"; }, { name = "keyword.other.data-integrity.sql"; match = "(?i:\bin\b)"; }, { name = "string.quoted.single.sql"; begin = "'"; end = "'"; swallow = "\\."; }, { name = "keyword.other.object-comments.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 = "comment.line.double-dash.sql"; match = "--.*$"; }, { name = "string.quoted.double.sql"; begin = """; end = """; patterns = ( { name = "string.interpolation.sql"; match = "#\{([^\}]*)\}"; } ); }, { name = "string.quoted.double.sql"; begin = "%\{"; end = "\}"; patterns = ( { name = "string.interpolation.sql"; match = "#\{([^\}]*)\}"; } ); }, { name = "string.regexp.sql"; begin = "/(?=\S.*/)"; end = "/"; patterns = ( { name = "string.interpolation.sql"; match = "#\{([^\}]*)\}"; }, { name = "string.escaped-slash.sql"; match = "\\/"; }, ); }, { name = "string.regexp.modr.sql"; begin = "%r\{"; end = "\}"; patterns = ( { name = "string.interpolation.sql"; match = "#\{([^\}]*)\}"; }, { name = "constant.character.escaped.slash.sql"; match = "\\/"; }, ); }, ); increaseIndentPattern = "^\s*(create|grant|insert|delete|update)\s*"; }
On 31/07/2005, at 13.34, Mark Cotner wrote:
This was my first stab at editing a language definition. I tried to add "COPY" support as well, but couldn't get it to work for whatever reason. This version supports most keywords in the spec. I'll try and add better stored procedure/function support as well as get copy working and respam.
Thanks, I updated the version in the repository. I changed keyword.function.create to keyword.other.create (to use an official name) but probably many of the current SQL names should be changed. e.g. NOT is an operator and NULL is a constant IMHO (both marked up as keywords currently).
Personally though I have close to no experience with SQL syntax, which is probably why most stuff ended up as keywords ;)
I also added support for # comments, `strings` and allowed for the name in the create table statement to be quoted (this name appears in the symbol popup btw). And I moved the increase-indent pattern to a bundle preferences item.
You can grab the updated SQL syntax from here (or do a svn checkout of the SQL bundle): http://macromates.com/svn/Bundles/trunk/Bundles/SQL.tmbundle/ Syntaxes/SQL.plist