swift.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*!---------------------------------------------------------------------------------------------
  2. * Copyright (C) David Owens II, owensd.io. All rights reserved.
  3. *--------------------------------------------------------------------------------------------*/
  4. define('vs/basic-languages/swift/swift',["require", "exports"], function (require, exports) {
  5. "use strict";
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.language = exports.conf = void 0;
  8. exports.conf = {
  9. comments: {
  10. lineComment: '//',
  11. blockComment: ['/*', '*/']
  12. },
  13. brackets: [
  14. ['{', '}'],
  15. ['[', ']'],
  16. ['(', ')']
  17. ],
  18. autoClosingPairs: [
  19. { open: '{', close: '}' },
  20. { open: '[', close: ']' },
  21. { open: '(', close: ')' },
  22. { open: '"', close: '"' },
  23. { open: "'", close: "'" },
  24. { open: '`', close: '`' }
  25. ],
  26. surroundingPairs: [
  27. { open: '{', close: '}' },
  28. { open: '[', close: ']' },
  29. { open: '(', close: ')' },
  30. { open: '"', close: '"' },
  31. { open: "'", close: "'" },
  32. { open: '`', close: '`' }
  33. ]
  34. };
  35. exports.language = {
  36. defaultToken: '',
  37. tokenPostfix: '.swift',
  38. // TODO(owensd): Support the full range of unicode valid identifiers.
  39. identifier: /[a-zA-Z_][\w$]*/,
  40. // TODO(owensd): Support the @availability macro properly.
  41. attributes: [
  42. '@autoclosure',
  43. '@noescape',
  44. '@noreturn',
  45. '@NSApplicationMain',
  46. '@NSCopying',
  47. '@NSManaged',
  48. '@objc',
  49. '@UIApplicationMain',
  50. '@noreturn',
  51. '@availability',
  52. '@IBAction',
  53. '@IBDesignable',
  54. '@IBInspectable',
  55. '@IBOutlet'
  56. ],
  57. accessmodifiers: ['public', 'private', 'fileprivate', 'internal'],
  58. keywords: [
  59. '__COLUMN__',
  60. '__FILE__',
  61. '__FUNCTION__',
  62. '__LINE__',
  63. 'as',
  64. 'as!',
  65. 'as?',
  66. 'associativity',
  67. 'break',
  68. 'case',
  69. 'catch',
  70. 'class',
  71. 'continue',
  72. 'convenience',
  73. 'default',
  74. 'deinit',
  75. 'didSet',
  76. 'do',
  77. 'dynamic',
  78. 'dynamicType',
  79. 'else',
  80. 'enum',
  81. 'extension',
  82. 'fallthrough',
  83. 'fileprivate',
  84. 'final',
  85. 'for',
  86. 'func',
  87. 'get',
  88. 'guard',
  89. 'if',
  90. 'import',
  91. 'in',
  92. 'infix',
  93. 'init',
  94. 'inout',
  95. 'internal',
  96. 'is',
  97. 'lazy',
  98. 'left',
  99. 'let',
  100. 'mutating',
  101. 'nil',
  102. 'none',
  103. 'nonmutating',
  104. 'operator',
  105. 'optional',
  106. 'override',
  107. 'postfix',
  108. 'precedence',
  109. 'prefix',
  110. 'private',
  111. 'protocol',
  112. 'Protocol',
  113. 'public',
  114. 'repeat',
  115. 'required',
  116. 'return',
  117. 'right',
  118. 'self',
  119. 'Self',
  120. 'set',
  121. 'static',
  122. 'struct',
  123. 'subscript',
  124. 'super',
  125. 'switch',
  126. 'throw',
  127. 'throws',
  128. 'try',
  129. 'try!',
  130. 'Type',
  131. 'typealias',
  132. 'unowned',
  133. 'var',
  134. 'weak',
  135. 'where',
  136. 'while',
  137. 'willSet',
  138. 'FALSE',
  139. 'TRUE'
  140. ],
  141. symbols: /[=(){}\[\].,:;@#\_&\-<>`?!+*\\\/]/,
  142. // Moved . to operatorstart so it can be a delimiter
  143. operatorstart: /[\/=\-+!*%<>&|^~?\u00A1-\u00A7\u00A9\u00AB\u00AC\u00AE\u00B0-\u00B1\u00B6\u00BB\u00BF\u00D7\u00F7\u2016-\u2017\u2020-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E\u2190-\u23FF\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3001-\u3003\u3008-\u3030]/,
  144. operatorend: /[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F\uE0100-\uE01EF]/,
  145. operators: /(@operatorstart)((@operatorstart)|(@operatorend))*/,
  146. // TODO(owensd): These are borrowed from C#; need to validate correctness for Swift.
  147. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  148. tokenizer: {
  149. root: [
  150. { include: '@whitespace' },
  151. { include: '@comment' },
  152. { include: '@attribute' },
  153. { include: '@literal' },
  154. { include: '@keyword' },
  155. { include: '@invokedmethod' },
  156. { include: '@symbol' }
  157. ],
  158. whitespace: [
  159. [/\s+/, 'white'],
  160. [/"""/, 'string.quote', '@endDblDocString']
  161. ],
  162. endDblDocString: [
  163. [/[^"]+/, 'string'],
  164. [/\\"/, 'string'],
  165. [/"""/, 'string.quote', '@popall'],
  166. [/"/, 'string']
  167. ],
  168. symbol: [
  169. [/[{}()\[\]]/, '@brackets'],
  170. [/[<>](?!@symbols)/, '@brackets'],
  171. [/[.]/, 'delimiter'],
  172. [/@operators/, 'operator'],
  173. [/@symbols/, 'operator']
  174. ],
  175. comment: [
  176. [/\/\/\/.*$/, 'comment.doc'],
  177. [/\/\*\*/, 'comment.doc', '@commentdocbody'],
  178. [/\/\/.*$/, 'comment'],
  179. [/\/\*/, 'comment', '@commentbody']
  180. ],
  181. commentdocbody: [
  182. [/\/\*/, 'comment', '@commentbody'],
  183. [/\*\//, 'comment.doc', '@pop'],
  184. [/\:[a-zA-Z]+\:/, 'comment.doc.param'],
  185. [/./, 'comment.doc']
  186. ],
  187. commentbody: [
  188. [/\/\*/, 'comment', '@commentbody'],
  189. [/\*\//, 'comment', '@pop'],
  190. [/./, 'comment']
  191. ],
  192. attribute: [
  193. [
  194. /@@@identifier/,
  195. {
  196. cases: {
  197. '@attributes': 'keyword.control',
  198. '@default': ''
  199. }
  200. }
  201. ]
  202. ],
  203. literal: [
  204. [/"/, { token: 'string.quote', next: '@stringlit' }],
  205. [/0[b]([01]_?)+/, 'number.binary'],
  206. [/0[o]([0-7]_?)+/, 'number.octal'],
  207. [/0[x]([0-9a-fA-F]_?)+([pP][\-+](\d_?)+)?/, 'number.hex'],
  208. [/(\d_?)*\.(\d_?)+([eE][\-+]?(\d_?)+)?/, 'number.float'],
  209. [/(\d_?)+/, 'number']
  210. ],
  211. stringlit: [
  212. [/\\\(/, { token: 'operator', next: '@interpolatedexpression' }],
  213. [/@escapes/, 'string'],
  214. [/\\./, 'string.escape.invalid'],
  215. [/"/, { token: 'string.quote', next: '@pop' }],
  216. [/./, 'string']
  217. ],
  218. interpolatedexpression: [
  219. [/\(/, { token: 'operator', next: '@interpolatedexpression' }],
  220. [/\)/, { token: 'operator', next: '@pop' }],
  221. { include: '@literal' },
  222. { include: '@keyword' },
  223. { include: '@symbol' }
  224. ],
  225. keyword: [
  226. [/`/, { token: 'operator', next: '@escapedkeyword' }],
  227. [
  228. /@identifier/,
  229. {
  230. cases: {
  231. '@keywords': 'keyword',
  232. '[A-Z][a-zA-Z0-9$]*': 'type.identifier',
  233. '@default': 'identifier'
  234. }
  235. }
  236. ]
  237. ],
  238. escapedkeyword: [
  239. [/`/, { token: 'operator', next: '@pop' }],
  240. [/./, 'identifier']
  241. ],
  242. // symbol: [
  243. // [ /@symbols/, 'operator' ],
  244. // [ /@operators/, 'operator' ]
  245. // ],
  246. invokedmethod: [
  247. [
  248. /([.])(@identifier)/,
  249. {
  250. cases: {
  251. $2: ['delimeter', 'type.identifier'],
  252. '@default': ''
  253. }
  254. }
  255. ]
  256. ]
  257. }
  258. };
  259. });