qsharp.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. define('vs/basic-languages/qsharp/qsharp',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. comments: {
  11. lineComment: '//'
  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. ],
  24. surroundingPairs: [
  25. { open: '{', close: '}' },
  26. { open: '[', close: ']' },
  27. { open: '(', close: ')' },
  28. { open: '"', close: '"' }
  29. ]
  30. };
  31. exports.language = {
  32. // Set defaultToken to invalid to see what you do not tokenize yet
  33. keywords: [
  34. 'namespace',
  35. 'open',
  36. 'as',
  37. 'operation',
  38. 'function',
  39. 'body',
  40. 'adjoint',
  41. 'newtype',
  42. 'controlled',
  43. 'if',
  44. 'elif',
  45. 'else',
  46. 'repeat',
  47. 'until',
  48. 'fixup',
  49. 'for',
  50. 'in',
  51. 'while',
  52. 'return',
  53. 'fail',
  54. 'within',
  55. 'apply',
  56. 'Adjoint',
  57. 'Controlled',
  58. 'Adj',
  59. 'Ctl',
  60. 'is',
  61. 'self',
  62. 'auto',
  63. 'distribute',
  64. 'invert',
  65. 'intrinsic',
  66. 'let',
  67. 'set',
  68. 'w/',
  69. 'new',
  70. 'not',
  71. 'and',
  72. 'or',
  73. 'use',
  74. 'borrow',
  75. 'using',
  76. 'borrowing',
  77. 'mutable'
  78. ],
  79. typeKeywords: [
  80. 'Unit',
  81. 'Int',
  82. 'BigInt',
  83. 'Double',
  84. 'Bool',
  85. 'String',
  86. 'Qubit',
  87. 'Result',
  88. 'Pauli',
  89. 'Range'
  90. ],
  91. invalidKeywords: [
  92. 'abstract',
  93. 'base',
  94. 'bool',
  95. 'break',
  96. 'byte',
  97. 'case',
  98. 'catch',
  99. 'char',
  100. 'checked',
  101. 'class',
  102. 'const',
  103. 'continue',
  104. 'decimal',
  105. 'default',
  106. 'delegate',
  107. 'do',
  108. 'double',
  109. 'enum',
  110. 'event',
  111. 'explicit',
  112. 'extern',
  113. 'finally',
  114. 'fixed',
  115. 'float',
  116. 'foreach',
  117. 'goto',
  118. 'implicit',
  119. 'int',
  120. 'interface',
  121. 'lock',
  122. 'long',
  123. 'null',
  124. 'object',
  125. 'operator',
  126. 'out',
  127. 'override',
  128. 'params',
  129. 'private',
  130. 'protected',
  131. 'public',
  132. 'readonly',
  133. 'ref',
  134. 'sbyte',
  135. 'sealed',
  136. 'short',
  137. 'sizeof',
  138. 'stackalloc',
  139. 'static',
  140. 'string',
  141. 'struct',
  142. 'switch',
  143. 'this',
  144. 'throw',
  145. 'try',
  146. 'typeof',
  147. 'unit',
  148. 'ulong',
  149. 'unchecked',
  150. 'unsafe',
  151. 'ushort',
  152. 'virtual',
  153. 'void',
  154. 'volatile'
  155. ],
  156. constants: ['true', 'false', 'PauliI', 'PauliX', 'PauliY', 'PauliZ', 'One', 'Zero'],
  157. builtin: [
  158. 'X',
  159. 'Y',
  160. 'Z',
  161. 'H',
  162. 'HY',
  163. 'S',
  164. 'T',
  165. 'SWAP',
  166. 'CNOT',
  167. 'CCNOT',
  168. 'MultiX',
  169. 'R',
  170. 'RFrac',
  171. 'Rx',
  172. 'Ry',
  173. 'Rz',
  174. 'R1',
  175. 'R1Frac',
  176. 'Exp',
  177. 'ExpFrac',
  178. 'Measure',
  179. 'M',
  180. 'MultiM',
  181. 'Message',
  182. 'Length',
  183. 'Assert',
  184. 'AssertProb',
  185. 'AssertEqual'
  186. ],
  187. operators: [
  188. 'and=',
  189. '<-',
  190. '->',
  191. '*',
  192. '*=',
  193. '@',
  194. '!',
  195. '^',
  196. '^=',
  197. ':',
  198. '::',
  199. '..',
  200. '==',
  201. '...',
  202. '=',
  203. '=>',
  204. '>',
  205. '>=',
  206. '<',
  207. '<=',
  208. '-',
  209. '-=',
  210. '!=',
  211. 'or=',
  212. '%',
  213. '%=',
  214. '|',
  215. '+',
  216. '+=',
  217. '?',
  218. '/',
  219. '/=',
  220. '&&&',
  221. '&&&=',
  222. '^^^',
  223. '^^^=',
  224. '>>>',
  225. '>>>=',
  226. '<<<',
  227. '<<<=',
  228. '|||',
  229. '|||=',
  230. '~~~',
  231. '_',
  232. 'w/',
  233. 'w/='
  234. ],
  235. namespaceFollows: ['namespace', 'open'],
  236. symbols: /[=><!~?:&|+\-*\/\^%@._]+/,
  237. escapes: /\\[\s\S]/,
  238. // The main tokenizer for our languages
  239. tokenizer: {
  240. root: [
  241. // identifiers and keywords
  242. [
  243. /[a-zA-Z_$][\w$]*/,
  244. {
  245. cases: {
  246. '@namespaceFollows': {
  247. token: 'keyword.$0',
  248. next: '@namespace'
  249. },
  250. '@typeKeywords': 'type',
  251. '@keywords': 'keyword',
  252. '@constants': 'constant',
  253. '@builtin': 'keyword',
  254. '@invalidKeywords': 'invalid',
  255. '@default': 'identifier'
  256. }
  257. }
  258. ],
  259. // whitespace
  260. { include: '@whitespace' },
  261. // delimiters and operators
  262. [/[{}()\[\]]/, '@brackets'],
  263. [/@symbols/, { cases: { '@operators': 'operator', '@default': '' } }],
  264. // numbers
  265. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  266. [/\d+/, 'number'],
  267. // delimiter: after number because of .\d floats
  268. [/[;,.]/, 'delimiter'],
  269. // strings
  270. //[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
  271. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }]
  272. ],
  273. string: [
  274. [/[^\\"]+/, 'string'],
  275. [/@escapes/, 'string.escape'],
  276. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  277. ],
  278. namespace: [
  279. { include: '@whitespace' },
  280. [/[A-Za-z]\w*/, 'namespace'],
  281. [/[\.=]/, 'delimiter'],
  282. ['', '', '@pop']
  283. ],
  284. whitespace: [
  285. [/[ \t\r\n]+/, 'white'],
  286. [/(\/\/).*/, 'comment']
  287. ]
  288. }
  289. };
  290. });