qsharp.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/qsharp/qsharp.ts
  8. var conf = {
  9. comments: {
  10. lineComment: "//"
  11. },
  12. brackets: [
  13. ["{", "}"],
  14. ["[", "]"],
  15. ["(", ")"]
  16. ],
  17. autoClosingPairs: [
  18. { open: "{", close: "}" },
  19. { open: "[", close: "]" },
  20. { open: "(", close: ")" },
  21. { open: '"', close: '"', notIn: ["string", "comment"] }
  22. ],
  23. surroundingPairs: [
  24. { open: "{", close: "}" },
  25. { open: "[", close: "]" },
  26. { open: "(", close: ")" },
  27. { open: '"', close: '"' }
  28. ]
  29. };
  30. var language = {
  31. keywords: [
  32. "namespace",
  33. "open",
  34. "as",
  35. "operation",
  36. "function",
  37. "body",
  38. "adjoint",
  39. "newtype",
  40. "controlled",
  41. "if",
  42. "elif",
  43. "else",
  44. "repeat",
  45. "until",
  46. "fixup",
  47. "for",
  48. "in",
  49. "while",
  50. "return",
  51. "fail",
  52. "within",
  53. "apply",
  54. "Adjoint",
  55. "Controlled",
  56. "Adj",
  57. "Ctl",
  58. "is",
  59. "self",
  60. "auto",
  61. "distribute",
  62. "invert",
  63. "intrinsic",
  64. "let",
  65. "set",
  66. "w/",
  67. "new",
  68. "not",
  69. "and",
  70. "or",
  71. "use",
  72. "borrow",
  73. "using",
  74. "borrowing",
  75. "mutable"
  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. tokenizer: {
  237. root: [
  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. { include: "@whitespace" },
  256. [/[{}()\[\]]/, "@brackets"],
  257. [/@symbols/, { cases: { "@operators": "operator", "@default": "" } }],
  258. [/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
  259. [/\d+/, "number"],
  260. [/[;,.]/, "delimiter"],
  261. [/"/, { token: "string.quote", bracket: "@open", next: "@string" }]
  262. ],
  263. string: [
  264. [/[^\\"]+/, "string"],
  265. [/@escapes/, "string.escape"],
  266. [/"/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  267. ],
  268. namespace: [
  269. { include: "@whitespace" },
  270. [/[A-Za-z]\w*/, "namespace"],
  271. [/[\.=]/, "delimiter"],
  272. ["", "", "@pop"]
  273. ],
  274. whitespace: [
  275. [/[ \t\r\n]+/, "white"],
  276. [/(\/\/).*/, "comment"]
  277. ]
  278. }
  279. };
  280. export {
  281. conf,
  282. language
  283. };