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