summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-chaiscript.min.js
blob: a64400b27f2a12cb8546575cfcf5205b21c24e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(Prism.languages.chaiscript = Prism.languages.extend('clike', {
  string: {
    pattern: /(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,
    lookbehind: !0,
    greedy: !0,
  },
  'class-name': [
    { pattern: /(\bclass\s+)\w+/, lookbehind: !0 },
    { pattern: /(\b(?:attr|def)\s+)\w+(?=\s*::)/, lookbehind: !0 },
  ],
  keyword:
    /\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,
  number: [Prism.languages.cpp.number, /\b(?:Infinity|NaN)\b/],
  operator:
    />>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/,
})),
  Prism.languages.insertBefore('chaiscript', 'operator', {
    'parameter-type': {
      pattern: /([,(]\s*)\w+(?=\s+\w)/,
      lookbehind: !0,
      alias: 'class-name',
    },
  }),
  Prism.languages.insertBefore('chaiscript', 'string', {
    'string-interpolation': {
      pattern:
        /(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,
      lookbehind: !0,
      greedy: !0,
      inside: {
        interpolation: {
          pattern:
            /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,
          lookbehind: !0,
          inside: {
            'interpolation-expression': {
              pattern: /(^\$\{)[\s\S]+(?=\}$)/,
              lookbehind: !0,
              inside: Prism.languages.chaiscript,
            },
            'interpolation-punctuation': {
              pattern: /^\$\{|\}$/,
              alias: 'punctuation',
            },
          },
        },
        string: /[\s\S]+/,
      },
    },
  });
/span>+ ')'; }); } return pattern.replace(/<<self>>/g, '[^\\s\\S]'); } // https://docs.microsoft.com/en-us/azure/quantum/user-guide/language/typesystem/ // https://github.com/microsoft/qsharp-language/tree/main/Specifications/Language/5_Grammar var keywordKinds = { // keywords which represent a return or variable type type: 'Adj BigInt Bool Ctl Double false Int One Pauli PauliI PauliX PauliY PauliZ Qubit Range Result String true Unit Zero', // all other keywords other: 'Adjoint adjoint apply as auto body borrow borrowing Controlled controlled distribute elif else fail fixup for function if in internal intrinsic invert is let mutable namespace new newtype open operation repeat return self set until use using while within', }; // keywords function keywordsToPattern(words) { return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b'; } var keywords = RegExp( keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.other) ); // types var identifier = /\b[A-Za-z_]\w*\b/.source; var qualifiedName = replace(/<<0>>(?:\s*\.\s*<<0>>)*/.source, [identifier]); var typeInside = { keyword: keywords, punctuation: /[<>()?,.:[\]]/, }; // strings var regularString = /"(?:\\.|[^\\"])*"/.source; Prism.languages.qsharp = Prism.languages.extend('clike', { comment: /\/\/.*/, string: [ { pattern: re(/(^|[^$\\])<<0>>/.source, [regularString]), lookbehind: true, greedy: true, }, ], 'class-name': [ { // open Microsoft.Quantum.Canon; // open Microsoft.Quantum.Canon as CN; pattern: re(/(\b(?:as|open)\s+)<<0>>(?=\s*(?:;|as\b))/.source, [ qualifiedName, ]), lookbehind: true, inside: typeInside, }, { // namespace Quantum.App1; pattern: re(/(\bnamespace\s+)<<0>>(?=\s*\{)/.source, [qualifiedName]), lookbehind: true, inside: typeInside, }, ], keyword: keywords, number: /(?:\b0(?:x[\da-f]+|b[01]+|o[0-7]+)|(?:\B\.\d+|\b\d+(?:\.\d*)?)(?:e[-+]?\d+)?)l?\b/i, operator: /\band=|\bor=|\band\b|\bnot\b|\bor\b|<[-=]|[-=]>|>>>=?|<<<=?|\^\^\^=?|\|\|\|=?|&&&=?|w\/=?|~~~|[*\/+\-^=!%]=?/, punctuation: /::|[{}[\];(),.:]/, }); Prism.languages.insertBefore('qsharp', 'number', { range: { pattern: /\.\./, alias: 'operator', }, }); // single line var interpolationExpr = nested( replace(/\{(?:[^"{}]|<<0>>|<<self>>)*\}/.source, [regularString]), 2 ); Prism.languages.insertBefore('qsharp', 'string', { 'interpolation-string': { pattern: re(/\$"(?:\\.|<<0>>|[^\\"{])*"/.source, [interpolationExpr]), greedy: true, inside: { interpolation: { pattern: re(/((?:^|[^\\])(?:\\\\)*)<<0>>/.source, [ interpolationExpr, ]), lookbehind: true, inside: { punctuation: /^\{|\}$/, expression: { pattern: /[\s\S]+/, alias: 'language-qsharp', inside: Prism.languages.qsharp, }, }, }, string: /[\s\S]+/, }, }, }); })(Prism); Prism.languages.qs = Prism.languages.qsharp;