logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

routeros.lua (2090B)


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