prism-parigp.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. Prism.languages.parigp = {
  2. 'comment': /\/\*[\s\S]*?\*\/|\\\\.*/,
  3. 'string': {
  4. pattern: /"(?:[^"\\\r\n]|\\.)*"/,
  5. greedy: true
  6. },
  7. // PARI/GP does not care about white spaces at all
  8. // so let's process the keywords to build an appropriate regexp
  9. // (e.g. "b *r *e *a *k", etc.)
  10. 'keyword': (function () {
  11. var keywords = [
  12. 'breakpoint', 'break', 'dbg_down', 'dbg_err', 'dbg_up', 'dbg_x',
  13. 'forcomposite', 'fordiv', 'forell', 'forpart', 'forprime',
  14. 'forstep', 'forsubgroup', 'forvec', 'for', 'iferr', 'if',
  15. 'local', 'my', 'next', 'return', 'until', 'while'
  16. ];
  17. keywords = keywords.map(function (keyword) {
  18. return keyword.split('').join(' *');
  19. }).join('|');
  20. return RegExp('\\b(?:' + keywords + ')\\b');
  21. }()),
  22. 'function': /\b\w(?:[\w ]*\w)?(?= *\()/,
  23. 'number': {
  24. // The lookbehind and the negative lookahead prevent from breaking the .. operator
  25. pattern: /((?:\. *\. *)?)(?:\b\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *(?:[+-] *)?\d(?: *\d)*)?/i,
  26. lookbehind: true
  27. },
  28. 'operator': /\. *\.|[*\/!](?: *=)?|%(?: *=|(?: *#)?(?: *')*)?|\+(?: *[+=])?|-(?: *[-=>])?|<(?: *>|(?: *<)?(?: *=)?)?|>(?: *>)?(?: *=)?|=(?: *=){0,2}|\\(?: *\/)?(?: *=)?|&(?: *&)?|\| *\||['#~^]/,
  29. 'punctuation': /[\[\]{}().,:;|]/
  30. };