dart.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. "use strict";
  6. import LanguageConfiguration = monaco.languages.LanguageConfiguration;
  7. import IMonarchLanguage = monaco.languages.IMonarchLanguage;
  8. export const conf: LanguageConfiguration = {
  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: "'", notIn: ["string", "comment"] },
  23. { open: '"', close: '"', notIn: ["string"] },
  24. { open: "`", close: "`", notIn: ["string", "comment"] },
  25. { open: "/**", close: " */", notIn: ["string"] }
  26. ],
  27. surroundingPairs: [
  28. { open: "{", close: "}" },
  29. { open: "[", close: "]" },
  30. { open: "(", close: ")" },
  31. { open: "<", close: ">" },
  32. { open: "'", close: "'" },
  33. { open: "(", close: ")" },
  34. { open: '"', close: '"' },
  35. { open: "`", close: "`" }
  36. ],
  37. folding: {
  38. markers: {
  39. start: /^\s*\s*#?region\b/,
  40. end: /^\s*\s*#?endregion\b/
  41. }
  42. }
  43. };
  44. export const language = <IMonarchLanguage>{
  45. defaultToken: "invalid",
  46. tokenPostfix: ".dart",
  47. keywords: [
  48. "abstract",
  49. "dynamic",
  50. "implements",
  51. "show",
  52. "as",
  53. "else",
  54. "import",
  55. "static",
  56. "assert",
  57. "enum",
  58. "in",
  59. "super",
  60. "async",
  61. "export",
  62. "interface",
  63. "switch",
  64. "await",
  65. "extends",
  66. "is",
  67. "sync",
  68. "break",
  69. "external",
  70. "library",
  71. "this",
  72. "case",
  73. "factory",
  74. "mixin",
  75. "throw",
  76. "catch",
  77. "false",
  78. "new",
  79. "true",
  80. "class",
  81. "final",
  82. "null",
  83. "try",
  84. "const",
  85. "finally",
  86. "on",
  87. "typedef",
  88. "continue",
  89. "for",
  90. "operator",
  91. "var",
  92. "covariant",
  93. "Function",
  94. "part",
  95. "void",
  96. "default",
  97. "get",
  98. "rethrow",
  99. "while",
  100. "deferred",
  101. "hide",
  102. "return",
  103. "with",
  104. "do",
  105. "if",
  106. "set",
  107. "yield"
  108. ],
  109. typeKeywords: ["int", "double", "String", "bool"],
  110. operators: [
  111. "+",
  112. "-",
  113. "*",
  114. "/",
  115. "~/",
  116. "%",
  117. "++",
  118. "--",
  119. "==",
  120. "!=",
  121. ">",
  122. "<",
  123. ">=",
  124. "<=",
  125. "=",
  126. "-=",
  127. "/=",
  128. "%=",
  129. ">>=",
  130. "^=",
  131. "+=",
  132. "*=",
  133. "~/=",
  134. "<<=",
  135. "&=",
  136. "!=",
  137. "||",
  138. "&&",
  139. "&",
  140. "|",
  141. "^",
  142. "~",
  143. "<<",
  144. ">>",
  145. "!",
  146. ">>>",
  147. "??",
  148. "?",
  149. ":",
  150. "|="
  151. ],
  152. // we include these common regular expressions
  153. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  154. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  155. digits: /\d+(_+\d+)*/,
  156. octaldigits: /[0-7]+(_+[0-7]+)*/,
  157. binarydigits: /[0-1]+(_+[0-1]+)*/,
  158. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  159. regexpctl: /[(){}\[\]\$\^|\-*+?\.]/,
  160. regexpesc: /\\(?:[bBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})/,
  161. // The main tokenizer for our languages
  162. tokenizer: {
  163. root: [[/[{}]/, "delimiter.bracket"], { include: "common" }],
  164. common: [
  165. // identifiers and keywords
  166. [
  167. /[a-z_$][\w$]*/,
  168. {
  169. cases: {
  170. "@typeKeywords": "keyword",
  171. "@keywords": "keyword",
  172. "@default": "identifier"
  173. }
  174. }
  175. ],
  176. [
  177. /(?<![a-zA-Z0-9_$])([_$]*[A-Z][a-zA-Z0-9_$]*|bool\\b|num\\b|int\\b|double\\b|dynamic\\b)/,
  178. "type.identifier"
  179. ], // to show class names nicely
  180. // [/[A-Z][\w\$]*/, 'identifier'],
  181. // whitespace
  182. { include: "@whitespace" },
  183. // regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
  184. [
  185. /\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/,
  186. { token: "regexp", bracket: "@open", next: "@regexp" }
  187. ],
  188. // @ annotations.
  189. [/@[a-zA-Z]+/, "annotation"],
  190. // variable
  191. // delimiters and operators
  192. [/[()\[\]]/, "@brackets"],
  193. [/[<>](?!@symbols)/, "@brackets"],
  194. [/!(?=([^=]|$))/, "delimiter"],
  195. [
  196. /@symbols/,
  197. {
  198. cases: {
  199. "@operators": "delimiter",
  200. "@default": ""
  201. }
  202. }
  203. ],
  204. // numbers
  205. [/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
  206. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
  207. [/0[xX](@hexdigits)n?/, "number.hex"],
  208. [/0[oO]?(@octaldigits)n?/, "number.octal"],
  209. [/0[bB](@binarydigits)n?/, "number.binary"],
  210. [/(@digits)n?/, "number"],
  211. // delimiter: after number because of .\d floats
  212. [/[;,.]/, "delimiter"],
  213. // strings
  214. [/"([^"\\]|\\.)*$/, "string.invalid"], // non-teminated string
  215. [/'([^'\\]|\\.)*$/, "string.invalid"], // non-teminated string
  216. [/"/, "string", "@string_double"],
  217. [/'/, "string", "@string_single"],
  218. [/`/, "string", "@string_backtick"]
  219. // [/[a-zA-Z]+/, "variable"]
  220. ],
  221. whitespace: [
  222. [/[ \t\r\n]+/, ""],
  223. [/\/\*\*(?!\/)/, "comment.doc", "@jsdoc"],
  224. [/\/\*/, "comment", "@comment"],
  225. [/\/\/.*$/, "comment"]
  226. ],
  227. comment: [
  228. [/[^\/*]+/, "comment"],
  229. [/\*\//, "comment", "@pop"],
  230. [/[\/*]/, "comment"]
  231. ],
  232. jsdoc: [
  233. [/[^\/*]+/, "comment.doc"],
  234. [/\*\//, "comment.doc", "@pop"],
  235. [/[\/*]/, "comment.doc"]
  236. ],
  237. // We match regular expression quite precisely
  238. regexp: [
  239. [
  240. /(\{)(\d+(?:,\d*)?)(\})/,
  241. [
  242. "regexp.escape.control",
  243. "regexp.escape.control",
  244. "regexp.escape.control"
  245. ]
  246. ],
  247. [
  248. /(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,
  249. [
  250. "regexp.escape.control",
  251. { token: "regexp.escape.control", next: "@regexrange" }
  252. ]
  253. ],
  254. [
  255. /(\()(\?:|\?=|\?!)/,
  256. ["regexp.escape.control", "regexp.escape.control"]
  257. ],
  258. [/[()]/, "regexp.escape.control"],
  259. [/@regexpctl/, "regexp.escape.control"],
  260. [/[^\\\/]/, "regexp"],
  261. [/@regexpesc/, "regexp.escape"],
  262. [/\\\./, "regexp.invalid"],
  263. [
  264. /(\/)([gimsuy]*)/,
  265. [
  266. { token: "regexp", bracket: "@close", next: "@pop" },
  267. "keyword.other"
  268. ]
  269. ]
  270. ],
  271. regexrange: [
  272. [/-/, "regexp.escape.control"],
  273. [/\^/, "regexp.invalid"],
  274. [/@regexpesc/, "regexp.escape"],
  275. [/[^\]]/, "regexp"],
  276. [
  277. /\]/,
  278. {
  279. token: "regexp.escape.control",
  280. next: "@pop",
  281. bracket: "@close"
  282. }
  283. ]
  284. ],
  285. string_double: [
  286. [/\$\{/, { token: "delimiter.bracket", next: "@bracketCounting" }],
  287. [/[^\\"]+/, "string"],
  288. [/@escapes/, "string.escape"],
  289. [/\\./, "string.escape.invalid"],
  290. [/"/, "string", "@pop"]
  291. ],
  292. string_single: [
  293. [/[^\\']+/, "string"],
  294. [/@escapes/, "string.escape"],
  295. [/\\./, "string.escape.invalid"],
  296. [/'/, "string", "@pop"]
  297. ],
  298. string_backtick: [
  299. [/\$\{/, { token: "delimiter.bracket", next: "@bracketCounting" }],
  300. [/[^\\`$]+/, "string"],
  301. [/@escapes/, "string.escape"],
  302. [/\\./, "string.escape.invalid"],
  303. [/`/, "string", "@pop"]
  304. ],
  305. bracketCounting: [
  306. [/\{/, "delimiter.bracket", "@bracketCounting"],
  307. [/\}/, "delimiter.bracket", "@pop"],
  308. { include: "common" }
  309. ]
  310. }
  311. };