|
| 1 | +import os |
| 2 | +import sys |
| 3 | +sys.path.append(os.path.abspath("../Parser/")) |
| 4 | + |
| 5 | +from pygments.lexer import RegexLexer, bygroups, include, words |
| 6 | +from pygments.token import (Comment, Generic, Keyword, Name, Operator, |
| 7 | + Punctuation, Text) |
| 8 | + |
| 9 | +from asdl import builtin_types |
| 10 | +from sphinx.highlighting import lexers |
| 11 | + |
| 12 | +class ASDLLexer(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 | +def setup(app): |
| 50 | + lexers["asdl"] = ASDLLexer() |
| 51 | + return {'version': '1.0', 'parallel_read_safe': True} |
0 commit comments