qsharp.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. ],
  76. typeKeywords: [
  77. 'Unit',
  78. 'Int',
  79. 'BigInt',
  80. 'Double',
  81. 'Bool',
  82. 'String',
  83. 'Qubit',
  84. 'Result',
  85. 'Pauli',
  86. 'Range'
  87. ],
  88. invalidKeywords: [
  89. 'abstract',
  90. 'base',
  91. 'bool',
  92. 'break',
  93. 'byte',
  94. 'case',
  95. 'catch',
  96. 'char',
  97. 'checked',
  98. 'class',
  99. 'const',
  100. 'continue',
  101. 'decimal',
  102. 'default',
  103. 'delegate',
  104. 'do',
  105. 'double',
  106. 'enum',
  107. 'event',
  108. 'explicit',
  109. 'extern',
  110. 'finally',
  111. 'fixed',
  112. 'float',
  113. 'foreach',
  114. 'goto',
  115. 'implicit',
  116. 'int',
  117. 'interface',
  118. 'lock',
  119. 'long',
  120. 'null',
  121. 'object',
  122. 'operator',
  123. 'out',
  124. 'override',
  125. 'params',
  126. 'private',
  127. 'protected',
  128. 'public',
  129. 'readonly',
  130. 'ref',
  131. 'sbyte',
  132. 'sealed',
  133. 'short',
  134. 'sizeof',
  135. 'stackalloc',
  136. 'static',
  137. 'string',
  138. 'struct',
  139. 'switch',
  140. 'this',
  141. 'throw',
  142. 'try',
  143. 'typeof',
  144. 'unit',
  145. 'ulong',
  146. 'unchecked',
  147. 'unsafe',
  148. 'ushort',
  149. 'virtual',
  150. 'void',
  151. 'volatile'
  152. ],
  153. constants: ['true', 'false', 'PauliI', 'PauliX', 'PauliY', 'PauliZ', 'One', 'Zero'],
  154. builtin: [
  155. 'X',
  156. 'Y',
  157. 'Z',
  158. 'H',
  159. 'HY',
  160. 'S',
  161. 'T',
  162. 'SWAP',
  163. 'CNOT',
  164. 'CCNOT',
  165. 'MultiX',
  166. 'R',
  167. 'RFrac',
  168. 'Rx',
  169. 'Ry',
  170. 'Rz',
  171. 'R1',
  172. 'R1Frac',
  173. 'Exp',
  174. 'ExpFrac',
  175. 'Measure',
  176. 'M',
  177. 'MultiM',
  178. 'Message',
  179. 'Length',
  180. 'Assert',
  181. 'AssertProb',
  182. 'AssertEqual'
  183. ],
  184. operators: [
  185. 'and=',
  186. '<-',
  187. '->',
  188. '*',
  189. '*=',
  190. '@',
  191. '!',
  192. '^',
  193. '^=',
  194. ':',
  195. '::',
  196. '..',
  197. '==',
  198. '...',
  199. '=',
  200. '=>',
  201. '>',
  202. '>=',
  203. '<',
  204. '<=',
  205. '-',
  206. '-=',
  207. '!=',
  208. 'or=',
  209. '%',
  210. '%=',
  211. '|',
  212. '+',
  213. '+=',
  214. '?',
  215. '/',
  216. '/=',
  217. '&&&',
  218. '&&&=',
  219. '^^^',
  220. '^^^=',
  221. '>>>',
  222. '>>>=',
  223. '<<<',
  224. '<<<=',
  225. '|||',
  226. '|||=',
  227. '~~~',
  228. '_',
  229. 'w/',
  230. 'w/='
  231. ],
  232. namespaceFollows: ['namespace', 'open'],
  233. symbols: /[=><!~?:&|+\-*\/\^%@._]+/,
  234. escapes: /\\[\s\S]/,
  235. // The main tokenizer for our languages
  236. tokenizer: {
  237. root: [
  238. // identifiers and keywords
  239. [
  240. /[a-zA-Z_$][\w$]*/,
  241. {
  242. cases: {
  243. '@namespaceFollows': {
  244. token: 'keyword.$0',
  245. next: '@namespace'
  246. },
  247. '@typeKeywords': 'type',
  248. '@keywords': 'keyword',
  249. '@constants': 'constant',
  250. '@builtin': 'keyword',
  251. '@invalidKeywords': 'invalid',
  252. '@default': 'identifier'
  253. }
  254. }
  255. ],
  256. // whitespace
  257. { include: '@whitespace' },
  258. // delimiters and operators
  259. [/[{}()\[\]]/, '@brackets'],
  260. [/@symbols/, { cases: { '@operators': 'operator', '@default': '' } }],
  261. // numbers
  262. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  263. [/\d+/, 'number'],
  264. // delimiter: after number because of .\d floats
  265. [/[;,.]/, 'delimiter'],
  266. // strings
  267. //[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
  268. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }]
  269. ],
  270. string: [
  271. [/[^\\"]+/, 'string'],
  272. [/@escapes/, 'string.escape'],
  273. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  274. ],
  275. namespace: [
  276. { include: '@whitespace' },
  277. [/[A-Za-z]\w*/, 'namespace'],
  278. [/[\.=]/, 'delimiter'],
  279. ['', '', '@pop']
  280. ],
  281. whitespace: [
  282. [/[ \t\r\n]+/, 'white'],
  283. [/(\/\/).*/, 'comment']
  284. ]
  285. }
  286. };