1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
"""
pygments.lexers.bare
~~~~~~~~~~~~~~~~~~~~
Lexer for the BARE schema.
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.lexer import RegexLexer, words, bygroups
from pygments.token import Text, Comment, Keyword, Name, Literal, Whitespace
__all__ = ['BareLexer']
class BareLexer(RegexLexer):
"""
For BARE schema source.
.. versionadded:: 2.7
"""
name = 'BARE'
url = 'https://baremessages.org'
filenames = ['*.bare']
aliases = ['bare']
keywords = [
'type',
'enum',
'u8',
'u16',
'u32',
'u64',
'uint',
'i8',
'i16',
'i32',
'i64',
'int',
'f32',
'f64',
'bool',
'void',
'data',
'string',
'optional',
'map',
]
tokens = {
'root': [
(r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)(\{)',
bygroups(Keyword, Whitespace, Name.Class, Whitespace, Text), 'struct'),
(r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)(\()',
bygroups(Keyword, Whitespace, Name.Class, Whitespace, Text), 'union'),
(r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)',
bygroups(Keyword, Whitespace, Name, Whitespace), 'typedef'),
(r'(enum)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\{)',
bygroups(Keyword, Whitespace, Name.Class, Whitespace), 'enum'),
(r'#.*?$', Comment),
(r'\s+', Whitespace),
],
'struct': [
(r'\{', Text, '#push'),
(r'\}', Text, '#pop'),
(r'([a-zA-Z0-9]+)(:)(\s*)',
bygroups(Name.Attribute, Text, Whitespace), 'typedef'),
(r'\s+', Whitespace),
],
'union': [
(r'\)', Text, '#pop'),
(r'(\s*)(\|)(\s*)', bygroups(Whitespace, Text, Whitespace)),
(r'[A-Z][a-zA-Z0-9]+', Name.Class),
(words(keywords), Keyword),
(r'\s+', Whitespace),
],
'typedef': [
(r'\[\]', Text),
(r'#.*?$', Comment, '#pop'),
(r'(\[)(\d+)(\])', bygroups(Text, Literal, Text)),
(r'<|>', Text),
(r'\(', Text, 'union'),
(r'(\[)([a-z][a-z-A-Z0-9]+)(\])', bygroups(Text, Keyword, Text)),
(r'(\[)([A-Z][a-z-A-Z0-9]+)(\])', bygroups(Text, Name.Class, Text)),
(r'([A-Z][a-z-A-Z0-9]+)', Name.Class),
(words(keywords), Keyword),
(r'\n', Text, '#pop'),
(r'\{', Text, 'struct'),
(r'\s+', Whitespace),
(r'\d+', Literal),
],
'enum': [
(r'\{', Text, '#push'),
(r'\}', Text, '#pop'),
(r'([A-Z][A-Z0-9_]*)(\s*=\s*)(\d+)',
bygroups(Name.Attribute, Text, Literal)),
(r'([A-Z][A-Z0-9_]*)', bygroups(Name.Attribute)),
(r'#.*?$', Comment),
(r'\s+', Whitespace),
],
}
|