dart.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. export var conf = {
  6. comments: {
  7. lineComment: '//',
  8. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '{', close: '}' },
  17. { open: '[', close: ']' },
  18. { open: '(', close: ')' },
  19. { open: "'", close: "'", notIn: ['string', 'comment'] },
  20. { open: '"', close: '"', notIn: ['string'] },
  21. { open: '`', close: '`', notIn: ['string', 'comment'] },
  22. { open: '/**', close: ' */', notIn: ['string'] }
  23. ],
  24. surroundingPairs: [
  25. { open: '{', close: '}' },
  26. { open: '[', close: ']' },
  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: /^\s*\s*#?region\b/,
  37. end: /^\s*\s*#?endregion\b/
  38. }
  39. }
  40. };
  41. export var language = {
  42. defaultToken: 'invalid',
  43. tokenPostfix: '.dart',
  44. keywords: [
  45. 'abstract',
  46. 'dynamic',
  47. 'implements',
  48. 'show',
  49. 'as',
  50. 'else',
  51. 'import',
  52. 'static',
  53. 'assert',
  54. 'enum',
  55. 'in',
  56. 'super',
  57. 'async',
  58. 'export',
  59. 'interface',
  60. 'switch',
  61. 'await',
  62. 'extends',
  63. 'is',
  64. 'sync',
  65. 'break',
  66. 'external',
  67. 'library',
  68. 'this',
  69. 'case',
  70. 'factory',
  71. 'mixin',
  72. 'throw',
  73. 'catch',
  74. 'false',
  75. 'new',
  76. 'true',
  77. 'class',
  78. 'final',
  79. 'null',
  80. 'try',
  81. 'const',
  82. 'finally',
  83. 'on',
  84. 'typedef',
  85. 'continue',
  86. 'for',
  87. 'operator',
  88. 'var',
  89. 'covariant',
  90. 'Function',
  91. 'part',
  92. 'void',
  93. 'default',
  94. 'get',
  95. 'rethrow',
  96. 'while',
  97. 'deferred',
  98. 'hide',
  99. 'return',
  100. 'with',
  101. 'do',
  102. 'if',
  103. 'set',
  104. 'yield'
  105. ],
  106. typeKeywords: ['int', 'double', 'String', 'bool'],
  107. operators: [
  108. '+',
  109. '-',
  110. '*',
  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. // we include these common regular expressions
  150. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  151. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  152. digits: /\d+(_+\d+)*/,
  153. octaldigits: /[0-7]+(_+[0-7]+)*/,
  154. binarydigits: /[0-1]+(_+[0-1]+)*/,
  155. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  156. regexpctl: /[(){}\[\]\$\^|\-*+?\.]/,
  157. regexpesc: /\\(?:[bBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})/,
  158. // The main tokenizer for our languages
  159. tokenizer: {
  160. root: [[/[{}]/, 'delimiter.bracket'], { include: 'common' }],
  161. common: [
  162. // identifiers and keywords
  163. [
  164. /[a-z_$][\w$]*/,
  165. {
  166. cases: {
  167. '@typeKeywords': 'type.identifier',
  168. '@keywords': 'keyword',
  169. '@default': 'identifier'
  170. }
  171. }
  172. ],
  173. [/[A-Z_$][\w\$]*/, 'type.identifier'],
  174. // [/[A-Z][\w\$]*/, 'identifier'],
  175. // whitespace
  176. { include: '@whitespace' },
  177. // regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
  178. [
  179. /\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/,
  180. { token: 'regexp', bracket: '@open', next: '@regexp' }
  181. ],
  182. // @ annotations.
  183. [/@[a-zA-Z]+/, 'annotation'],
  184. // variable
  185. // delimiters and operators
  186. [/[()\[\]]/, '@brackets'],
  187. [/[<>](?!@symbols)/, '@brackets'],
  188. [/!(?=([^=]|$))/, 'delimiter'],
  189. [
  190. /@symbols/,
  191. {
  192. cases: {
  193. '@operators': 'delimiter',
  194. '@default': ''
  195. }
  196. }
  197. ],
  198. // numbers
  199. [/(@digits)[eE]([\-+]?(@digits))?/, 'number.float'],
  200. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, 'number.float'],
  201. [/0[xX](@hexdigits)n?/, 'number.hex'],
  202. [/0[oO]?(@octaldigits)n?/, 'number.octal'],
  203. [/0[bB](@binarydigits)n?/, 'number.binary'],
  204. [/(@digits)n?/, 'number'],
  205. // delimiter: after number because of .\d floats
  206. [/[;,.]/, 'delimiter'],
  207. // strings
  208. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  209. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  210. [/"/, 'string', '@string_double'],
  211. [/'/, 'string', '@string_single']
  212. // [/[a-zA-Z]+/, "variable"]
  213. ],
  214. whitespace: [
  215. [/[ \t\r\n]+/, ''],
  216. [/\/\*\*(?!\/)/, 'comment.doc', '@jsdoc'],
  217. [/\/\*/, 'comment', '@comment'],
  218. [/\/\/\/.*$/, 'comment.doc'],
  219. [/\/\/.*$/, 'comment']
  220. ],
  221. comment: [
  222. [/[^\/*]+/, 'comment'],
  223. [/\*\//, 'comment', '@pop'],
  224. [/[\/*]/, 'comment']
  225. ],
  226. jsdoc: [
  227. [/[^\/*]+/, 'comment.doc'],
  228. [/\*\//, 'comment.doc', '@pop'],
  229. [/[\/*]/, 'comment.doc']
  230. ],
  231. // We match regular expression quite precisely
  232. regexp: [
  233. [
  234. /(\{)(\d+(?:,\d*)?)(\})/,
  235. ['regexp.escape.control', 'regexp.escape.control', 'regexp.escape.control']
  236. ],
  237. [
  238. /(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,
  239. ['regexp.escape.control', { token: 'regexp.escape.control', next: '@regexrange' }]
  240. ],
  241. [/(\()(\?:|\?=|\?!)/, ['regexp.escape.control', 'regexp.escape.control']],
  242. [/[()]/, 'regexp.escape.control'],
  243. [/@regexpctl/, 'regexp.escape.control'],
  244. [/[^\\\/]/, 'regexp'],
  245. [/@regexpesc/, 'regexp.escape'],
  246. [/\\\./, 'regexp.invalid'],
  247. [
  248. /(\/)([gimsuy]*)/,
  249. [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']
  250. ]
  251. ],
  252. regexrange: [
  253. [/-/, 'regexp.escape.control'],
  254. [/\^/, 'regexp.invalid'],
  255. [/@regexpesc/, 'regexp.escape'],
  256. [/[^\]]/, 'regexp'],
  257. [
  258. /\]/,
  259. {
  260. token: 'regexp.escape.control',
  261. next: '@pop',
  262. bracket: '@close'
  263. }
  264. ]
  265. ],
  266. string_double: [
  267. [/[^\\"\$]+/, 'string'],
  268. [/[^\\"]+/, 'string'],
  269. [/@escapes/, 'string.escape'],
  270. [/\\./, 'string.escape.invalid'],
  271. [/"/, 'string', '@pop'],
  272. [/\$\w+/, 'identifier']
  273. ],
  274. string_single: [
  275. [/[^\\'\$]+/, 'string'],
  276. [/@escapes/, 'string.escape'],
  277. [/\\./, 'string.escape.invalid'],
  278. [/'/, 'string', '@pop'],
  279. [/\$\w+/, 'identifier']
  280. ]
  281. }
  282. };