summaryrefslogtreecommitdiffstats
path: root/Doc/tools
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhanosmantaskaya@gmail.com>2020-05-07 20:57:26 (GMT)
committerGitHub <noreply@github.com>2020-05-07 20:57:26 (GMT)
commitb7a78ca74ab539943ab11b5c4c9cfab7f5b7ff5a (patch)
tree35877dd4ca920a639376626fc69c438efcf2a48f /Doc/tools
parent4e363761fc02a89d53aba4382dc451293bd6f0ba (diff)
downloadcpython-b7a78ca74ab539943ab11b5c4c9cfab7f5b7ff5a.zip
cpython-b7a78ca74ab539943ab11b5c4c9cfab7f5b7ff5a.tar.gz
cpython-b7a78ca74ab539943ab11b5c4c9cfab7f5b7ff5a.tar.bz2
bpo-40517: Implement syntax highlighting support for ASDL (GH-19967)
Diffstat (limited to 'Doc/tools')
-rw-r--r--Doc/tools/extensions/asdl_highlight.py51
1 files changed, 51 insertions, 0 deletions
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}