1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
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 |
|
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 |
|
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 | {
|
74 | variants: [
|
75 | {
|
76 | begin: /\/\*/,
|
77 | end: /\*\//
|
78 | },
|
79 | {
|
80 | begin: /\/\//,
|
81 | end: /$/
|
82 | },
|
83 | {
|
84 | begin: /<\//,
|
85 | end: />/
|
86 | }
|
87 | ],
|
88 | illegal: /./
|
89 | },
|
90 | hljs.COMMENT('^#', '$'),
|
91 | QUOTE_STRING,
|
92 | APOS_STRING,
|
93 | VAR,
|
94 |
|
95 | {
|
96 |
|
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 |
|
119 | begin: /("[^"]*"|[^\s{}[\]]+)/
|
120 | }
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | ]
|
138 | }
|
139 | ]
|
140 | },
|
141 | {
|
142 |
|
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: 'built_in',
|
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 | export { routeros as default };
|