SQL.sublime-syntax (9097B)
1 %YAML 1.2 2 --- 3 name: SQL 4 file_extensions: 5 - sql 6 - ddl 7 - dml 8 scope: source.sql 9 10 variables: 11 end_identifier: (?=[ \t]*(?:[^\w'"`. \t]|$)) 12 13 contexts: 14 main: 15 - include: comments 16 - match: |- 17 (?xi) 18 \b(create(?:\s+or\s+replace)?)\s+ 19 (aggregate|conversion|database|domain|function|group|(?:unique\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) 20 \b\s* 21 scope: meta.create.sql 22 captures: 23 1: keyword.other.create.sql 24 2: keyword.other.sql 25 push: identifier_create 26 - match: (?i:\s*\b(drop)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)) 27 scope: meta.drop.sql 28 captures: 29 1: keyword.other.create.sql 30 2: keyword.other.sql 31 - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) 32 scope: meta.drop.sql 33 captures: 34 1: keyword.other.create.sql 35 2: keyword.other.table.sql 36 3: entity.name.function.sql 37 4: keyword.other.cascade.sql 38 - match: (?i:\s*\b(alter)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+) 39 scope: meta.alter.sql 40 captures: 41 1: keyword.other.create.sql 42 2: keyword.other.table.sql 43 - match: |- 44 (?xi) 45 46 # normal stuff, capture 1 47 \b(bigint|bigserial|bit|boolean|box|bytea|cidr|circle|date|datetime|double\sprecision|inet|int|integer|line|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text)\b 48 49 # numeric suffix, capture 2 + 3i 50 |\b(bit\svarying|character\s(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) 51 52 # optional numeric suffix, capture 4 + 5i 53 |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? 54 55 # special case, capture 6 + 7i + 8i 56 |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? 57 58 # special case, captures 9, 10i, 11 59 |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\stime\szone\b)? 60 61 # special case, captures 12, 13, 14i, 15 62 |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\stime\szone\b)? 63 64 65 captures: 66 1: storage.type.sql 67 2: storage.type.sql 68 3: constant.numeric.sql 69 4: storage.type.sql 70 5: constant.numeric.sql 71 6: storage.type.sql 72 7: constant.numeric.sql 73 8: constant.numeric.sql 74 9: storage.type.sql 75 10: constant.numeric.sql 76 11: storage.type.sql 77 12: storage.type.sql 78 13: storage.type.sql 79 14: constant.numeric.sql 80 15: storage.type.sql 81 - match: (?i:\b((?:primary|foreign)\s+key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) 82 scope: storage.modifier.sql 83 - match: \b\d+\b 84 scope: constant.numeric.sql 85 - match: (?i:\b(true|false)\b) 86 scope: constant.boolean.sql 87 - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|case|when|then|else|end|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) 88 scope: keyword.other.DML.sql 89 - match: (?i:\b(?:(is)\s+)?(?:(not)\s+)?(null)\b) 90 captures: 91 1: keyword.operator.logical.sql 92 2: keyword.operator.logical.sql 93 3: constant.language.sql 94 - match: (?i:\b(and|or|like|having|exists|between|in)\b) 95 scope: keyword.operator.logical.sql 96 - match: (?i:\bvalues\b) 97 scope: keyword.other.DML.II.sql 98 - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) 99 scope: keyword.other.LUW.sql 100 - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) 101 scope: keyword.other.authorization.sql 102 - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) 103 scope: keyword.other.object-comments.sql 104 - match: (?i)\bas\b 105 scope: keyword.operator.assignment.alias.sql 106 - match: (?i)\b(asc|desc)\b 107 scope: keyword.other.order.sql 108 - match: \* 109 scope: variable.language.star.sql 110 - match: "<=>|[!<>]?=|<>|<|>" 111 scope: keyword.operator.comparison.sql 112 - match: '-|\+|/' 113 scope: keyword.operator.math.sql 114 - match: \|\| 115 scope: keyword.operator.concatenator.sql 116 - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b 117 comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html 118 scope: support.function.scalar.sql 119 - match: (?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\() 120 comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html 121 scope: support.function.aggregate.sql 122 - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b 123 scope: support.function.string.sql 124 - match: \b(\w+?)\.(\w+)\b 125 captures: 126 1: constant.other.database-name.sql 127 2: constant.other.table-name.sql 128 - include: strings 129 - include: regexps 130 - match: (\()(\)) 131 comment: Allow for special ↩ behavior 132 scope: meta.block.sql 133 captures: 134 1: punctuation.section.scope.begin.sql 135 2: punctuation.section.scope.end.sql 136 comments: 137 - match: "--" 138 scope: punctuation.definition.comment.sql 139 push: 140 - meta_scope: comment.line.double-dash.sql 141 - match: \n 142 pop: true 143 - match: "#" 144 scope: punctuation.definition.comment.sql 145 push: 146 - meta_scope: comment.line.number-sign.sql 147 - match: \n 148 pop: true 149 - match: /\* 150 scope: punctuation.definition.comment.sql 151 push: 152 - meta_scope: comment.block.c 153 - match: \*/ 154 pop: true 155 - match: ^\s*(\*)(?!/) 156 captures: 157 1: punctuation.definition.comment.sql 158 regexps: 159 - match: /(?=\S.*/) 160 scope: punctuation.definition.string.begin.sql 161 push: 162 - meta_scope: string.regexp.sql 163 - match: / 164 scope: punctuation.definition.string.end.sql 165 pop: true 166 - include: string_interpolation 167 - match: \\/ 168 scope: constant.character.escape.slash.sql 169 - match: '%r\{' 170 comment: We should probably handle nested bracket pairs!?! -- Allan 171 scope: punctuation.definition.string.begin.sql 172 push: 173 - meta_scope: string.regexp.modr.sql 174 - match: '\}' 175 scope: punctuation.definition.string.end.sql 176 pop: true 177 - include: string_interpolation 178 string_escape: 179 - match: \\. 180 scope: constant.character.escape.sql 181 string_interpolation: 182 - match: '(#\{)([^\}]*)(\})' 183 scope: string.interpolated.sql 184 captures: 185 1: punctuation.definition.string.begin.sql 186 3: punctuation.definition.string.end.sql 187 strings: 188 - match: "'" 189 scope: punctuation.definition.string.begin.sql 190 push: 191 - meta_scope: string.quoted.single.sql 192 - match: "''" 193 scope: constant.character.escape.sql 194 - match: "'" 195 scope: punctuation.definition.string.end.sql 196 pop: true 197 - include: string_escape 198 - match: "`" 199 scope: punctuation.definition.string.begin.sql 200 push: 201 - meta_scope: string.quoted.other.backtick.sql 202 - match: "`" 203 scope: punctuation.definition.string.end.sql 204 pop: true 205 - include: string_escape 206 - match: '"' 207 scope: punctuation.definition.string.begin.sql 208 push: 209 - meta_scope: string.quoted.double.sql 210 - match: '""' 211 scope: constant.character.escape.sql 212 - match: '"' 213 scope: punctuation.definition.string.end.sql 214 pop: true 215 - include: string_interpolation 216 - match: '%\{' 217 scope: punctuation.definition.string.begin.sql 218 push: 219 - meta_scope: string.other.quoted.brackets.sql 220 - match: '\}' 221 scope: punctuation.definition.string.end.sql 222 pop: true 223 - include: string_interpolation 224 identifier_create: 225 - meta_content_scope: meta.toc-list.full-identifier.sql 226 - match: '(?:(\w+)|''([^'']+)''|"([^"]+)"|`([^`]+)`){{end_identifier}}' 227 scope: meta.toc-list.full-identifier.sql 228 captures: 229 1: entity.name.function.sql 230 2: entity.name.function.sql 231 3: entity.name.function.sql 232 4: entity.name.function.sql 233 pop: true 234 # Schema identifiers 235 - match: (?:\w+|'[^']+'|"[^"]+"|`[^`]+`)\s*(\.) 236 captures: 237 1: punctuation.accessor.dot.sql 238 # Handle situations where the schema and . 239 - match: '{{end_identifier}}' 240 pop: true