swift.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
  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. "@GKInspectable",
  41. "@IBAction",
  42. "@IBDesignable",
  43. "@IBInspectable",
  44. "@IBOutlet",
  45. "@IBSegueAction",
  46. "@NSApplicationMain",
  47. "@NSCopying",
  48. "@NSManaged",
  49. "@Sendable",
  50. "@UIApplicationMain",
  51. "@autoclosure",
  52. "@actorIndependent",
  53. "@asyncHandler",
  54. "@available",
  55. "@convention",
  56. "@derivative",
  57. "@differentiable",
  58. "@discardableResult",
  59. "@dynamicCallable",
  60. "@dynamicMemberLookup",
  61. "@escaping",
  62. "@frozen",
  63. "@globalActor",
  64. "@inlinable",
  65. "@inline",
  66. "@main",
  67. "@noDerivative",
  68. "@nonobjc",
  69. "@noreturn",
  70. "@objc",
  71. "@objcMembers",
  72. "@preconcurrency",
  73. "@propertyWrapper",
  74. "@requires_stored_property_inits",
  75. "@resultBuilder",
  76. "@testable",
  77. "@unchecked",
  78. "@unknown",
  79. "@usableFromInline",
  80. "@warn_unqualified_access"
  81. ],
  82. accessmodifiers: ["open", "public", "internal", "fileprivate", "private"],
  83. keywords: [
  84. "#available",
  85. "#colorLiteral",
  86. "#column",
  87. "#dsohandle",
  88. "#else",
  89. "#elseif",
  90. "#endif",
  91. "#error",
  92. "#file",
  93. "#fileID",
  94. "#fileLiteral",
  95. "#filePath",
  96. "#function",
  97. "#if",
  98. "#imageLiteral",
  99. "#keyPath",
  100. "#line",
  101. "#selector",
  102. "#sourceLocation",
  103. "#warning",
  104. "Any",
  105. "Protocol",
  106. "Self",
  107. "Type",
  108. "actor",
  109. "as",
  110. "assignment",
  111. "associatedtype",
  112. "associativity",
  113. "async",
  114. "await",
  115. "break",
  116. "case",
  117. "catch",
  118. "class",
  119. "continue",
  120. "convenience",
  121. "default",
  122. "defer",
  123. "deinit",
  124. "didSet",
  125. "do",
  126. "dynamic",
  127. "dynamicType",
  128. "else",
  129. "enum",
  130. "extension",
  131. "fallthrough",
  132. "false",
  133. "fileprivate",
  134. "final",
  135. "for",
  136. "func",
  137. "get",
  138. "guard",
  139. "higherThan",
  140. "if",
  141. "import",
  142. "in",
  143. "indirect",
  144. "infix",
  145. "init",
  146. "inout",
  147. "internal",
  148. "is",
  149. "isolated",
  150. "lazy",
  151. "left",
  152. "let",
  153. "lowerThan",
  154. "mutating",
  155. "nil",
  156. "none",
  157. "nonisolated",
  158. "nonmutating",
  159. "open",
  160. "operator",
  161. "optional",
  162. "override",
  163. "postfix",
  164. "precedence",
  165. "precedencegroup",
  166. "prefix",
  167. "private",
  168. "protocol",
  169. "public",
  170. "repeat",
  171. "required",
  172. "rethrows",
  173. "return",
  174. "right",
  175. "safe",
  176. "self",
  177. "set",
  178. "some",
  179. "static",
  180. "struct",
  181. "subscript",
  182. "super",
  183. "switch",
  184. "throw",
  185. "throws",
  186. "true",
  187. "try",
  188. "typealias",
  189. "unowned",
  190. "unsafe",
  191. "var",
  192. "weak",
  193. "where",
  194. "while",
  195. "willSet",
  196. "__consuming",
  197. "__owned"
  198. ],
  199. symbols: /[=(){}\[\].,:;@#\_&\-<>`?!+*\\\/]/,
  200. 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]/,
  201. operatorend: /[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F\uE0100-\uE01EF]/,
  202. operators: /(@operatorstart)((@operatorstart)|(@operatorend))*/,
  203. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  204. tokenizer: {
  205. root: [
  206. { include: "@whitespace" },
  207. { include: "@comment" },
  208. { include: "@attribute" },
  209. { include: "@literal" },
  210. { include: "@keyword" },
  211. { include: "@invokedmethod" },
  212. { include: "@symbol" }
  213. ],
  214. whitespace: [
  215. [/\s+/, "white"],
  216. [/"""/, "string.quote", "@endDblDocString"]
  217. ],
  218. endDblDocString: [
  219. [/[^"]+/, "string"],
  220. [/\\"/, "string"],
  221. [/"""/, "string.quote", "@popall"],
  222. [/"/, "string"]
  223. ],
  224. symbol: [
  225. [/[{}()\[\]]/, "@brackets"],
  226. [/[<>](?!@symbols)/, "@brackets"],
  227. [/[.]/, "delimiter"],
  228. [/@operators/, "operator"],
  229. [/@symbols/, "operator"]
  230. ],
  231. comment: [
  232. [/\/\/\/.*$/, "comment.doc"],
  233. [/\/\*\*/, "comment.doc", "@commentdocbody"],
  234. [/\/\/.*$/, "comment"],
  235. [/\/\*/, "comment", "@commentbody"]
  236. ],
  237. commentdocbody: [
  238. [/\/\*/, "comment", "@commentbody"],
  239. [/\*\//, "comment.doc", "@pop"],
  240. [/\:[a-zA-Z]+\:/, "comment.doc.param"],
  241. [/./, "comment.doc"]
  242. ],
  243. commentbody: [
  244. [/\/\*/, "comment", "@commentbody"],
  245. [/\*\//, "comment", "@pop"],
  246. [/./, "comment"]
  247. ],
  248. attribute: [
  249. [
  250. /@@@identifier/,
  251. {
  252. cases: {
  253. "@attributes": "keyword.control",
  254. "@default": ""
  255. }
  256. }
  257. ]
  258. ],
  259. literal: [
  260. [/"/, { token: "string.quote", next: "@stringlit" }],
  261. [/0[b]([01]_?)+/, "number.binary"],
  262. [/0[o]([0-7]_?)+/, "number.octal"],
  263. [/0[x]([0-9a-fA-F]_?)+([pP][\-+](\d_?)+)?/, "number.hex"],
  264. [/(\d_?)*\.(\d_?)+([eE][\-+]?(\d_?)+)?/, "number.float"],
  265. [/(\d_?)+/, "number"]
  266. ],
  267. stringlit: [
  268. [/\\\(/, { token: "operator", next: "@interpolatedexpression" }],
  269. [/@escapes/, "string"],
  270. [/\\./, "string.escape.invalid"],
  271. [/"/, { token: "string.quote", next: "@pop" }],
  272. [/./, "string"]
  273. ],
  274. interpolatedexpression: [
  275. [/\(/, { token: "operator", next: "@interpolatedexpression" }],
  276. [/\)/, { token: "operator", next: "@pop" }],
  277. { include: "@literal" },
  278. { include: "@keyword" },
  279. { include: "@symbol" }
  280. ],
  281. keyword: [
  282. [/`/, { token: "operator", next: "@escapedkeyword" }],
  283. [
  284. /@identifier/,
  285. {
  286. cases: {
  287. "@keywords": "keyword",
  288. "[A-Z][a-zA-Z0-9$]*": "type.identifier",
  289. "@default": "identifier"
  290. }
  291. }
  292. ]
  293. ],
  294. escapedkeyword: [
  295. [/`/, { token: "operator", next: "@pop" }],
  296. [/./, "identifier"]
  297. ],
  298. invokedmethod: [
  299. [
  300. /([.])(@identifier)/,
  301. {
  302. cases: {
  303. $2: ["delimeter", "type.identifier"],
  304. "@default": ""
  305. }
  306. }
  307. ]
  308. ]
  309. }
  310. };
  311. export {
  312. conf,
  313. language
  314. };
  315. /*!---------------------------------------------------------------------------------------------
  316. * Copyright (C) David Owens II, owensd.io. All rights reserved.
  317. *--------------------------------------------------------------------------------------------*/