Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a lexer for the TLS presentation language (#2455)
This is the syntax used to define TLS structures. It is defined (somewhat loosely) here: https://www.rfc-editor.org/rfc/rfc8446#section-3
- Loading branch information
Showing
5 changed files
with
3,163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
pygments.lexers.tls | ||
~~~~~~~~~~~~~~~~~~~ | ||
Lexers for the TLS presentation language. | ||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
import re | ||
|
||
from pygments.lexer import RegexLexer, bygroups, words | ||
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ | ||
Number, Punctuation, Whitespace | ||
|
||
__all__ = ['TlsLexer'] | ||
|
||
|
||
class TlsLexer(RegexLexer): | ||
""" | ||
The TLS presentation language, described in RFC 8446. | ||
.. versionadded:: 2.16 | ||
""" | ||
name = 'TLS Presentation Language' | ||
url = 'https://www.rfc-editor.org/rfc/rfc8446#section-3' | ||
filenames = [] | ||
aliases = ['tls'] | ||
mimetypes = [] | ||
|
||
flags = re.MULTILINE | re.DOTALL | ||
|
||
tokens = { | ||
'root': [ | ||
(r'\s+', Whitespace), | ||
# comments | ||
(r'/[*].*?[*]/', Comment.Multiline), | ||
# Keywords | ||
(words(('struct', 'enum', 'select', 'case'), suffix=r'\b'), | ||
Keyword), | ||
(words(('uint8', 'uint16', 'uint24', 'uint32', 'uint64', 'opaque'), | ||
suffix=r'\b'), Keyword.Type), | ||
# numeric literals | ||
(r'0x[0-9a-fA-F]+', Number.Hex), | ||
(r'[0-9]+', Number.Integer), | ||
# string literal | ||
(r'"(\\.|[^"\\])*"', String), | ||
# tokens | ||
(r'[.]{2}', Operator), | ||
(r'[+\-*/&^]', Operator), | ||
(r'[|<>=!()\[\]{}.,;:\?]', Punctuation), | ||
# identifiers | ||
(r'[^\W\d]\w*', Name.Other), | ||
] | ||
} |
Oops, something went wrong.