swift.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/swift/swift.ts
  8. var 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. var language = {
  36. defaultToken: "",
  37. tokenPostfix: ".swift",
  38. identifier: /[a-zA-Z_][\w$]*/,
  39. attributes: [
  40. "@autoclosure",
  41. "@noescape",
  42. "@noreturn",
  43. "@NSApplicationMain",
  44. "@NSCopying",
  45. "@NSManaged",
  46. "@objc",
  47. "@UIApplicationMain",
  48. "@noreturn",
  49. "@availability",
  50. "@IBAction",
  51. "@IBDesignable",
  52. "@IBInspectable",
  53. "@IBOutlet"
  54. ],
  55. accessmodifiers: ["public", "private", "fileprivate", "internal"],
  56. keywords: [
  57. "__COLUMN__",
  58. "__FILE__",
  59. "__FUNCTION__",
  60. "__LINE__",
  61. "as",
  62. "as!",
  63. "as?",
  64. "associativity",
  65. "break",
  66. "case",
  67. "catch",
  68. "class",
  69. "continue",
  70. "convenience",
  71. "default",
  72. "deinit",
  73. "didSet",
  74. "do",
  75. "dynamic",
  76. "dynamicType",
  77. "else",
  78. "enum",
  79. "extension",
  80. "fallthrough",
  81. "fileprivate",
  82. "final",
  83. "for",
  84. "func",
  85. "get",
  86. "guard",
  87. "if",
  88. "import",
  89. "in",
  90. "infix",
  91. "init",
  92. "inout",
  93. "internal",
  94. "is",
  95. "lazy",
  96. "left",
  97. "let",
  98. "mutating",
  99. "nil",
  100. "none",
  101. "nonmutating",
  102. "operator",
  103. "optional",
  104. "override",
  105. "postfix",
  106. "precedence",
  107. "prefix",
  108. "private",
  109. "protocol",
  110. "Protocol",
  111. "public",
  112. "repeat",
  113. "required",
  114. "return",
  115. "right",
  116. "self",
  117. "Self",
  118. "set",
  119. "static",
  120. "struct",
  121. "subscript",
  122. "super",
  123. "switch",
  124. "throw",
  125. "throws",
  126. "try",
  127. "try!",
  128. "Type",
  129. "typealias",
  130. "unowned",
  131. "var",
  132. "weak",
  133. "where",
  134. "while",
  135. "willSet",
  136. "FALSE",
  137. "TRUE"
  138. ],
  139. symbols: /[=(){}\[\].,:;@#\_&\-<>`?!+*\\\/]/,
  140. 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]/,
  141. operatorend: /[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F\uE0100-\uE01EF]/,
  142. operators: /(@operatorstart)((@operatorstart)|(@operatorend))*/,
  143. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  144. tokenizer: {
  145. root: [
  146. { include: "@whitespace" },
  147. { include: "@comment" },
  148. { include: "@attribute" },
  149. { include: "@literal" },
  150. { include: "@keyword" },
  151. { include: "@invokedmethod" },
  152. { include: "@symbol" }
  153. ],
  154. whitespace: [
  155. [/\s+/, "white"],
  156. [/"""/, "string.quote", "@endDblDocString"]
  157. ],
  158. endDblDocString: [
  159. [/[^"]+/, "string"],
  160. [/\\"/, "string"],
  161. [/"""/, "string.quote", "@popall"],
  162. [/"/, "string"]
  163. ],
  164. symbol: [
  165. [/[{}()\[\]]/, "@brackets"],
  166. [/[<>](?!@symbols)/, "@brackets"],
  167. [/[.]/, "delimiter"],
  168. [/@operators/, "operator"],
  169. [/@symbols/, "operator"]
  170. ],
  171. comment: [
  172. [/\/\/\/.*$/, "comment.doc"],
  173. [/\/\*\*/, "comment.doc", "@commentdocbody"],
  174. [/\/\/.*$/, "comment"],
  175. [/\/\*/, "comment", "@commentbody"]
  176. ],
  177. commentdocbody: [
  178. [/\/\*/, "comment", "@commentbody"],
  179. [/\*\//, "comment.doc", "@pop"],
  180. [/\:[a-zA-Z]+\:/, "comment.doc.param"],
  181. [/./, "comment.doc"]
  182. ],
  183. commentbody: [
  184. [/\/\*/, "comment", "@commentbody"],
  185. [/\*\//, "comment", "@pop"],
  186. [/./, "comment"]
  187. ],
  188. attribute: [
  189. [
  190. /@@@identifier/,
  191. {
  192. cases: {
  193. "@attributes": "keyword.control",
  194. "@default": ""
  195. }
  196. }
  197. ]
  198. ],
  199. literal: [
  200. [/"/, { token: "string.quote", next: "@stringlit" }],
  201. [/0[b]([01]_?)+/, "number.binary"],
  202. [/0[o]([0-7]_?)+/, "number.octal"],
  203. [/0[x]([0-9a-fA-F]_?)+([pP][\-+](\d_?)+)?/, "number.hex"],
  204. [/(\d_?)*\.(\d_?)+([eE][\-+]?(\d_?)+)?/, "number.float"],
  205. [/(\d_?)+/, "number"]
  206. ],
  207. stringlit: [
  208. [/\\\(/, { token: "operator", next: "@interpolatedexpression" }],
  209. [/@escapes/, "string"],
  210. [/\\./, "string.escape.invalid"],
  211. [/"/, { token: "string.quote", next: "@pop" }],
  212. [/./, "string"]
  213. ],
  214. interpolatedexpression: [
  215. [/\(/, { token: "operator", next: "@interpolatedexpression" }],
  216. [/\)/, { token: "operator", next: "@pop" }],
  217. { include: "@literal" },
  218. { include: "@keyword" },
  219. { include: "@symbol" }
  220. ],
  221. keyword: [
  222. [/`/, { token: "operator", next: "@escapedkeyword" }],
  223. [
  224. /@identifier/,
  225. {
  226. cases: {
  227. "@keywords": "keyword",
  228. "[A-Z][a-zA-Z0-9$]*": "type.identifier",
  229. "@default": "identifier"
  230. }
  231. }
  232. ]
  233. ],
  234. escapedkeyword: [
  235. [/`/, { token: "operator", next: "@pop" }],
  236. [/./, "identifier"]
  237. ],
  238. invokedmethod: [
  239. [
  240. /([.])(@identifier)/,
  241. {
  242. cases: {
  243. $2: ["delimeter", "type.identifier"],
  244. "@default": ""
  245. }
  246. }
  247. ]
  248. ]
  249. }
  250. };
  251. export {
  252. conf,
  253. language
  254. };
  255. /*!---------------------------------------------------------------------------------------------
  256. * Copyright (C) David Owens II, owensd.io. All rights reserved.
  257. *--------------------------------------------------------------------------------------------*/