awk.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Category: scripting
  7. */
  8. /** @type LanguageFn */
  9. function awk(hljs) {
  10. const VARIABLE = {
  11. className: 'variable',
  12. variants: [
  13. { begin: /\$[\w\d#@][\w\d_]*/ },
  14. { begin: /\$\{(.*?)\}/ }
  15. ]
  16. };
  17. const KEYWORDS = 'BEGIN END if else while do for in break continue delete next nextfile function func exit|10';
  18. const STRING = {
  19. className: 'string',
  20. contains: [ hljs.BACKSLASH_ESCAPE ],
  21. variants: [
  22. {
  23. begin: /(u|b)?r?'''/,
  24. end: /'''/,
  25. relevance: 10
  26. },
  27. {
  28. begin: /(u|b)?r?"""/,
  29. end: /"""/,
  30. relevance: 10
  31. },
  32. {
  33. begin: /(u|r|ur)'/,
  34. end: /'/,
  35. relevance: 10
  36. },
  37. {
  38. begin: /(u|r|ur)"/,
  39. end: /"/,
  40. relevance: 10
  41. },
  42. {
  43. begin: /(b|br)'/,
  44. end: /'/
  45. },
  46. {
  47. begin: /(b|br)"/,
  48. end: /"/
  49. },
  50. hljs.APOS_STRING_MODE,
  51. hljs.QUOTE_STRING_MODE
  52. ]
  53. };
  54. return {
  55. name: 'Awk',
  56. keywords: { keyword: KEYWORDS },
  57. contains: [
  58. VARIABLE,
  59. STRING,
  60. hljs.REGEXP_MODE,
  61. hljs.HASH_COMMENT_MODE,
  62. hljs.NUMBER_MODE
  63. ]
  64. };
  65. }
  66. export { awk as default };