prism-gn.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // https://gn.googlesource.com/gn/+/refs/heads/main/docs/reference.md#grammar
  2. Prism.languages.gn = {
  3. 'comment': {
  4. pattern: /#.*/,
  5. greedy: true
  6. },
  7. 'string-literal': {
  8. pattern: /(^|[^\\"])"(?:[^\r\n"\\]|\\.)*"/,
  9. lookbehind: true,
  10. greedy: true,
  11. inside: {
  12. 'interpolation': {
  13. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[\s\S]*?\}|[a-zA-Z_]\w*|0x[a-fA-F0-9]{2})/,
  14. lookbehind: true,
  15. inside: {
  16. 'number': /^\$0x[\s\S]{2}$/,
  17. 'variable': /^\$\w+$/,
  18. 'interpolation-punctuation': {
  19. pattern: /^\$\{|\}$/,
  20. alias: 'punctuation'
  21. },
  22. 'expression': {
  23. pattern: /[\s\S]+/,
  24. inside: null // see below
  25. }
  26. }
  27. },
  28. 'string': /[\s\S]+/
  29. }
  30. },
  31. 'keyword': /\b(?:else|if)\b/,
  32. 'boolean': /\b(?:false|true)\b/,
  33. 'builtin-function': {
  34. // a few functions get special highlighting to improve readability
  35. pattern: /\b(?:assert|defined|foreach|import|pool|print|template|tool|toolchain)(?=\s*\()/i,
  36. alias: 'keyword'
  37. },
  38. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  39. 'constant': /\b(?:current_cpu|current_os|current_toolchain|default_toolchain|host_cpu|host_os|root_build_dir|root_gen_dir|root_out_dir|target_cpu|target_gen_dir|target_os|target_out_dir)\b/,
  40. 'number': /-?\b\d+\b/,
  41. 'operator': /[-+!=<>]=?|&&|\|\|/,
  42. 'punctuation': /[(){}[\],.]/
  43. };
  44. Prism.languages.gn['string-literal'].inside['interpolation'].inside['expression'].inside = Prism.languages.gn;
  45. Prism.languages.gni = Prism.languages.gn;