tls.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. pygments.lexers.tls
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexers for the TLS presentation language.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, words
  10. from pygments.token import Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation, Whitespace
  12. __all__ = ['TlsLexer']
  13. class TlsLexer(RegexLexer):
  14. """
  15. The TLS presentation language, described in RFC 8446.
  16. """
  17. name = 'TLS Presentation Language'
  18. url = 'https://www.rfc-editor.org/rfc/rfc8446#section-3'
  19. filenames = []
  20. aliases = ['tls']
  21. mimetypes = []
  22. version_added = '2.16'
  23. flags = re.MULTILINE | re.DOTALL
  24. tokens = {
  25. 'root': [
  26. (r'\s+', Whitespace),
  27. # comments
  28. (r'/[*].*?[*]/', Comment.Multiline),
  29. # Keywords
  30. (words(('struct', 'enum', 'select', 'case'), suffix=r'\b'),
  31. Keyword),
  32. (words(('uint8', 'uint16', 'uint24', 'uint32', 'uint64', 'opaque'),
  33. suffix=r'\b'), Keyword.Type),
  34. # numeric literals
  35. (r'0x[0-9a-fA-F]+', Number.Hex),
  36. (r'[0-9]+', Number.Integer),
  37. # string literal
  38. (r'"(\\.|[^"\\])*"', String),
  39. # tokens
  40. (r'[.]{2}', Operator),
  41. (r'[+\-*/&^]', Operator),
  42. (r'[|<>=!()\[\]{}.,;:\?]', Punctuation),
  43. # identifiers
  44. (r'[^\W\d]\w*', Name.Other),
  45. ]
  46. }