Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd60040b

Browse files
authored
bpo-40517: Implement syntax highlighting support for ASDL (#19928)
1 parentb9c46a2 commitd60040b

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

‎Doc/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# ---------------------
1515

1616
extensions= ['sphinx.ext.coverage','sphinx.ext.doctest',
17-
'pyspecific','c_annotations','escape4chm']
17+
'pyspecific','c_annotations','escape4chm',
18+
'asdl_highlight']
1819

1920

2021
doctest_global_setup='''

‎Doc/library/ast.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Abstract Grammar
3535
The abstract grammar is currently defined as follows:
3636

3737
..literalinclude::../../Parser/Python.asdl
38-
:language:none
38+
:language:asdl
3939

4040

4141
Node classes
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
importos
2+
importsys
3+
sys.path.append(os.path.abspath("../Parser/"))
4+
5+
frompygments.lexerimportRegexLexer,bygroups,include,words
6+
frompygments.tokenimport (Comment,Generic,Keyword,Name,Operator,
7+
Punctuation,Text)
8+
9+
fromasdlimportbuiltin_types
10+
fromsphinx.highlightingimportlexers
11+
12+
classASDLLexer(RegexLexer):
13+
name="ASDL"
14+
aliases= ["asdl"]
15+
filenames= ["*.asdl"]
16+
_name=r"([^\W\d]\w*)"
17+
_text_ws=r"(\s*)"
18+
19+
tokens= {
20+
"ws": [
21+
(r"\n",Text),
22+
(r"\s+",Text),
23+
(r"--.*?$",Comment.Singleline),
24+
],
25+
"root": [
26+
include("ws"),
27+
(
28+
r"(module)"+_text_ws+_name,
29+
bygroups(Keyword,Text,Name.Class),
30+
),
31+
(
32+
r"(\w+)(\*\s|\?\s|\s)(\w+)",
33+
bygroups(Name.Variable,Generic.Strong,Name.Tag),
34+
),
35+
(words(builtin_types),Keyword.Type),
36+
(r"attributes",Name.Builtin),
37+
(
38+
_name+_text_ws+"(=)",
39+
bygroups(Name.Variable,Text,Operator),
40+
),
41+
(_name,Name.Function),
42+
(r"\|",Operator),
43+
(r"{|}|\(|\)",Punctuation),
44+
(r".",Text),
45+
],
46+
}
47+
48+
49+
defsetup(app):
50+
lexers["asdl"]=ASDLLexer()
51+
return {'version':'1.0','parallel_read_safe':True}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp