qsharp.ts 4.5 KB

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