prism-pure.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function (Prism) {
  2. // https://agraef.github.io/pure-docs/pure.html#lexical-matters
  3. Prism.languages.pure = {
  4. 'comment': [
  5. {
  6. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  7. lookbehind: true
  8. },
  9. {
  10. pattern: /(^|[^\\:])\/\/.*/,
  11. lookbehind: true
  12. },
  13. /#!.+/
  14. ],
  15. 'inline-lang': {
  16. pattern: /%<[\s\S]+?%>/,
  17. greedy: true,
  18. inside: {
  19. 'lang': {
  20. pattern: /(^%< *)-\*-.+?-\*-/,
  21. lookbehind: true,
  22. alias: 'comment'
  23. },
  24. 'delimiter': {
  25. pattern: /^%<.*|%>$/,
  26. alias: 'punctuation'
  27. }
  28. }
  29. },
  30. 'string': {
  31. pattern: /"(?:\\.|[^"\\\r\n])*"/,
  32. greedy: true
  33. },
  34. 'number': {
  35. // The look-behind prevents wrong highlighting of the .. operator
  36. pattern: /((?:\.\.)?)(?:\b(?:inf|nan)\b|\b0x[\da-f]+|(?:\b(?:0b)?\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?L?)/i,
  37. lookbehind: true
  38. },
  39. 'keyword': /\b(?:NULL|ans|break|bt|case|catch|cd|clear|const|def|del|dump|else|end|exit|extern|false|force|help|if|infix[lr]?|interface|let|ls|mem|namespace|nonfix|of|otherwise|outfix|override|postfix|prefix|private|public|pwd|quit|run|save|show|stats|then|throw|trace|true|type|underride|using|when|with)\b/,
  40. 'function': /\b(?:abs|add_(?:addr|constdef|(?:fundef|interface|macdef|typedef)(?:_at)?|vardef)|all|any|applp?|arity|bigintp?|blob(?:_crc|_size|p)?|boolp?|byte_c?string(?:_pointer)?|byte_(?:matrix|pointer)|calloc|cat|catmap|ceil|char[ps]?|check_ptrtag|chr|clear_sentry|clearsym|closurep?|cmatrixp?|cols?|colcat(?:map)?|colmap|colrev|colvector(?:p|seq)?|complex(?:_float_(?:matrix|pointer)|_matrix(?:_view)?|_pointer|p)?|conj|cookedp?|cst|cstring(?:_(?:dup|list|vector))?|curry3?|cyclen?|del_(?:constdef|fundef|interface|macdef|typedef|vardef)|delete|diag(?:mat)?|dim|dmatrixp?|do|double(?:_matrix(?:_view)?|_pointer|p)?|dowith3?|drop|dropwhile|eval(?:cmd)?|exactp|filter|fix|fixity|flip|float(?:_matrix|_pointer)|floor|fold[lr]1?|frac|free|funp?|functionp?|gcd|get(?:_(?:byte|constdef|double|float|fundef|int(?:64)?|interface(?:_typedef)?|long|macdef|pointer|ptrtag|sentry|short|string|typedef|vardef))?|globsym|hash|head|id|im|imatrixp?|index|inexactp|infp|init|insert|int(?:_matrix(?:_view)?|_pointer|p)?|int64_(?:matrix|pointer)|integerp?|iteraten?|iterwhile|join|keys?|lambdap?|last(?:err(?:pos)?)?|lcd|list[2p]?|listmap|make_ptrtag|malloc|map|matcat|matrixp?|max|member|min|nanp|nargs|nmatrixp?|null|numberp?|ord|pack(?:ed)?|pointer(?:_cast|_tag|_type|p)?|pow|pred|ptrtag|put(?:_(?:byte|double|float|int(?:64)?|long|pointer|short|string))?|rationalp?|re|realp?|realloc|recordp?|redim|reduce(?:_with)?|refp?|repeatn?|reverse|rlistp?|round|rows?|rowcat(?:map)?|rowmap|rowrev|rowvector(?:p|seq)?|same|scan[lr]1?|sentry|sgn|short_(?:matrix|pointer)|slice|smatrixp?|sort|split|str|strcat|stream|stride|string(?:_(?:dup|list|vector)|p)?|subdiag(?:mat)?|submat|subseq2?|substr|succ|supdiag(?:mat)?|symbolp?|tail|take|takewhile|thunkp?|transpose|trunc|tuplep?|typep|ubyte|uint(?:64)?|ulong|uncurry3?|unref|unzip3?|update|ushort|vals?|varp?|vector(?:p|seq)?|void|zip3?|zipwith3?)\b/,
  41. 'special': {
  42. pattern: /\b__[a-z]+__\b/i,
  43. alias: 'builtin'
  44. },
  45. // Any combination of operator chars can be an operator
  46. // eslint-disable-next-line no-misleading-character-class
  47. 'operator': /(?:[!"#$%&'*+,\-.\/:<=>?@\\^`|~\u00a1-\u00bf\u00d7-\u00f7\u20d0-\u2bff]|\b_+\b)+|\b(?:and|div|mod|not|or)\b/,
  48. // FIXME: How can we prevent | and , to be highlighted as operator when they are used alone?
  49. 'punctuation': /[(){}\[\];,|]/
  50. };
  51. var inlineLanguages = [
  52. 'c',
  53. { lang: 'c++', alias: 'cpp' },
  54. 'fortran'
  55. ];
  56. var inlineLanguageRe = /%< *-\*- *<lang>\d* *-\*-[\s\S]+?%>/.source;
  57. inlineLanguages.forEach(function (lang) {
  58. var alias = lang;
  59. if (typeof lang !== 'string') {
  60. alias = lang.alias;
  61. lang = lang.lang;
  62. }
  63. if (Prism.languages[alias]) {
  64. var o = {};
  65. o['inline-lang-' + alias] = {
  66. pattern: RegExp(inlineLanguageRe.replace('<lang>', lang.replace(/([.+*?\/\\(){}\[\]])/g, '\\$1')), 'i'),
  67. inside: Prism.util.clone(Prism.languages.pure['inline-lang'].inside)
  68. };
  69. o['inline-lang-' + alias].inside.rest = Prism.util.clone(Prism.languages[alias]);
  70. Prism.languages.insertBefore('pure', 'inline-lang', o);
  71. }
  72. });
  73. // C is the default inline language
  74. if (Prism.languages.c) {
  75. Prism.languages.pure['inline-lang'].inside.rest = Prism.util.clone(Prism.languages.c);
  76. }
  77. }(Prism));