qsharp.js 6.1 KB

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