summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/conf.py3
-rw-r--r--Doc/library/ast.rst2
-rw-r--r--Doc/tools/extensions/asdl_highlight.py51
3 files changed, 54 insertions, 2 deletions
diff --git a/Doc/conf.py b/Doc/conf.py
index 32db343..12d74ea 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -14,7 +14,8 @@ sys.path.append(os.path.abspath('includes'))
# ---------------------
extensions = ['sphinx.ext.coverage', 'sphinx.ext.doctest',
- 'pyspecific', 'c_annotations', 'escape4chm']
+ 'pyspecific', 'c_annotations', 'escape4chm',
+ 'asdl_highlight']
doctest_global_setup = '''
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index fc04114..6c6ad01 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -35,7 +35,7 @@ Abstract Grammar
The abstract grammar is currently defined as follows:
.. literalinclude:: ../../Parser/Python.asdl
- :language: none
+ :language: asdl
Node classes
diff --git a/Doc/tools/extensions/asdl_highlight.py b/Doc/tools/extensions/asdl_highlight.py
new file mode 100644
index 0000000..7d2ef01
--- /dev/null
+++ b/Doc/tools/extensions/asdl_highlight.py
@@ -0,0 +1,51 @@
+import os
+import sys
+sys.path.append(os.path.abspath("../Parser/"))
+
+from pygments.lexer import RegexLexer, bygroups, include, words
+from pygments.token import (Comment, Generic, Keyword, Name, Operator,
+ Punctuation, Text)
+
+from asdl import builtin_types
+from sphinx.highlighting import lexers
+
+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),
+ ),
+ (words(builtin_types), Name.Builtin),
+ (r"attributes", Name.Builtin),
+ (
+ _name + _text_ws + "(=)",
+ bygroups(Name, Text, Operator),
+ ),
+ (_name, Name.Class),
+ (r"\|", Operator),
+ (r"{|}|\(|\)", Punctuation),
+ (r".", Text),
+ ],
+ }
+
+
+def setup(app):
+ lexers["asdl"] = ASDLLexer()
+ return {'version': '1.0', 'parallel_read_safe': True}