Skip to content
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
9 changes: 7 additions & 2 deletions pep_sphinx_extensions/LICENCE.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
The files in this directory are placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.
Unless otherwise stated, the files in this directory are placed in the
public domain or under the CC0-1.0-Universal license, whichever is more
permissive.

Some files are based on work from external projects. Check the individual
file headers for specific licensing details. In particular:
- lexers/asdl_lexer.py
53 changes: 53 additions & 0 deletions pep_sphinx_extensions/lexers/asdl_lexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# The code in this file is based on:
# https://github.com/python/cpython/blob/v3.15.2/Doc/tools/extensions/lexers/asdl_lexer.py

# Licensed under the Python Software Foundation License v2
# For the full license text, see:
# https://github.com/python/cpython/blob/v3.15.2/LICENSE

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)(\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),
],
}


def register():
return [ASDLLexer]
2 changes: 1 addition & 1 deletion peps/pep-0823.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ do not support assignments themselves and thus the context will always be
expression nodes. It is set to ``1`` if an expression is the topmost
node in a group, ``0`` otherwise.

::
.. code-block:: ASDL

expr = ...
| Attribute(expr value, identifier attr, expr_context ctx)
Expand Down
4 changes: 2 additions & 2 deletions peps/pep-0824.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ AST changes
A new ``Coalesce`` operator is added to ``boolop`` for use in ``BoolOp``
nodes.

::
.. code-block:: ASDL

expr = BoolOp(boolop op, expr* values)
| ...
Expand Down Expand Up @@ -284,7 +284,7 @@ A new ``BoolAssign`` AST node is added. Similar to ``AugAssign``,
it stores a ``target`` and ``value`` expression as well as
the boolean operator ``Coalesce``.

::
.. code-block:: ASDL

stmt = ...
| AugAssign(expr target, operator op, expr value)
Expand Down
Loading