dos.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. Language: Batch file (DOS)
  3. Author: Alexander Makarov <sam@rmcreative.ru>
  4. Contributors: Anton Kochkov <anton.kochkov@gmail.com>
  5. Website: https://en.wikipedia.org/wiki/Batch_file
  6. Category: scripting
  7. */
  8. /** @type LanguageFn */
  9. function dos(hljs) {
  10. const COMMENT = hljs.COMMENT(
  11. /^\s*@?rem\b/, /$/,
  12. { relevance: 10 }
  13. );
  14. const LABEL = {
  15. className: 'symbol',
  16. begin: '^\\s*[A-Za-z._?][A-Za-z0-9_$#@~.?]*(:|\\s+label)',
  17. relevance: 0
  18. };
  19. const KEYWORDS = [
  20. "if",
  21. "else",
  22. "goto",
  23. "for",
  24. "in",
  25. "do",
  26. "call",
  27. "exit",
  28. "not",
  29. "exist",
  30. "errorlevel",
  31. "defined",
  32. "equ",
  33. "neq",
  34. "lss",
  35. "leq",
  36. "gtr",
  37. "geq"
  38. ];
  39. const BUILT_INS = [
  40. "prn",
  41. "nul",
  42. "lpt3",
  43. "lpt2",
  44. "lpt1",
  45. "con",
  46. "com4",
  47. "com3",
  48. "com2",
  49. "com1",
  50. "aux",
  51. "shift",
  52. "cd",
  53. "dir",
  54. "echo",
  55. "setlocal",
  56. "endlocal",
  57. "set",
  58. "pause",
  59. "copy",
  60. "append",
  61. "assoc",
  62. "at",
  63. "attrib",
  64. "break",
  65. "cacls",
  66. "cd",
  67. "chcp",
  68. "chdir",
  69. "chkdsk",
  70. "chkntfs",
  71. "cls",
  72. "cmd",
  73. "color",
  74. "comp",
  75. "compact",
  76. "convert",
  77. "date",
  78. "dir",
  79. "diskcomp",
  80. "diskcopy",
  81. "doskey",
  82. "erase",
  83. "fs",
  84. "find",
  85. "findstr",
  86. "format",
  87. "ftype",
  88. "graftabl",
  89. "help",
  90. "keyb",
  91. "label",
  92. "md",
  93. "mkdir",
  94. "mode",
  95. "more",
  96. "move",
  97. "path",
  98. "pause",
  99. "print",
  100. "popd",
  101. "pushd",
  102. "promt",
  103. "rd",
  104. "recover",
  105. "rem",
  106. "rename",
  107. "replace",
  108. "restore",
  109. "rmdir",
  110. "shift",
  111. "sort",
  112. "start",
  113. "subst",
  114. "time",
  115. "title",
  116. "tree",
  117. "type",
  118. "ver",
  119. "verify",
  120. "vol",
  121. // winutils
  122. "ping",
  123. "net",
  124. "ipconfig",
  125. "taskkill",
  126. "xcopy",
  127. "ren",
  128. "del"
  129. ];
  130. return {
  131. name: 'Batch file (DOS)',
  132. aliases: [
  133. 'bat',
  134. 'cmd'
  135. ],
  136. case_insensitive: true,
  137. illegal: /\/\*/,
  138. keywords: {
  139. keyword: KEYWORDS,
  140. built_in: BUILT_INS
  141. },
  142. contains: [
  143. {
  144. className: 'variable',
  145. begin: /%%[^ ]|%[^ ]+?%|![^ ]+?!/
  146. },
  147. {
  148. className: 'function',
  149. begin: LABEL.begin,
  150. end: 'goto:eof',
  151. contains: [
  152. hljs.inherit(hljs.TITLE_MODE, { begin: '([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*' }),
  153. COMMENT
  154. ]
  155. },
  156. {
  157. className: 'number',
  158. begin: '\\b\\d+',
  159. relevance: 0
  160. },
  161. COMMENT
  162. ]
  163. };
  164. }
  165. export { dos as default };