8000 [3.13] GH-121970: Combine custom Pygments lexers into a package (GH-121976) by miss-islington · Pull Request #122021 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] GH-121970: Combine custom Pygments lexers into a package (GH-121976) #122021

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
GH-121970: Combine custom Pygments lexers into a package (GH-121976)
(cherry picked from commit 7431c37)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
  • Loading branch information
2 people authored and miss-islington committed Jul 19, 2024
commit 29e173c29bf3f670e9b03b3d460a109a59880c38
3 changes: 1 addition & 2 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
# ---------------------

extensions = [
'asdl_highlight',
'c_annotations',
'escape4chm',
'glossary_search',
'peg_highlight',
'lexers',
'pyspecific',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
Expand Down
15 changes: 15 additions & 0 deletions Doc/tools/extensions/lexers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .asdl_lexer import ASDLLexer
from .peg_lexer import PEGLexer


def setup(app):
# Used for highlighting Parser/Python.asdl in library/ast.rst
app.add_lexer("asdl", ASDLLexer)
# Used for highlighting Grammar/python.gram in reference/grammar.rst
app.add_lexer("peg", PEGLexer)

return {
"version": "1.0",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
8000
Original file line number Diff line numberDiff line change
@@ -1,15 +1,6 @@
import sys
from pathlib import Path
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import Comment, Keyword, Name, Operator, Punctuation, Text

CPYTHON_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(CPYTHON_ROOT / "Parser"))

from pygments.lexer import RegexLexer, bygroups, include, words
from pygments.token import (Comment, Keyword, Name, Operator,
Punctuation, Text)

from asdl import builtin_types
from sphinx.highlighting import lexers

class ASDLLexer(RegexLexer):
name = "ASDL"
Expand All @@ -34,7 +25,10 @@ class ASDLLexer(RegexLexer):
r"(\w+)(\*\s|\?\s|\s)(\w+)",
bygroups(Name.Builtin.Pseudo, Operator, Name),
),
(words(builtin_types), Name.Builtin),
# 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 + "(=)",
Expand All @@ -46,8 +40,3 @@ class ASDLLexer(RegexLexer):
(r".", Text),
],
}


def setup(app):
lexers["asdl"] = ASDLLexer()
return {'version': '1.0', 'parallel_read_safe': True}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import Comment, Keyword, Name, Operator, Punctuation, Text

from sphinx.highlighting import lexers


class PEGLexer(RegexLexer):
"""Pygments Lexer for PEG grammar (.gram) files
Expand Down Expand Up @@ -81,8 +79,3 @@ class PEGLexer(RegexLexer):
(r".", Text),
],
}


def setup(app):
lexers["peg"] = PEGLexer()
return {"version": "1.0", "parallel_read_safe": True}
Loading
0