Skip to content

Commit

Permalink
aded MikroTik RouterOS highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Jul 5, 2020
1 parent 6336a2e commit c7d806b
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/enlighterjs.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/lang/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {python} from './python';
export {qml} from './qml';
export {r} from './r';
export {raw} from './raw';
export {routeros} from './routeros';
export {ruby} from './ruby';
export {rust} from './rust';
export {scala} from './scala';
Expand Down
108 changes: 108 additions & 0 deletions src/lang/routeros.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2020 Andi Dittrich <https://andidittrich.de>
// ----------------------------------------------------------------------

// Generic Rules/Regex
import _language_common_rules from './rulesets/generic';
import {generic} from './generic';

// RouterOS/SwitchOS Language
// Author: [Andi Dittrich]
// --
export class routeros extends generic {

// language aliases
static alias(){
return ['mikrotik', 'mt', 'switchos', 'ros'];
}

setupLanguage() {

this.rules = [

// strings
_language_common_rules.dqStrings,

// multi line strings
{
regex: /("[\s\S]*?")/g,
type: 's5'
},

// boolean expression
{
regex: /\b(yes|no)\b/gi,
type: 'e0'
},

// key-value pairs
{
regex: /\b([\w-]+)(=)/gi,
type: ['k6', 'k3']
},

// variable type/initializations
{
regex: /[^\b](:local|:global)\s/gm,
type: 'k2'
},

// namespaces
{
regex: /^\/\w+(?:\s+[a-z-]+)*\s*$/gm,
type: 'k10'
},

// special common keywords
{
regex: /\b(add|set|print|enable|disable|export|find|get|move|remove)\b/gi,
type: 'k9'
},

// commands
{
regex: /[^\b](:[a-z-]+)\s/gm,
type: 'k0'
},

// variables
{
regex: /\$[\w]*/gi,
type: 'k7'
},

// mac addresses
{
regex: /(?:[a-f0-9]{2}:){5}(?:[a-f0-9]{2})/gi,
type: 's0'
},

// ip4 addresses
{
regex: /(?:\d{1,3}\.){3}(?:\d{1,3})(?:\/\d{1,2})?/gi,
type: 's0'
},

// regular comments
_language_common_rules.poundComments,

// units
{
regex: /[\b\W](-?\d+)([a-z]{1,4})?[\b\W]/gi,
type: 'n0'
},

// numbers
_language_common_rules.int,
_language_common_rules.hex,

// brackets
_language_common_rules.brackets

]
}
}

0 comments on commit c7d806b

Please sign in to comment.