mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
GH-121970: Combine custom Pygments lexers into a package (#121976)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
12c1afa9d1
commit
7431c3799e
4 changed files with 22 additions and 26 deletions
42
Doc/tools/extensions/lexers/asdl_lexer.py
Normal file
42
Doc/tools/extensions/lexers/asdl_lexer.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from pygments.lexer import RegexLexer, bygroups, include
|
||||
from pygments.token import Comment, Keyword, Name, Operator, Punctuation, Text
|
||||
|
||||
|
||||
class ASDLLexer(RegexLexer):
|
||||
name = "ASDL"
|
||||
aliases = ["asdl"]
|
||||
filenames = ["*.asdl"]
|
||||
_name = r"([^\W\d]\w*)"
|
||||
_text_ws = r"(\s*)"
|
||||
|
||||
tokens = {
|
||||
"ws": [
|
||||
(r"\n", Text),
|
||||
(r"\s+", Text),
|
||||
(r"--.*?$", Comment.Singleline),
|
||||
],
|
||||
"root": [
|
||||
include("ws"),
|
||||
(
|
||||
r"(module)" + _text_ws + _name,
|
||||
bygroups(Keyword, Text, Name.Tag),
|
||||
),
|
||||
(
|
||||
r"(\w+)(\*\s|\?\s|\s)(\w+)",
|
||||
bygroups(Name.Builtin.Pseudo, Operator, Name),
|
||||
),
|
||||
# Keep in line with ``builtin_types`` from Parser/asdl.py.
|
||||
# ASDL's 4 builtin types are
|
||||
# constant, identifier, int, string
|
||||
('constant|identifier|int|string', Name.Builtin),
|
||||
(r"attributes", Name.Builtin),
|
||||
(
|
||||
_name + _text_ws + "(=)",
|
||||
bygroups(Name, Text, Operator),
|
||||
),
|
||||
(_name, Name.Class),
|
||||
(r"\|", Operator),
|
||||
(r"{|}|\(|\)", Punctuation),
|
||||
(r".", Text),
|
||||
],
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue