prism-pascaligo.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function (Prism) {
  2. // Pascaligo is a layer 2 smart contract language for the tezos blockchain
  3. var braces = /\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/.source;
  4. var type = /(?:\b\w+(?:<braces>)?|<braces>)/.source.replace(/<braces>/g, function () { return braces; });
  5. var pascaligo = Prism.languages.pascaligo = {
  6. 'comment': /\(\*[\s\S]+?\*\)|\/\/.*/,
  7. 'string': {
  8. pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\^[a-z]/i,
  9. greedy: true
  10. },
  11. 'class-name': [
  12. {
  13. pattern: RegExp(/(\btype\s+\w+\s+is\s+)<type>/.source.replace(/<type>/g, function () { return type; }), 'i'),
  14. lookbehind: true,
  15. inside: null // see below
  16. },
  17. {
  18. pattern: RegExp(/<type>(?=\s+is\b)/.source.replace(/<type>/g, function () { return type; }), 'i'),
  19. inside: null // see below
  20. },
  21. {
  22. pattern: RegExp(/(:\s*)<type>/.source.replace(/<type>/g, function () { return type; })),
  23. lookbehind: true,
  24. inside: null // see below
  25. }
  26. ],
  27. 'keyword': {
  28. 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,
  29. lookbehind: true
  30. },
  31. 'boolean': {
  32. pattern: /(^|[^&])\b(?:False|True)\b/i,
  33. lookbehind: true
  34. },
  35. 'builtin': {
  36. pattern: /(^|[^&])\b(?:bool|int|list|map|nat|record|string|unit)\b/i,
  37. lookbehind: true
  38. },
  39. 'function': /\b\w+(?=\s*\()/,
  40. 'number': [
  41. // Hexadecimal, octal and binary
  42. /%[01]+|&[0-7]+|\$[a-f\d]+/i,
  43. // Decimal
  44. /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?(?:mtz|n)?/i
  45. ],
  46. 'operator': /->|=\/=|\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=|]|\b(?:and|mod|or)\b/,
  47. 'punctuation': /\(\.|\.\)|[()\[\]:;,.{}]/
  48. };
  49. var classNameInside = ['comment', 'keyword', 'builtin', 'operator', 'punctuation'].reduce(function (accum, key) {
  50. accum[key] = pascaligo[key];
  51. return accum;
  52. }, {});
  53. pascaligo['class-name'].forEach(function (p) {
  54. p.inside = classNameInside;
  55. });
  56. }(Prism));