trafficscript.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. pygments.lexers.trafficscript
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for RiverBed's TrafficScript (RTS) language.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer
  9. from pygments.token import String, Number, Name, Keyword, Operator, Text, Comment
  10. __all__ = ['RtsLexer']
  11. class RtsLexer(RegexLexer):
  12. """
  13. For Riverbed Stingray Traffic Manager
  14. """
  15. name = 'TrafficScript'
  16. aliases = ['trafficscript', 'rts']
  17. filenames = ['*.rts']
  18. url = 'https://riverbed.com'
  19. version_added = '2.1'
  20. tokens = {
  21. 'root' : [
  22. (r"'(\\\\|\\[^\\]|[^'\\])*'", String),
  23. (r'"', String, 'escapable-string'),
  24. (r'(0x[0-9a-fA-F]+|\d+)', Number),
  25. (r'\d+\.\d+', Number.Float),
  26. (r'\$[a-zA-Z](\w|_)*', Name.Variable),
  27. (r'(if|else|for(each)?|in|while|do|break|sub|return|import)', Keyword),
  28. (r'[a-zA-Z][\w.]*', Name.Function),
  29. (r'[-+*/%=,;(){}<>^.!~|&\[\]\?\:]', Operator),
  30. (r'(>=|<=|==|!=|'
  31. r'&&|\|\||'
  32. r'\+=|.=|-=|\*=|/=|%=|<<=|>>=|&=|\|=|\^=|'
  33. r'>>|<<|'
  34. r'\+\+|--|=>)', Operator),
  35. (r'[ \t\r]+', Text),
  36. (r'#[^\n]*', Comment),
  37. ],
  38. 'escapable-string' : [
  39. (r'\\[tsn]', String.Escape),
  40. (r'[^"]', String),
  41. (r'"', String, '#pop'),
  42. ],
  43. }