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