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