routeros.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. Language: MikroTik 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. Category: scripting
  7. */
  8. // Colors from RouterOS terminal:
  9. // green - #0E9A00
  10. // teal - #0C9A9A
  11. // purple - #99069A
  12. // light-brown - #9A9900
  13. function routeros(hljs) {
  14. const STATEMENTS = 'foreach do while for if from to step else on-error and or not in';
  15. // Global commands: Every global command should start with ":" token, otherwise it will be treated as variable.
  16. 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';
  17. // Common commands: Following commands available from most sub-menus:
  18. const COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning';
  19. const LITERALS = 'true false yes no nothing nil null';
  20. 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';
  21. const VAR = {
  22. className: 'variable',
  23. variants: [
  24. { begin: /\$[\w\d#@][\w\d_]*/ },
  25. { begin: /\$\{(.*?)\}/ }
  26. ]
  27. };
  28. const QUOTE_STRING = {
  29. className: 'string',
  30. begin: /"/,
  31. end: /"/,
  32. contains: [
  33. hljs.BACKSLASH_ESCAPE,
  34. VAR,
  35. {
  36. className: 'variable',
  37. begin: /\$\(/,
  38. end: /\)/,
  39. contains: [ hljs.BACKSLASH_ESCAPE ]
  40. }
  41. ]
  42. };
  43. const APOS_STRING = {
  44. className: 'string',
  45. begin: /'/,
  46. end: /'/
  47. };
  48. return {
  49. name: 'MikroTik RouterOS script',
  50. aliases: [ 'mikrotik' ],
  51. case_insensitive: true,
  52. keywords: {
  53. $pattern: /:?[\w-]+/,
  54. literal: LITERALS,
  55. keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :')
  56. },
  57. contains: [
  58. { // illegal syntax
  59. variants: [
  60. { // -- comment
  61. begin: /\/\*/,
  62. end: /\*\//
  63. },
  64. { // Stan comment
  65. begin: /\/\//,
  66. end: /$/
  67. },
  68. { // HTML tags
  69. begin: /<\//,
  70. end: />/
  71. }
  72. ],
  73. illegal: /./
  74. },
  75. hljs.COMMENT('^#', '$'),
  76. QUOTE_STRING,
  77. APOS_STRING,
  78. VAR,
  79. // attribute=value
  80. {
  81. // > is to avoid matches with => in other grammars
  82. begin: /[\w-]+=([^\s{}[\]()>]+)/,
  83. relevance: 0,
  84. returnBegin: true,
  85. contains: [
  86. {
  87. className: 'attribute',
  88. begin: /[^=]+/
  89. },
  90. {
  91. begin: /=/,
  92. endsWithParent: true,
  93. relevance: 0,
  94. contains: [
  95. QUOTE_STRING,
  96. APOS_STRING,
  97. VAR,
  98. {
  99. className: 'literal',
  100. begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b'
  101. },
  102. {
  103. // Do not format unclassified values. Needed to exclude highlighting of values as built_in.
  104. begin: /("[^"]*"|[^\s{}[\]]+)/ }
  105. /*
  106. {
  107. // IPv4 addresses and subnets
  108. className: 'number',
  109. variants: [
  110. {begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24
  111. {begin: IPADDR+'-'+IPADDR}, // 192.168.0.1-192.168.0.3
  112. {begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1
  113. ]
  114. },
  115. {
  116. // MAC addresses and DHCP Client IDs
  117. className: 'number',
  118. begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/,
  119. },
  120. */
  121. ]
  122. }
  123. ]
  124. },
  125. {
  126. // HEX values
  127. className: 'number',
  128. begin: /\*[0-9a-fA-F]+/
  129. },
  130. {
  131. begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s[(\\]|])',
  132. returnBegin: true,
  133. contains: [
  134. {
  135. className: 'built_in', // 'function',
  136. begin: /\w+/
  137. }
  138. ]
  139. },
  140. {
  141. className: 'built_in',
  142. variants: [
  143. { begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+' },
  144. {
  145. begin: /\.\./,
  146. relevance: 0
  147. }
  148. ]
  149. }
  150. ]
  151. };
  152. }
  153. export { routeros as default };