|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.capnproto |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for the Cap'n Proto schema language. |
|
7 |
|
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, default |
|
15 from pygments.token import Text, Comment, Keyword, Name, Literal |
|
16 |
|
17 __all__ = ['CapnProtoLexer'] |
|
18 |
|
19 |
|
20 class CapnProtoLexer(RegexLexer): |
|
21 """ |
|
22 For `Cap'n Proto <https://capnproto.org>`_ source. |
|
23 |
|
24 .. versionadded:: 2.2 |
|
25 """ |
|
26 name = 'Cap\'n Proto' |
|
27 filenames = ['*.capnp'] |
|
28 aliases = ['capnp'] |
|
29 |
|
30 flags = re.MULTILINE | re.UNICODE |
|
31 |
|
32 tokens = { |
|
33 'root': [ |
|
34 (r'#.*?$', Comment.Single), |
|
35 (r'@[0-9a-zA-Z]*', Name.Decorator), |
|
36 (r'=', Literal, 'expression'), |
|
37 (r':', Name.Class, 'type'), |
|
38 (r'\$', Name.Attribute, 'annotation'), |
|
39 (r'(struct|enum|interface|union|import|using|const|annotation|' |
|
40 r'extends|in|of|on|as|with|from|fixed)\b', |
|
41 Keyword), |
|
42 (r'[\w.]+', Name), |
|
43 (r'[^#@=:$\w]+', Text), |
|
44 ], |
|
45 'type': [ |
|
46 (r'[^][=;,(){}$]+', Name.Class), |
|
47 (r'[\[(]', Name.Class, 'parentype'), |
|
48 default('#pop'), |
|
49 ], |
|
50 'parentype': [ |
|
51 (r'[^][;()]+', Name.Class), |
|
52 (r'[\[(]', Name.Class, '#push'), |
|
53 (r'[])]', Name.Class, '#pop'), |
|
54 default('#pop'), |
|
55 ], |
|
56 'expression': [ |
|
57 (r'[^][;,(){}$]+', Literal), |
|
58 (r'[\[(]', Literal, 'parenexp'), |
|
59 default('#pop'), |
|
60 ], |
|
61 'parenexp': [ |
|
62 (r'[^][;()]+', Literal), |
|
63 (r'[\[(]', Literal, '#push'), |
|
64 (r'[])]', Literal, '#pop'), |
|
65 default('#pop'), |
|
66 ], |
|
67 'annotation': [ |
|
68 (r'[^][;,(){}=:]+', Name.Attribute), |
|
69 (r'[\[(]', Name.Attribute, 'annexp'), |
|
70 default('#pop'), |
|
71 ], |
|
72 'annexp': [ |
|
73 (r'[^][;()]+', Name.Attribute), |
|
74 (r'[\[(]', Name.Attribute, '#push'), |
|
75 (r'[])]', Name.Attribute, '#pop'), |
|
76 default('#pop'), |
|
77 ], |
|
78 } |