Skip to content

Commit

Permalink
Add a lexer for the TLS presentation language (#2455)
Browse files Browse the repository at this point in the history
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
davidben committed Jun 15, 2023
1 parent 29af4a9 commit bcd506d
Show file tree
Hide file tree
Showing 5 changed files with 3,163 additions and 0 deletions.
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
* 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),
]
}

0 comments on commit bcd506d

Please sign in to comment.