awk.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Language: Awk
  3. Author: Matthew Daly <matthewbdaly@gmail.com>
  4. Website: https://www.gnu.org/software/gawk/manual/gawk.html
  5. Description: language definition for Awk scripts
  6. */
  7. /** @type LanguageFn */
  8. function awk(hljs) {
  9. const VARIABLE = {
  10. className: 'variable',
  11. variants: [
  12. {
  13. begin: /\$[\w\d#@][\w\d_]*/
  14. },
  15. {
  16. begin: /\$\{(.*?)\}/
  17. }
  18. ]
  19. };
  20. const KEYWORDS = 'BEGIN END if else while do for in break continue delete next nextfile function func exit|10';
  21. const STRING = {
  22. className: 'string',
  23. contains: [hljs.BACKSLASH_ESCAPE],
  24. variants: [
  25. {
  26. begin: /(u|b)?r?'''/,
  27. end: /'''/,
  28. relevance: 10
  29. },
  30. {
  31. begin: /(u|b)?r?"""/,
  32. end: /"""/,
  33. relevance: 10
  34. },
  35. {
  36. begin: /(u|r|ur)'/,
  37. end: /'/,
  38. relevance: 10
  39. },
  40. {
  41. begin: /(u|r|ur)"/,
  42. end: /"/,
  43. relevance: 10
  44. },
  45. {
  46. begin: /(b|br)'/,
  47. end: /'/
  48. },
  49. {
  50. begin: /(b|br)"/,
  51. end: /"/
  52. },
  53. hljs.APOS_STRING_MODE,
  54. hljs.QUOTE_STRING_MODE
  55. ]
  56. };
  57. return {
  58. name: 'Awk',
  59. keywords: {
  60. keyword: KEYWORDS
  61. },
  62. contains: [
  63. VARIABLE,
  64. STRING,
  65. hljs.REGEXP_MODE,
  66. hljs.HASH_COMMENT_MODE,
  67. hljs.NUMBER_MODE
  68. ]
  69. };
  70. }
  71. module.exports = awk;