Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lexer for the TLS presentation language #2455

Merged
merged 5 commits into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -31,6 +31,7 @@ Other contributors, listed alphabetically, are:
* Michael Bayer -- Myghty lexers
* Thomas Beale -- Archetype lexers
* John Benediktsson -- Factor lexer
* David Benjamin, Google LLC -- TLS lexer
jeanas marked this conversation as resolved.
Show resolved Hide resolved
* Trevor Bergeron -- mIRC formatter
* Vincent Bernat -- LessCSS lexer
* Christopher Bertels -- Fancy lexer
Expand Down
1 change: 1 addition & 0 deletions pygments/lexers/_mapping.py
Expand Up @@ -502,6 +502,7 @@
'ThriftLexer': ('pygments.lexers.dsls', 'Thrift', ('thrift',), ('*.thrift',), ('application/x-thrift',)),
'TiddlyWiki5Lexer': ('pygments.lexers.markup', 'tiddler', ('tid',), ('*.tid',), ('text/vnd.tiddlywiki',)),
'TlbLexer': ('pygments.lexers.tlb', 'Tl-b', ('tlb',), ('*.tlb',), ()),
'TlsLexer': ('pygments.lexers.tls', 'TLS Presentation Language', ('tls',), (), ()),
'TodotxtLexer': ('pygments.lexers.textfmts', 'Todotxt', ('todotxt',), ('todo.txt', '*.todotxt'), ('text/x-todo',)),
'TransactSqlLexer': ('pygments.lexers.sql', 'Transact-SQL', ('tsql', 't-sql'), ('*.sql',), ('text/x-tsql',)),
'TreetopLexer': ('pygments.lexers.parsers', 'Treetop', ('treetop',), ('*.treetop', '*.tt'), ()),
Expand Down
55 changes: 55 additions & 0 deletions pygments/lexers/tls.py
@@ -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),
]
}