Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/capnproto.py: 100%
9 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.capnproto
3 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 Lexers for the Cap'n Proto schema language.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, default
12from pygments.token import Text, Comment, Keyword, Name, Literal, Whitespace
14__all__ = ['CapnProtoLexer']
17class CapnProtoLexer(RegexLexer):
18 """
19 For Cap'n Proto source.
21 .. versionadded:: 2.2
22 """
23 name = 'Cap\'n Proto'
24 url = 'https://capnproto.org'
25 filenames = ['*.capnp']
26 aliases = ['capnp']
28 tokens = {
29 'root': [
30 (r'#.*?$', Comment.Single),
31 (r'@[0-9a-zA-Z]*', Name.Decorator),
32 (r'=', Literal, 'expression'),
33 (r':', Name.Class, 'type'),
34 (r'\$', Name.Attribute, 'annotation'),
35 (r'(struct|enum|interface|union|import|using|const|annotation|'
36 r'extends|in|of|on|as|with|from|fixed)\b',
37 Keyword),
38 (r'[\w.]+', Name),
39 (r'[^#@=:$\w\s]+', Text),
40 (r'\s+', Whitespace),
41 ],
42 'type': [
43 (r'[^][=;,(){}$]+', Name.Class),
44 (r'[\[(]', Name.Class, 'parentype'),
45 default('#pop'),
46 ],
47 'parentype': [
48 (r'[^][;()]+', Name.Class),
49 (r'[\[(]', Name.Class, '#push'),
50 (r'[])]', Name.Class, '#pop'),
51 default('#pop'),
52 ],
53 'expression': [
54 (r'[^][;,(){}$]+', Literal),
55 (r'[\[(]', Literal, 'parenexp'),
56 default('#pop'),
57 ],
58 'parenexp': [
59 (r'[^][;()]+', Literal),
60 (r'[\[(]', Literal, '#push'),
61 (r'[])]', Literal, '#pop'),
62 default('#pop'),
63 ],
64 'annotation': [
65 (r'[^][;,(){}=:]+', Name.Attribute),
66 (r'[\[(]', Name.Attribute, 'annexp'),
67 default('#pop'),
68 ],
69 'annexp': [
70 (r'[^][;()]+', Name.Attribute),
71 (r'[\[(]', Name.Attribute, '#push'),
72 (r'[])]', Name.Attribute, '#pop'),
73 default('#pop'),
74 ],
75 }