routeros.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. module.exports = // Colors from RouterOS terminal:
  2. // green - #0E9A00
  3. // teal - #0C9A9A
  4. // purple - #99069A
  5. // light-brown - #9A9900
  6. function(hljs) {
  7. var STATEMENTS = 'foreach do while for if from to step else on-error and or not in';
  8. // Global commands: Every global command should start with ":" token, otherwise it will be treated as variable.
  9. var 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';
  10. // Common commands: Following commands available from most sub-menus:
  11. var COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning';
  12. var LITERALS = 'true false yes no nothing nil null';
  13. var 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 firewall 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';
  14. // print parameters
  15. // Several parameters are available for print command:
  16. // ToDo: var PARAMETERS_PRINT = 'append as-value brief detail count-only file follow follow-only from interval terse value-list without-paging where info';
  17. // ToDo: var OPERATORS = '&& and ! not || or in ~ ^ & << >> + - * /';
  18. // ToDo: var TYPES = 'num number bool boolean str string ip ip6-prefix id time array';
  19. // ToDo: The following tokens serve as delimiters in the grammar: () [] {} : ; $ /
  20. var VAR_PREFIX = 'global local set for foreach';
  21. var VAR = {
  22. className: 'variable',
  23. variants: [
  24. {begin: /\$[\w\d#@][\w\d_]*/},
  25. {begin: /\$\{(.*?)}/}
  26. ]
  27. };
  28. var QUOTE_STRING = {
  29. className: 'string',
  30. begin: /"/, end: /"/,
  31. contains: [
  32. hljs.BACKSLASH_ESCAPE,
  33. VAR,
  34. {
  35. className: 'variable',
  36. begin: /\$\(/, end: /\)/,
  37. contains: [hljs.BACKSLASH_ESCAPE]
  38. }
  39. ]
  40. };
  41. var APOS_STRING = {
  42. className: 'string',
  43. begin: /'/, end: /'/
  44. };
  45. var IPADDR = '((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\b';
  46. var IPADDR_wBITMASK = IPADDR+'/(3[0-2]|[1-2][0-9]|\\d)';
  47. //////////////////////////////////////////////////////////////////////
  48. return {
  49. aliases: ['routeros', 'mikrotik'],
  50. case_insensitive: true,
  51. lexemes: /:?[\w-]+/,
  52. keywords: {
  53. literal: LITERALS,
  54. keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :'),
  55. },
  56. contains: [
  57. { // недопустимые конструкции
  58. variants: [
  59. { begin: /^@/, end: /$/, }, // dns
  60. { begin: /\/\*/, end: /\*\//, }, // -- comment
  61. { begin: /%%/, end: /$/, }, // -- comment
  62. { begin: /^'/, end: /$/, }, // Monkey one line comment
  63. { begin: /^\s*\/[\w-]+=/, end: /$/, }, // jboss-cli
  64. { begin: /\/\//, end: /$/, }, // Stan comment
  65. { begin: /^\[\</, end: /\>\]$/, }, // F# class declaration?
  66. { begin: /<\//, end: />/, }, // HTML tags
  67. { begin: /^facet /, end: /\}/, }, // roboconf - лютый костыль )))
  68. { begin: '^1\\.\\.(\\d+)$', end: /$/, }, // tap
  69. ],
  70. illegal: /./,
  71. },
  72. hljs.COMMENT('^#', '$'),
  73. QUOTE_STRING,
  74. APOS_STRING,
  75. VAR,
  76. { // attribute=value
  77. begin: /[\w-]+\=([^\s\{\}\[\]\(\)]+)/,
  78. relevance: 0,
  79. returnBegin: true,
  80. contains: [
  81. {
  82. className: 'attribute',
  83. begin: /[^=]+/
  84. },
  85. {
  86. begin: /=/,
  87. endsWithParent: true,
  88. relevance: 0,
  89. contains: [
  90. QUOTE_STRING,
  91. APOS_STRING,
  92. VAR,
  93. {
  94. className: 'literal',
  95. begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b',
  96. },
  97. /*{
  98. // IPv4 addresses and subnets
  99. className: 'number',
  100. variants: [
  101. {begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24
  102. {begin: IPADDR+'-'+IPADDR}, // 192.168.0.1-192.168.0.3
  103. {begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1
  104. ]
  105. }, // */
  106. /*{
  107. // MAC addresses and DHCP Client IDs
  108. className: 'number',
  109. begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/,
  110. }, //*/
  111. {
  112. // Не форматировать не классифицированные значения. Необходимо для исключения подсветки значений как built_in.
  113. // className: 'number',
  114. begin: /("[^"]*"|[^\s\{\}\[\]]+)/,
  115. }, //*/
  116. ]
  117. } //*/
  118. ]
  119. },//*/
  120. {
  121. // HEX values
  122. className: 'number',
  123. begin: /\*[0-9a-fA-F]+/,
  124. }, //*/
  125. {
  126. begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s\[\(]|\])',
  127. returnBegin: true,
  128. contains: [
  129. {
  130. className: 'builtin-name', //'function',
  131. begin: /\w+/,
  132. },
  133. ],
  134. },
  135. {
  136. className: 'built_in',
  137. variants: [
  138. {begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+',relevance: 10,},
  139. {begin: /\.\./,},
  140. ],
  141. },//*/
  142. ]
  143. };
  144. };