trafficscript.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. pygments.lexers.trafficscript
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for RiverBed's TrafficScript (RTS) language.
  5. :copyright: Copyright 2006-2023 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. .. versionadded:: 2.1
  15. """
  16. name = 'TrafficScript'
  17. aliases = ['trafficscript', 'rts']
  18. filenames = ['*.rts']
  19. tokens = {
  20. 'root' : [
  21. (r"'(\\\\|\\[^\\]|[^'\\])*'", String),
  22. (r'"', String, 'escapable-string'),
  23. (r'(0x[0-9a-fA-F]+|\d+)', Number),
  24. (r'\d+\.\d+', Number.Float),
  25. (r'\$[a-zA-Z](\w|_)*', Name.Variable),
  26. (r'(if|else|for(each)?|in|while|do|break|sub|return|import)', Keyword),
  27. (r'[a-zA-Z][\w.]*', Name.Function),
  28. (r'[-+*/%=,;(){}<>^.!~|&\[\]\?\:]', Operator),
  29. (r'(>=|<=|==|!=|'
  30. r'&&|\|\||'
  31. r'\+=|.=|-=|\*=|/=|%=|<<=|>>=|&=|\|=|\^=|'
  32. r'>>|<<|'
  33. r'\+\+|--|=>)', Operator),
  34. (r'[ \t\r]+', Text),
  35. (r'#[^\n]*', Comment),
  36. ],
  37. 'escapable-string' : [
  38. (r'\\[tsn]', String.Escape),
  39. (r'[^"]', String),
  40. (r'"', String, '#pop'),
  41. ],
  42. }