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