csharp.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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/csharp/csharp.ts
  8. var conf = {
  9. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  10. comments: {
  11. lineComment: "//",
  12. blockComment: ["/*", "*/"]
  13. },
  14. brackets: [
  15. ["{", "}"],
  16. ["[", "]"],
  17. ["(", ")"]
  18. ],
  19. autoClosingPairs: [
  20. { open: "{", close: "}" },
  21. { open: "[", close: "]" },
  22. { open: "(", close: ")" },
  23. { open: "'", close: "'", notIn: ["string", "comment"] },
  24. { open: '"', close: '"', notIn: ["string", "comment"] }
  25. ],
  26. surroundingPairs: [
  27. { open: "{", close: "}" },
  28. { open: "[", close: "]" },
  29. { open: "(", close: ")" },
  30. { open: "<", close: ">" },
  31. { open: "'", close: "'" },
  32. { open: '"', close: '"' }
  33. ],
  34. folding: {
  35. markers: {
  36. start: new RegExp("^\\s*#region\\b"),
  37. end: new RegExp("^\\s*#endregion\\b")
  38. }
  39. }
  40. };
  41. var language = {
  42. defaultToken: "",
  43. tokenPostfix: ".cs",
  44. brackets: [
  45. { open: "{", close: "}", token: "delimiter.curly" },
  46. { open: "[", close: "]", token: "delimiter.square" },
  47. { open: "(", close: ")", token: "delimiter.parenthesis" },
  48. { open: "<", close: ">", token: "delimiter.angle" }
  49. ],
  50. keywords: [
  51. "extern",
  52. "alias",
  53. "using",
  54. "bool",
  55. "decimal",
  56. "sbyte",
  57. "byte",
  58. "short",
  59. "ushort",
  60. "int",
  61. "uint",
  62. "long",
  63. "ulong",
  64. "char",
  65. "float",
  66. "double",
  67. "object",
  68. "dynamic",
  69. "string",
  70. "assembly",
  71. "is",
  72. "as",
  73. "ref",
  74. "out",
  75. "this",
  76. "base",
  77. "new",
  78. "typeof",
  79. "void",
  80. "checked",
  81. "unchecked",
  82. "default",
  83. "delegate",
  84. "var",
  85. "const",
  86. "if",
  87. "else",
  88. "switch",
  89. "case",
  90. "while",
  91. "do",
  92. "for",
  93. "foreach",
  94. "in",
  95. "break",
  96. "continue",
  97. "goto",
  98. "return",
  99. "throw",
  100. "try",
  101. "catch",
  102. "finally",
  103. "lock",
  104. "yield",
  105. "from",
  106. "let",
  107. "where",
  108. "join",
  109. "on",
  110. "equals",
  111. "into",
  112. "orderby",
  113. "ascending",
  114. "descending",
  115. "select",
  116. "group",
  117. "by",
  118. "namespace",
  119. "partial",
  120. "class",
  121. "field",
  122. "event",
  123. "method",
  124. "param",
  125. "public",
  126. "protected",
  127. "internal",
  128. "private",
  129. "abstract",
  130. "sealed",
  131. "static",
  132. "struct",
  133. "readonly",
  134. "volatile",
  135. "virtual",
  136. "override",
  137. "params",
  138. "get",
  139. "set",
  140. "add",
  141. "remove",
  142. "operator",
  143. "true",
  144. "false",
  145. "implicit",
  146. "explicit",
  147. "interface",
  148. "enum",
  149. "null",
  150. "async",
  151. "await",
  152. "fixed",
  153. "sizeof",
  154. "stackalloc",
  155. "unsafe",
  156. "nameof",
  157. "when"
  158. ],
  159. namespaceFollows: ["namespace", "using"],
  160. parenFollows: ["if", "for", "while", "switch", "foreach", "using", "catch", "when"],
  161. operators: [
  162. "=",
  163. "??",
  164. "||",
  165. "&&",
  166. "|",
  167. "^",
  168. "&",
  169. "==",
  170. "!=",
  171. "<=",
  172. ">=",
  173. "<<",
  174. "+",
  175. "-",
  176. "*",
  177. "/",
  178. "%",
  179. "!",
  180. "~",
  181. "++",
  182. "--",
  183. "+=",
  184. "-=",
  185. "*=",
  186. "/=",
  187. "%=",
  188. "&=",
  189. "|=",
  190. "^=",
  191. "<<=",
  192. ">>=",
  193. ">>",
  194. "=>"
  195. ],
  196. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  197. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  198. tokenizer: {
  199. root: [
  200. [
  201. /\@?[a-zA-Z_]\w*/,
  202. {
  203. cases: {
  204. "@namespaceFollows": {
  205. token: "keyword.$0",
  206. next: "@namespace"
  207. },
  208. "@keywords": {
  209. token: "keyword.$0",
  210. next: "@qualified"
  211. },
  212. "@default": { token: "identifier", next: "@qualified" }
  213. }
  214. }
  215. ],
  216. { include: "@whitespace" },
  217. [
  218. /}/,
  219. {
  220. cases: {
  221. "$S2==interpolatedstring": {
  222. token: "string.quote",
  223. next: "@pop"
  224. },
  225. "$S2==litinterpstring": {
  226. token: "string.quote",
  227. next: "@pop"
  228. },
  229. "@default": "@brackets"
  230. }
  231. }
  232. ],
  233. [/[{}()\[\]]/, "@brackets"],
  234. [/[<>](?!@symbols)/, "@brackets"],
  235. [
  236. /@symbols/,
  237. {
  238. cases: {
  239. "@operators": "delimiter",
  240. "@default": ""
  241. }
  242. }
  243. ],
  244. [/[0-9_]*\.[0-9_]+([eE][\-+]?\d+)?[fFdD]?/, "number.float"],
  245. [/0[xX][0-9a-fA-F_]+/, "number.hex"],
  246. [/0[bB][01_]+/, "number.hex"],
  247. [/[0-9_]+/, "number"],
  248. [/[;,.]/, "delimiter"],
  249. [/"([^"\\]|\\.)*$/, "string.invalid"],
  250. [/"/, { token: "string.quote", next: "@string" }],
  251. [/\$\@"/, { token: "string.quote", next: "@litinterpstring" }],
  252. [/\@"/, { token: "string.quote", next: "@litstring" }],
  253. [/\$"/, { token: "string.quote", next: "@interpolatedstring" }],
  254. [/'[^\\']'/, "string"],
  255. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  256. [/'/, "string.invalid"]
  257. ],
  258. qualified: [
  259. [
  260. /[a-zA-Z_][\w]*/,
  261. {
  262. cases: {
  263. "@keywords": { token: "keyword.$0" },
  264. "@default": "identifier"
  265. }
  266. }
  267. ],
  268. [/\./, "delimiter"],
  269. ["", "", "@pop"]
  270. ],
  271. namespace: [
  272. { include: "@whitespace" },
  273. [/[A-Z]\w*/, "namespace"],
  274. [/[\.=]/, "delimiter"],
  275. ["", "", "@pop"]
  276. ],
  277. comment: [
  278. [/[^\/*]+/, "comment"],
  279. ["\\*/", "comment", "@pop"],
  280. [/[\/*]/, "comment"]
  281. ],
  282. string: [
  283. [/[^\\"]+/, "string"],
  284. [/@escapes/, "string.escape"],
  285. [/\\./, "string.escape.invalid"],
  286. [/"/, { token: "string.quote", next: "@pop" }]
  287. ],
  288. litstring: [
  289. [/[^"]+/, "string"],
  290. [/""/, "string.escape"],
  291. [/"/, { token: "string.quote", next: "@pop" }]
  292. ],
  293. litinterpstring: [
  294. [/[^"{]+/, "string"],
  295. [/""/, "string.escape"],
  296. [/{{/, "string.escape"],
  297. [/}}/, "string.escape"],
  298. [/{/, { token: "string.quote", next: "root.litinterpstring" }],
  299. [/"/, { token: "string.quote", next: "@pop" }]
  300. ],
  301. interpolatedstring: [
  302. [/[^\\"{]+/, "string"],
  303. [/@escapes/, "string.escape"],
  304. [/\\./, "string.escape.invalid"],
  305. [/{{/, "string.escape"],
  306. [/}}/, "string.escape"],
  307. [/{/, { token: "string.quote", next: "root.interpolatedstring" }],
  308. [/"/, { token: "string.quote", next: "@pop" }]
  309. ],
  310. whitespace: [
  311. [/^[ \t\v\f]*#((r)|(load))(?=\s)/, "directive.csx"],
  312. [/^[ \t\v\f]*#\w.*$/, "namespace.cpp"],
  313. [/[ \t\v\f\r\n]+/, ""],
  314. [/\/\*/, "comment", "@comment"],
  315. [/\/\/.*$/, "comment"]
  316. ]
  317. }
  318. };
  319. export {
  320. conf,
  321. language
  322. };