routeros.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. Language: Microtik RouterOS script
  3. Author: Ivan Dementev <ivan_div@mail.ru>
  4. Description: Scripting host provides a way to automate some router maintenance tasks by means of executing user-defined scripts bounded to some event occurrence
  5. Website: https://wiki.mikrotik.com/wiki/Manual:Scripting
  6. */
  7. // Colors from RouterOS terminal:
  8. // green - #0E9A00
  9. // teal - #0C9A9A
  10. // purple - #99069A
  11. // light-brown - #9A9900
  12. function routeros(hljs) {
  13. const STATEMENTS = 'foreach do while for if from to step else on-error and or not in';
  14. // Global commands: Every global command should start with ":" token, otherwise it will be treated as variable.
  15. const GLOBAL_COMMANDS = 'global local beep delay put len typeof pick log time set find environment terminal error execute parse resolve toarray tobool toid toip toip6 tonum tostr totime';
  16. // Common commands: Following commands available from most sub-menus:
  17. const COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning';
  18. const LITERALS = 'true false yes no nothing nil null';
  19. const OBJECTS = 'traffic-flow traffic-generator firewall scheduler aaa accounting address-list address align area bandwidth-server bfd bgp bridge client clock community config connection console customer default dhcp-client dhcp-server discovery dns e-mail ethernet filter firmware gps graphing group hardware health hotspot identity igmp-proxy incoming instance interface ip ipsec ipv6 irq l2tp-server lcd ldp logging mac-server mac-winbox mangle manual mirror mme mpls nat nd neighbor network note ntp ospf ospf-v3 ovpn-server page peer pim ping policy pool port ppp pppoe-client pptp-server prefix profile proposal proxy queue radius resource rip ripng route routing screen script security-profiles server service service-port settings shares smb sms sniffer snmp snooper socks sstp-server system tool tracking type upgrade upnp user-manager users user vlan secret vrrp watchdog web-access wireless pptp pppoe lan wan layer7-protocol lease simple raw';
  20. const VAR = {
  21. className: 'variable',
  22. variants: [
  23. {
  24. begin: /\$[\w\d#@][\w\d_]*/
  25. },
  26. {
  27. begin: /\$\{(.*?)\}/
  28. }
  29. ]
  30. };
  31. const QUOTE_STRING = {
  32. className: 'string',
  33. begin: /"/,
  34. end: /"/,
  35. contains: [
  36. hljs.BACKSLASH_ESCAPE,
  37. VAR,
  38. {
  39. className: 'variable',
  40. begin: /\$\(/,
  41. end: /\)/,
  42. contains: [ hljs.BACKSLASH_ESCAPE ]
  43. }
  44. ]
  45. };
  46. const APOS_STRING = {
  47. className: 'string',
  48. begin: /'/,
  49. end: /'/
  50. };
  51. return {
  52. name: 'Microtik RouterOS script',
  53. aliases: [
  54. 'mikrotik'
  55. ],
  56. case_insensitive: true,
  57. keywords: {
  58. $pattern: /:?[\w-]+/,
  59. literal: LITERALS,
  60. keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :')
  61. },
  62. contains: [
  63. { // illegal syntax
  64. variants: [
  65. { // -- comment
  66. begin: /\/\*/,
  67. end: /\*\//
  68. },
  69. { // Stan comment
  70. begin: /\/\//,
  71. end: /$/
  72. },
  73. { // HTML tags
  74. begin: /<\//,
  75. end: />/
  76. }
  77. ],
  78. illegal: /./
  79. },
  80. hljs.COMMENT('^#', '$'),
  81. QUOTE_STRING,
  82. APOS_STRING,
  83. VAR,
  84. // attribute=value
  85. {
  86. // > is to avoid matches with => in other grammars
  87. begin: /[\w-]+=([^\s{}[\]()>]+)/,
  88. relevance: 0,
  89. returnBegin: true,
  90. contains: [
  91. {
  92. className: 'attribute',
  93. begin: /[^=]+/
  94. },
  95. {
  96. begin: /=/,
  97. endsWithParent: true,
  98. relevance: 0,
  99. contains: [
  100. QUOTE_STRING,
  101. APOS_STRING,
  102. VAR,
  103. {
  104. className: 'literal',
  105. begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b'
  106. },
  107. {
  108. // Do not format unclassified values. Needed to exclude highlighting of values as built_in.
  109. begin: /("[^"]*"|[^\s{}[\]]+)/
  110. }
  111. /*
  112. {
  113. // IPv4 addresses and subnets
  114. className: 'number',
  115. variants: [
  116. {begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24
  117. {begin: IPADDR+'-'+IPADDR}, // 192.168.0.1-192.168.0.3
  118. {begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1
  119. ]
  120. },
  121. {
  122. // MAC addresses and DHCP Client IDs
  123. className: 'number',
  124. begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/,
  125. },
  126. */
  127. ]
  128. }
  129. ]
  130. },
  131. {
  132. // HEX values
  133. className: 'number',
  134. begin: /\*[0-9a-fA-F]+/
  135. },
  136. {
  137. begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s[(\\]|])',
  138. returnBegin: true,
  139. contains: [
  140. {
  141. className: 'builtin-name', // 'function',
  142. begin: /\w+/
  143. }
  144. ]
  145. },
  146. {
  147. className: 'built_in',
  148. variants: [
  149. {
  150. begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+'
  151. },
  152. {
  153. begin: /\.\./,
  154. relevance: 0
  155. }
  156. ]
  157. }
  158. ]
  159. };
  160. }
  161. module.exports = routeros;