Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/bare.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1""" 

2 pygments.lexers.bare 

3 ~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for the BARE schema. 

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, words, bygroups 

12from pygments.token import Text, Comment, Keyword, Name, Literal, Whitespace 

13 

14__all__ = ['BareLexer'] 

15 

16 

17class BareLexer(RegexLexer): 

18 """ 

19 For BARE schema source. 

20 """ 

21 name = 'BARE' 

22 url = 'https://baremessages.org' 

23 filenames = ['*.bare'] 

24 aliases = ['bare'] 

25 version_added = '2.7' 

26 

27 keywords = [ 

28 'type', 

29 'enum', 

30 'u8', 

31 'u16', 

32 'u32', 

33 'u64', 

34 'uint', 

35 'i8', 

36 'i16', 

37 'i32', 

38 'i64', 

39 'int', 

40 'f32', 

41 'f64', 

42 'bool', 

43 'void', 

44 'data', 

45 'string', 

46 'optional', 

47 'map', 

48 ] 

49 

50 tokens = { 

51 'root': [ 

52 (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)(\{)', 

53 bygroups(Keyword, Whitespace, Name.Class, Whitespace, Text), 'struct'), 

54 (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)(\()', 

55 bygroups(Keyword, Whitespace, Name.Class, Whitespace, Text), 'union'), 

56 (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)', 

57 bygroups(Keyword, Whitespace, Name, Whitespace), 'typedef'), 

58 (r'(enum)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\{)', 

59 bygroups(Keyword, Whitespace, Name.Class, Whitespace), 'enum'), 

60 (r'#.*?$', Comment), 

61 (r'\s+', Whitespace), 

62 ], 

63 'struct': [ 

64 (r'\{', Text, '#push'), 

65 (r'\}', Text, '#pop'), 

66 (r'([a-zA-Z0-9]+)(:)(\s*)', 

67 bygroups(Name.Attribute, Text, Whitespace), 'typedef'), 

68 (r'\s+', Whitespace), 

69 ], 

70 'union': [ 

71 (r'\)', Text, '#pop'), 

72 (r'(\s*)(\|)(\s*)', bygroups(Whitespace, Text, Whitespace)), 

73 (r'[A-Z][a-zA-Z0-9]+', Name.Class), 

74 (words(keywords), Keyword), 

75 (r'\s+', Whitespace), 

76 ], 

77 'typedef': [ 

78 (r'\[\]', Text), 

79 (r'#.*?$', Comment, '#pop'), 

80 (r'(\[)(\d+)(\])', bygroups(Text, Literal, Text)), 

81 (r'<|>', Text), 

82 (r'\(', Text, 'union'), 

83 (r'(\[)([a-z][a-z-A-Z0-9]+)(\])', bygroups(Text, Keyword, Text)), 

84 (r'(\[)([A-Z][a-z-A-Z0-9]+)(\])', bygroups(Text, Name.Class, Text)), 

85 (r'([A-Z][a-z-A-Z0-9]+)', Name.Class), 

86 (words(keywords), Keyword), 

87 (r'\n', Text, '#pop'), 

88 (r'\{', Text, 'struct'), 

89 (r'\s+', Whitespace), 

90 (r'\d+', Literal), 

91 ], 

92 'enum': [ 

93 (r'\{', Text, '#push'), 

94 (r'\}', Text, '#pop'), 

95 (r'([A-Z][A-Z0-9_]*)(\s*=\s*)(\d+)', 

96 bygroups(Name.Attribute, Text, Literal)), 

97 (r'([A-Z][A-Z0-9_]*)', bygroups(Name.Attribute)), 

98 (r'#.*?$', Comment), 

99 (r'\s+', Whitespace), 

100 ], 

101 }