|
| 1 | +%YAML 1.2 |
| 2 | +--- |
| 3 | +# http://www.sublimetext.com/docs/3/syntax.html |
| 4 | +name: Calypso |
| 5 | +comment: This file was somewhat inspired by https://github.com/microsoft/vscode/blob/main/extensions/rust/syntaxes/rust.tmLanguage.json which is under the MIT license. |
| 6 | +file_extensions: |
| 7 | + - cal |
| 8 | +scope: source.calypso |
| 9 | +contexts: |
| 10 | + main: |
| 11 | + - match: '(@)(\!?)([A-Za-z_][A-Za-z0-9_]*\!?\??)(?:\([^\)\n]*\))?' |
| 12 | + comment: attributes |
| 13 | + scope: meta.attribute.calypso |
| 14 | + captures: |
| 15 | + 1: punctuation.definition.attribute.calypso |
| 16 | + 2: keyword.operator.attribute.inner.calypso |
| 17 | + 3: meta.attribute.name.calypso |
| 18 | + 4: meta.attribute.content.calypso |
| 19 | + - match: '(mod)\s+(?!root|self|super)([a-z][A-Za-z0-9_]*)' |
| 20 | + comment: modules |
| 21 | + captures: |
| 22 | + 1: storage.type.calypso |
| 23 | + 2: entity.name.module.calypso |
| 24 | + - match: \b(import)\s |
| 25 | + comment: import statements |
| 26 | + captures: |
| 27 | + 1: keyword.other.calypso |
| 28 | + push: |
| 29 | + - meta_scope: meta.import.calypso |
| 30 | + - match: '}|\n' |
| 31 | + captures: |
| 32 | + 0: punctuation.semi.calypso |
| 33 | + pop: true |
| 34 | + - include: block-comments |
| 35 | + - include: comments |
| 36 | + - include: keywords |
| 37 | + - include: namespaces |
| 38 | + - include: punctuation |
| 39 | + - include: special-variables |
| 40 | + - include: constants |
| 41 | + - include: keywords |
| 42 | + - include: block-comments |
| 43 | + - include: comments |
| 44 | + - include: punctuation |
| 45 | + - include: namespaces |
| 46 | + - include: special-variables |
| 47 | + - include: variables |
| 48 | + - include: strings |
| 49 | + - include: types |
| 50 | + - include: functions |
| 51 | + block-comments: |
| 52 | + - match: '/\*[\*!]{1}\*/' |
| 53 | + comment: empty doc comment |
| 54 | + scope: comment.block.documentation.calypso |
| 55 | + - match: /\*\*/ |
| 56 | + comment: empty block comment |
| 57 | + scope: comment.block.calypso |
| 58 | + - match: '/\*[\*!]{1}' |
| 59 | + comment: block doc comment |
| 60 | + push: |
| 61 | + - meta_scope: comment.block.documentation.calypso |
| 62 | + - match: \*/ |
| 63 | + pop: true |
| 64 | + - include: block-comments |
| 65 | + - match: /\*(?!\*) |
| 66 | + comment: block comment |
| 67 | + push: |
| 68 | + - meta_scope: comment.block.calypso |
| 69 | + - match: \*/ |
| 70 | + pop: true |
| 71 | + - include: block-comments |
| 72 | + comments: |
| 73 | + - match: '^\s*//[/!]{1}.*' |
| 74 | + comment: doc comments, internal or external |
| 75 | + scope: comment.line.documentation |
| 76 | + - match: \s*//.* |
| 77 | + comment: regular comments |
| 78 | + scope: comment.line.double-slash |
| 79 | + constants: |
| 80 | + - match: '\b[A-Z]{2}[A-Z0-9_]*\!?\??\b' |
| 81 | + comment: ALL CAPS constants |
| 82 | + scope: constant.other.caps.calypso |
| 83 | + - match: '\b(const)\s+([A-Z][A-Za-z0-9_]*\!?\??)\b' |
| 84 | + comment: constant declarations |
| 85 | + captures: |
| 86 | + 1: storage.type.calypso |
| 87 | + 2: constant.other.caps.calypso |
| 88 | + - match: '\b[\-]?\d[\d_]*(\.?)[\d_]*(?:(E)([+-])([\d_]+))?(f|s|u)?\b' |
| 89 | + comment: decimal integers and floats |
| 90 | + scope: constant.numeric.decimal.calypso |
| 91 | + captures: |
| 92 | + 1: punctuation.separator.dot.decimal.calypso |
| 93 | + 2: keyword.operator.exponent.calypso |
| 94 | + 3: keyword.operator.exponent.sign.calypso |
| 95 | + 4: constant.numeric.decimal.exponent.mantissa.calypso |
| 96 | + 5: entity.name.type.numeric.calypso |
| 97 | + - match: '\b0x[\da-fA-F_]+(u|s)?\b' |
| 98 | + comment: hexadecimal integers |
| 99 | + scope: constant.numeric.hex.calypso |
| 100 | + captures: |
| 101 | + 1: entity.name.type.numeric.calypso |
| 102 | + - match: '\b0o[0-7_]+(u|s)?\b' |
| 103 | + comment: octal integers |
| 104 | + scope: constant.numeric.oct.calypso |
| 105 | + captures: |
| 106 | + 1: entity.name.type.numeric.calypso |
| 107 | + - match: '\b0b[01_]+(u|s)?\b' |
| 108 | + comment: binary integers |
| 109 | + scope: constant.numeric.bin.calypso |
| 110 | + captures: |
| 111 | + 1: entity.name.type.numeric.calypso |
| 112 | + - match: \b(true|false)\b |
| 113 | + comment: booleans |
| 114 | + scope: constant.language.bool.calypso |
| 115 | + - match: \bnull\b |
| 116 | + comment: nulls |
| 117 | + scope: constant.language.null.calypso |
| 118 | + - match: ':(?!")[A-Za-z_][A-Za-z0-9_]*\!?\??' |
| 119 | + comment: atoms--they're essentially keywords so we treat them as so |
| 120 | + scope: keyword.other.calypso |
| 121 | + - match: (:)(") |
| 122 | + comment: atoms, strings |
| 123 | + captures: |
| 124 | + 1: punctuation.atom.calypso |
| 125 | + 2: punctuation.defintition.string.calypso |
| 126 | + push: |
| 127 | + - meta_scope: keyword.other.calypso |
| 128 | + - meta_content_scope: string.quoted.double.calypso |
| 129 | + - match: '"' |
| 130 | + captures: |
| 131 | + 0: punctuation.definition.string.calypso |
| 132 | + pop: true |
| 133 | + escapes: |
| 134 | + - match: '(\\)(?:(?:(x[0-7][0-7a-fA-F])|(u(\{)[\da-fA-F]{4,6}(\}))|.))' |
| 135 | + comment: "escapes: ASCII, byte, Unicode, quote, regex" |
| 136 | + scope: constant.character.escape.calypso |
| 137 | + captures: |
| 138 | + 1: constant.character.escape.backslash.calypso |
| 139 | + 2: constant.character.escape.bit.calypso |
| 140 | + 3: constant.character.escape.unicode.calypso |
| 141 | + 4: constant.character.escape.unicode.punctuation.calypso |
| 142 | + 5: constant.character.escape.unicode.punctuation.calypso |
| 143 | + functions: |
| 144 | + - match: \b(pub)(\() |
| 145 | + comment: pub as a function |
| 146 | + captures: |
| 147 | + 1: keyword.other.calypso |
| 148 | + 2: punctuation.brackets.round.calypso |
| 149 | + - match: '\b(fn)\s+((?!root|self|super)[A-Za-z_][A-Za-z0-9_]+\!?\??)(\()' |
| 150 | + comment: function definition |
| 151 | + captures: |
| 152 | + 1: keyword.other.fn.calypso |
| 153 | + 2: entity.name.function.calypso |
| 154 | + 4: punctuation.brackets.round.calypso |
| 155 | + push: |
| 156 | + - meta_scope: meta.function.definition.calypso |
| 157 | + - match: "->|;" |
| 158 | + captures: |
| 159 | + 0: punctuation.brackets.curly.calypso |
| 160 | + pop: true |
| 161 | + - include: block-comments |
| 162 | + - include: comments |
| 163 | + - include: keywords |
| 164 | + - include: special-variables |
| 165 | + - include: constants |
| 166 | + - include: functions |
| 167 | + - include: namespaces |
| 168 | + - include: punctuation |
| 169 | + - include: strings |
| 170 | + - include: types |
| 171 | + - include: variables |
| 172 | + - match: '((?:r#(?!root|self|super))?[A-Za-z_][A-Za-z0-9_]+\!?\??)(\()' |
| 173 | + comment: function/method calls, chaining |
| 174 | + captures: |
| 175 | + 1: entity.name.function.calypso |
| 176 | + 2: punctuation.brackets.round.calypso |
| 177 | + push: |
| 178 | + - meta_scope: meta.function.call.calypso |
| 179 | + - match: \) |
| 180 | + captures: |
| 181 | + 0: punctuation.brackets.round.calypso |
| 182 | + pop: true |
| 183 | + - include: block-comments |
| 184 | + - include: comments |
| 185 | + - include: keywords |
| 186 | + - include: special-variables |
| 187 | + - include: constants |
| 188 | + - include: functions |
| 189 | + - include: namespaces |
| 190 | + - include: punctuation |
| 191 | + - include: strings |
| 192 | + - include: types |
| 193 | + - include: variables |
| 194 | + interpolations: |
| 195 | + - match: '\${' |
| 196 | + comment: string interpolations |
| 197 | + captures: |
| 198 | + 1: punctuation.definition.interpolation.calypso |
| 199 | + push: |
| 200 | + - meta_scope: meta.interpolation.calypso |
| 201 | + - match: "}" |
| 202 | + captures: |
| 203 | + 1: punctuation.definition.interpolation.calypso |
| 204 | + pop: true |
| 205 | + - include: main |
| 206 | + keywords: |
| 207 | + - match: \b(break|continue|do|else|for|if|loop|case|ret|try|catch|while|throw|end|->|\|>)\b |
| 208 | + comment: control flow |
| 209 | + scope: keyword.control.calypso |
| 210 | + - match: \b(const|extern|let|mod|struct|trait|marker)\b |
| 211 | + comment: storage keywords |
| 212 | + scope: storage.type.calypso |
| 213 | + - match: \b(as|impl|in|is|isa|isan|has|pub|import|where|assert|self|super)\b |
| 214 | + comment: other keywords |
| 215 | + scope: keyword.other.calypso |
| 216 | + - match: \bfn\b |
| 217 | + comment: fn |
| 218 | + scope: keyword.other.fn.calypso |
| 219 | + - match: \broot\b |
| 220 | + comment: root |
| 221 | + scope: keyword.other.root.calypso |
| 222 | + - match: \bmut\b |
| 223 | + comment: mut |
| 224 | + scope: storage.modifier.mut.calypso |
| 225 | + - match: (\^|\||\|\||&&|<<|>>|!)(?!=) |
| 226 | + comment: logical operators |
| 227 | + scope: keyword.operator.logical.calypso |
| 228 | + - match: "&(?![&=])" |
| 229 | + comment: logical AND |
| 230 | + scope: keyword.operator.and.calypso |
| 231 | + - match: (\+=|-=|\*=|\*\*=|/=|%=|\^=|&=|\|=|<<=|>>=) |
| 232 | + comment: assignment operators |
| 233 | + scope: keyword.operator.assignment.calypso |
| 234 | + - match: "(?<![<>])=(?!=|>)" |
| 235 | + comment: single equal |
| 236 | + scope: keyword.operator.assingment.equal.calypso |
| 237 | + - match: (=(=)?(?!>)|!=|<=|(?<!=)>=) |
| 238 | + comment: comparison operators |
| 239 | + scope: keyword.operator.comparison.calypso |
| 240 | + - match: '(([+%]|(\*{1,2}))(?!=))|(-(?!>))|(/(?!/))' |
| 241 | + comment: math operators |
| 242 | + scope: keyword.operator.math.calypso |
| 243 | + - match: '(?:\b|(?:(\))|(\])|(\})))[ \t]+([<>])[ \t]+(?:\b|(?:(\()|(\[)|(\{)))' |
| 244 | + comment: less than, greater than (special case) |
| 245 | + captures: |
| 246 | + 1: punctuation.brackets.round.calypso |
| 247 | + 2: punctuation.brackets.square.calypso |
| 248 | + 3: punctuation.brackets.curly.calypso |
| 249 | + 4: keyword.operator.comparison.calypso |
| 250 | + 5: punctuation.brackets.round.calypso |
| 251 | + 6: punctuation.brackets.square.calypso |
| 252 | + 7: punctuation.brackets.curly.calypso |
| 253 | + - match: \.(?!\.) |
| 254 | + comment: dot access |
| 255 | + scope: keyword.operator.access.dot.calyppso |
| 256 | + - match: '\.{2}(=|\.)?' |
| 257 | + comment: ranges, range patterns |
| 258 | + scope: keyword.operator.range.calypso |
| 259 | + - match: ':(?![:A-Za-z0-9"])' |
| 260 | + comment: colon |
| 261 | + scope: keyword.operator.key-value.calypso |
| 262 | + - match: "->" |
| 263 | + comment: dashrocket, skinny arrow |
| 264 | + scope: keyword.operator.arrow.skinny.calypso |
| 265 | + - match: "=>" |
| 266 | + comment: hashrocket, fat arrow |
| 267 | + scope: keyword.operator.arrow.fat.calypso |
| 268 | + - match: (println|type) |
| 269 | + comment: builtin functions |
| 270 | + scope: entity.name.function.calypso |
| 271 | + namespaces: |
| 272 | + - match: '(?<![A-Za-z0-9_])([a-z0-9_]+)((?<!super|self)\.)' |
| 273 | + comment: namespace (non-type, non-function path segment) |
| 274 | + captures: |
| 275 | + 1: entity.name.namespace.calypso |
| 276 | + 2: keyword.operator.calypso |
| 277 | + punctuation: |
| 278 | + - match: "," |
| 279 | + comment: comma |
| 280 | + scope: punctuation.comma.calypso |
| 281 | + - match: "[{}]" |
| 282 | + comment: curly braces |
| 283 | + scope: punctuation.braces.curly.calypso |
| 284 | + - match: "[()]" |
| 285 | + comment: parentheses, round brackets |
| 286 | + scope: punctuation.brackets.round.calypso |
| 287 | + - match: ; |
| 288 | + comment: semicolon |
| 289 | + scope: punctuation.semi.calypso |
| 290 | + - match: '[\[\]]' |
| 291 | + comment: square brackets |
| 292 | + scope: punctuation.brackets.square.calypso |
| 293 | + - match: "(?<!=)[<>]" |
| 294 | + comment: angle brackets |
| 295 | + scope: punctuation.brackets.angle.calypso |
| 296 | + special-variables: |
| 297 | + - match: \bself\b |
| 298 | + comment: self |
| 299 | + scope: variable.language.self.calypso |
| 300 | + - match: \bsuper\b |
| 301 | + comment: super |
| 302 | + scope: variable.language.super.calypso |
| 303 | + strings: |
| 304 | + - match: (") |
| 305 | + comment: double-quoted strings |
| 306 | + captures: |
| 307 | + 1: punctuation.definition.string.calypso |
| 308 | + push: |
| 309 | + - meta_scope: string.quoted.double.calypso |
| 310 | + - match: '"' |
| 311 | + captures: |
| 312 | + 0: punctuation.definition.string.calypso |
| 313 | + pop: true |
| 314 | + - include: escapes |
| 315 | + - include: interpolations |
| 316 | + - match: (') |
| 317 | + comment: characters |
| 318 | + captures: |
| 319 | + 1: punctuation.definition.char.calypso |
| 320 | + push: |
| 321 | + - meta_scope: string.quoted.single.char.calypso |
| 322 | + - match: "'" |
| 323 | + captures: |
| 324 | + 0: punctuation.definition.char.calypso |
| 325 | + pop: true |
| 326 | + - include: escapes |
| 327 | + types: |
| 328 | + - match: '(?<![A-Za-z])(float|sint|uint)\b' |
| 329 | + comment: numeric types |
| 330 | + captures: |
| 331 | + 1: entity.name.type.numeric.calypso |
| 332 | + - match: \b(bool|char|string|array|tuple|hash|atom|any)\b |
| 333 | + comment: primitive types |
| 334 | + scope: entity.name.type.primitive.calypso |
| 335 | + - match: '\b(trait)\s+([A-Z][A-Za-z0-9]*)\b' |
| 336 | + comment: trait declarations |
| 337 | + captures: |
| 338 | + 1: storage.type.calypso |
| 339 | + 2: entity.name.type.trait.calypso |
| 340 | + - match: '\b[A-Z][A-Za-z0-9]*\b' |
| 341 | + comment: types |
| 342 | + scope: entity.name.type.calypso |
| 343 | + variables: |
| 344 | + - match: '\b(?<!(?<!\.)\.)(?!(root|self|super))[A-Za-z_][A-Za-z0-9_]*\!?\??' |
| 345 | + comment: variables |
| 346 | + scope: variable.other.calypso |
0 commit comments