trafficscript.py 1.5 KB

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