prism-jq.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. greedy: true,
  23. inside: stringInterpolation
  24. },
  25. 'string': {
  26. pattern: string,
  27. greedy: true,
  28. inside: stringInterpolation
  29. },
  30. 'function': {
  31. pattern: /(\bdef\s+)[a-z_]\w+/i,
  32. lookbehind: true
  33. },
  34. 'variable': /\B\$\w+/,
  35. 'property-literal': {
  36. pattern: /\b[a-z_]\w*(?=\s*:(?!:))/i,
  37. alias: 'property'
  38. },
  39. 'keyword': /\b(?:as|break|catch|def|elif|else|end|foreach|if|import|include|label|module|modulemeta|null|reduce|then|try|while)\b/,
  40. 'boolean': /\b(?:true|false)\b/,
  41. 'number': /(?:\b\d+\.|\B\.)?\b\d+(?:[eE][+-]?\d+)?\b/,
  42. 'operator': [
  43. {
  44. pattern: /\|=?/,
  45. alias: 'pipe'
  46. },
  47. /\.\.|[!=<>]?=|\?\/\/|\/\/=?|[-+*/%]=?|[<>?]|\b(?:and|or|not)\b/
  48. ],
  49. 'c-style-function': {
  50. pattern: /\b[a-z_]\w*(?=\s*\()/i,
  51. alias: 'function'
  52. },
  53. 'punctuation': /::|[()\[\]{},:;]|\.(?=\s*[\[\w$])/,
  54. 'dot': {
  55. pattern: /\./,
  56. alias: 'important'
  57. }
  58. }
  59. stringInterpolation.interpolation.inside.content.inside = jq;
  60. }(Prism));