prism-batch.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. (function (Prism) {
  2. var variable = /%%?[~:\w]+%?|!\S+!/;
  3. var parameter = {
  4. pattern: /\/[a-z?]+(?=[ :]|$):?|-[a-z]\b|--[a-z-]+\b/im,
  5. alias: 'attr-name',
  6. inside: {
  7. 'punctuation': /:/
  8. }
  9. };
  10. var string = /"(?:[\\"]"|[^"])*"(?!")/;
  11. var number = /(?:\b|-)\d+\b/;
  12. Prism.languages.batch = {
  13. 'comment': [
  14. /^::.*/m,
  15. {
  16. pattern: /((?:^|[&(])[ \t]*)rem\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
  17. lookbehind: true
  18. }
  19. ],
  20. 'label': {
  21. pattern: /^:.*/m,
  22. alias: 'property'
  23. },
  24. 'command': [
  25. {
  26. // FOR command
  27. pattern: /((?:^|[&(])[ \t]*)for(?: \/[a-z?](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* \S+ in \([^)]+\) do/im,
  28. lookbehind: true,
  29. inside: {
  30. 'keyword': /\b(?:do|in)\b|^for\b/i,
  31. 'string': string,
  32. 'parameter': parameter,
  33. 'variable': variable,
  34. 'number': number,
  35. 'punctuation': /[()',]/
  36. }
  37. },
  38. {
  39. // IF command
  40. pattern: /((?:^|[&(])[ \t]*)if(?: \/[a-z?](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* (?:not )?(?:cmdextversion \d+|defined \w+|errorlevel \d+|exist \S+|(?:"[^"]*"|(?!")(?:(?!==)\S)+)?(?:==| (?:equ|geq|gtr|leq|lss|neq) )(?:"[^"]*"|[^\s"]\S*))/im,
  41. lookbehind: true,
  42. inside: {
  43. 'keyword': /\b(?:cmdextversion|defined|errorlevel|exist|not)\b|^if\b/i,
  44. 'string': string,
  45. 'parameter': parameter,
  46. 'variable': variable,
  47. 'number': number,
  48. 'operator': /\^|==|\b(?:equ|geq|gtr|leq|lss|neq)\b/i
  49. }
  50. },
  51. {
  52. // ELSE command
  53. pattern: /((?:^|[&()])[ \t]*)else\b/im,
  54. lookbehind: true,
  55. inside: {
  56. 'keyword': /^else\b/i
  57. }
  58. },
  59. {
  60. // SET command
  61. pattern: /((?:^|[&(])[ \t]*)set(?: \/[a-z](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* (?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
  62. lookbehind: true,
  63. inside: {
  64. 'keyword': /^set\b/i,
  65. 'string': string,
  66. 'parameter': parameter,
  67. 'variable': [
  68. variable,
  69. /\w+(?=(?:[*\/%+\-&^|]|<<|>>)?=)/
  70. ],
  71. 'number': number,
  72. 'operator': /[*\/%+\-&^|]=?|<<=?|>>=?|[!~_=]/,
  73. 'punctuation': /[()',]/
  74. }
  75. },
  76. {
  77. // Other commands
  78. pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:"(?:[\\"]"|[^"])*"(?!")|[^"^&)\r\n]|\^(?:\r\n|[\s\S]))*/m,
  79. lookbehind: true,
  80. inside: {
  81. 'keyword': /^\w+\b/,
  82. 'string': string,
  83. 'parameter': parameter,
  84. 'label': {
  85. pattern: /(^\s*):\S+/m,
  86. lookbehind: true,
  87. alias: 'property'
  88. },
  89. 'variable': variable,
  90. 'number': number,
  91. 'operator': /\^/
  92. }
  93. }
  94. ],
  95. 'operator': /[&@]/,
  96. 'punctuation': /[()']/
  97. };
  98. }(Prism));