trafficscript.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """
  2. pygments.lexers.trafficscript
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for RiverBed's TrafficScript (RTS) language.
  5. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer
  10. from pygments.token import String, Number, Name, Keyword, Operator, Text, Comment
  11. __all__ = ['RtsLexer']
  12. class RtsLexer(RegexLexer):
  13. """
  14. For `Riverbed Stingray Traffic Manager <http://www.riverbed.com/stingray>`_
  15. .. versionadded:: 2.1
  16. """
  17. name = 'TrafficScript'
  18. aliases = ['trafficscript', 'rts']
  19. filenames = ['*.rts']
  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. }