prism-jq.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. (function (Prism) {
  2. var interpolation = /\\\((?:[^()]|\([^()]*\))*\)/.source;
  3. var string = RegExp(/(^|[^\\])"(?:[^"\r\n\\]|\\[^\r\n(]|__)*"/.source.replace(/__/g, function () { return interpolation; }));
  4. var stringInterpolation = {
  5. 'interpolation': {
  6. pattern: RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + interpolation),
  7. lookbehind: true,
  8. inside: {
  9. 'content': {
  10. pattern: /^(\\\()[\s\S]+(?=\)$)/,
  11. lookbehind: true,
  12. inside: null // see below
  13. },
  14. 'punctuation': /^\\\(|\)$/
  15. }
  16. }
  17. };
  18. var jq = Prism.languages.jq = {
  19. 'comment': /#.*/,
  20. 'property': {
  21. pattern: RegExp(string.source + /(?=\s*:(?!:))/.source),
  22. lookbehind: true,
  23. greedy: true,
  24. inside: stringInterpolation
  25. },
  26. 'string': {
  27. pattern: string,
  28. lookbehind: true,
  29. greedy: true,
  30. inside: stringInterpolation
  31. },
  32. 'function': {
  33. pattern: /(\bdef\s+)[a-z_]\w+/i,
  34. lookbehind: true
  35. },
  36. 'variable': /\B\$\w+/,
  37. 'property-literal': {
  38. pattern: /\b[a-z_]\w*(?=\s*:(?!:))/i,
  39. alias: 'property'
  40. },
  41. 'keyword': /\b(?:as|break|catch|def|elif|else|end|foreach|if|import|include|label|module|modulemeta|null|reduce|then|try|while)\b/,
  42. 'boolean': /\b(?:false|true)\b/,
  43. 'number': /(?:\b\d+\.|\B\.)?\b\d+(?:[eE][+-]?\d+)?\b/,
  44. 'operator': [
  45. {
  46. pattern: /\|=?/,
  47. alias: 'pipe'
  48. },
  49. /\.\.|[!=<>]?=|\?\/\/|\/\/=?|[-+*/%]=?|[<>?]|\b(?:and|not|or)\b/
  50. ],
  51. 'c-style-function': {
  52. pattern: /\b[a-z_]\w*(?=\s*\()/i,
  53. alias: 'function'
  54. },
  55. 'punctuation': /::|[()\[\]{},:;]|\.(?=\s*[\[\w$])/,
  56. 'dot': {
  57. pattern: /\./,
  58. alias: 'important'
  59. }
  60. };
  61. stringInterpolation.interpolation.inside.content.inside = jq;
  62. }(Prism));