Debian Codegraph @

Doc/tools/extensions/lexers/asdl_lexer.py

raw
1 from pygments.lexer import RegexLexer, bygroups, include
2 from pygments.token import Comment, Keyword, Name, Operator, Punctuation, Text
3
4
5 class ASDLLexer(RegexLexer):
6 name = "ASDL"
7 aliases = ["asdl"]
8 filenames = ["*.asdl"]
9 _name = r"([^\W\d]\w*)"
10 _text_ws = r"(\s*)"
11
12 tokens = {
13 "ws": [
14 (r"\n", Text),
15 (r"\s+", Text),
16 (r"--.*?$", Comment.Singleline),
17 ],
18 "root": [
19 include("ws"),
20 (
21 r"(module)" + _text_ws + _name,
22 bygroups(Keyword, Text, Name.Tag),
23 ),
24 (
25 r"(\w+)([\?\*]*\s)(\w+)",
26 bygroups(Name.Builtin.Pseudo, Operator, Name),
27 ),
28 # Keep in line with ``builtin_types`` from Parser/asdl.py.
29 # ASDL's 4 builtin types are
30 # constant, identifier, int, string
31 ("constant|identifier|int|string", Name.Builtin),
32 (r"attributes", Name.Builtin),
33 (
34 _name + _text_ws + "(=)",
35 bygroups(Name, Text, Operator),
36 ),
37 (_name, Name.Class),
38 (r"\|", Operator),
39 (r"{|}|\(|\)", Punctuation),
40 (r".", Text),
41 ],
42 }