vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

routeros.lua

(2070B)


      1 -- Copyright 2020-2025 Christian Hesse. See LICENSE.
      2 -- Mikrotik RouterOS script LPeg lexer.
      3 
      4 local lexer = require('lexer')
      5 local token, word_match = lexer.token, lexer.word_match
      6 local P, S = lpeg.P, lpeg.S
      7 
      8 local lex = lexer.new('routeros')
      9 
     10 -- Whitespace.
     11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
     12 
     13 -- Keywords.
     14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
     15 	-- Control.
     16 	':delay', ':do', 'on-error', 'while', ':error', ':foreach', 'in', 'do', ':for', 'from', 'to',
     17 	'step', ':if', 'do', 'else', ':return', ':while', 'do',
     18 	-- Menu specific commands.
     19 	'add', 'disable', 'edit', 'enable', 'export', 'find', 'get', 'info', 'monitor', 'print', 'append',
     20 	'as-value', 'brief', 'count-only', 'detail', 'file', 'follow', 'follow-only', 'from', 'interval',
     21 	'terse', 'value-list', 'where', 'without-paging', 'remove', 'set',
     22 	-- Output & string handling.
     23 	':beep', ':blink', ':environment', ':execute', ':find', ':len', ':log', 'alert', 'critical',
     24 	'debug', 'emergency', 'error', 'info', 'notice', 'warning', ':parse', ':pick', ':put',
     25 	':terminal', ':time', ':typeof',
     26 	-- Variable declaration.
     27 	':global', ':local', ':set',
     28 	-- Variable casting.
     29 	':toarray', ':tobool', ':toid', ':toip', ':toip6', ':tonum', ':tostr', ':totime',
     30 	-- Boolean values and logical operators.
     31 	'false', 'no', 'true', 'yes', 'and', 'in', 'or',
     32 	-- Networking.
     33 	':ping', ':resolve'
     34 }))
     35 
     36 -- Identifiers.
     37 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     38 
     39 -- Comments.
     40 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
     41 
     42 -- Numbers.
     43 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
     44 
     45 -- Strings.
     46 lex:add_rule('string', token(lexer.STRING, lexer.range('"')))
     47 
     48 -- Variables.
     49 lex:add_rule('variable', token(lexer.VARIABLE, '$' *
     50 	(S('!#?*@$') + lexer.digit^1 + lexer.word + lexer.range('{', '}', true, false, true))))
     51 
     52 -- Operators.
     53 lex:add_rule('operator', token(lexer.OPERATOR, S('=!%<>+-/*&|~.,;()[]{}')))
     54 
     55 -- Fold points.
     56 lex:add_fold_point(lexer.OPERATOR, '{', '}')
     57 
     58 lexer.property['scintillua.comment'] = '#'
     59 
     60 return lex