summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-pascaligo.js
blob: 337ddef8b128d9a5e922bd81a885b87414f80b34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: 
(function (Prism) {
  // Pascaligo is a layer 2 smart contract language for the tezos blockchain

  var braces = /\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/.source;
  var type = /(?:\b\w+(?:<braces>)?|<braces>)/.source.replace(
    /<braces>/g,
    function () {
      return braces;
    }
  );

  var pascaligo = (Prism.languages.pascaligo = {
    comment: /\(\*[\s\S]+?\*\)|\/\/.*/,
    string: {
      pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\^[a-z]/i,
      greedy: true,
    },
    'class-name': [
      {
        pattern: RegExp(
          /(\btype\s+\w+\s+is\s+)<type>/.source.replace(/<type>/g, function () {
            return type;
          }),
          'i'
        ),
        lookbehind: true,
        inside: null, // see below
      },
      {
        pattern: RegExp(
          /<type>(?=\s+is\b)/.source.replace(/<type>/g, function () {
            return type;
          }),
          'i'
        ),
        inside: null, // see below
      },
      {
        pattern: RegExp(
          /(:\s*)<type>/.source.replace(/<type>/g, function () {
            return type;
          })
        ),
        lookbehind: true,
        inside: null, // see below
      },
    ],
    keyword: {
      pattern:
        /(^|[^&])\b(?:begin|block|case|const|else|end|fail|for|from|function|if|is|nil|of|remove|return|skip|then|type|var|while|with)\b/i,
      lookbehind: true,
    },
    boolean: {
      pattern: /(^|[^&])\b(?:False|True)\b/i,
      lookbehind: true,
    },
    builtin: {
      pattern: /(^|[^&])\b(?:bool|int|list|map|nat|record|string|unit)\b/i,
      lookbehind: true,
    },
    function: /\b\w+(?=\s*\()/,
    number: [
      // Hexadecimal, octal and binary
      /%[01]+|&[0-7]+|\$[a-f\d]+/i,
      // Decimal
      /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?(?:mtz|n)?/i,
    ],
    operator:
      /->|=\/=|\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=|]|\b(?:and|mod|or)\b/,
    punctuation: /\(\.|\.\)|[()\[\]:;,.{}]/,
  });

  var classNameInside = [
    'comment',
    'keyword',
    'builtin',
    'operator',
    'punctuation',
  ].reduce(function (accum, key) {
    accum[key] = pascaligo[key];
    return accum;
  }, {});

  pascaligo['class-name'].forEach(function (p) {
    p.inside = classNameInside;
  });
})(Prism);