Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/ada.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

15 statements  

1""" 

2 pygments.lexers.ada 

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

4 

5 Lexers for Ada family languages. 

6 

7 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, bygroups, words, using, this, \ 

14 default 

15from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

16 Number, Punctuation 

17from pygments.lexers._ada_builtins import KEYWORD_LIST, BUILTIN_LIST 

18 

19__all__ = ['AdaLexer'] 

20 

21 

22class AdaLexer(RegexLexer): 

23 """ 

24 For Ada source code. 

25 """ 

26 

27 name = 'Ada' 

28 aliases = ['ada', 'ada95', 'ada2005'] 

29 filenames = ['*.adb', '*.ads', '*.ada'] 

30 mimetypes = ['text/x-ada'] 

31 url = 'https://www.adaic.org' 

32 version_added = '1.3' 

33 

34 flags = re.MULTILINE | re.IGNORECASE 

35 

36 tokens = { 

37 'root': [ 

38 (r'[^\S\n]+', Text), 

39 (r'--.*?\n', Comment.Single), 

40 (r'function|procedure|entry', Keyword.Declaration, 'subprogram'), 

41 (r'(subtype|type)(\s+)(\w+)', 

42 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), 

43 (r'task|protected', Keyword.Declaration), 

44 (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)), 

45 (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'), 

46 (r'(pragma)(\s+)(\w+)', bygroups(Keyword.Reserved, Text, 

47 Comment.Preproc)), 

48 (r'(true|false|null)\b', Keyword.Constant), 

49 # builtin types 

50 (words(BUILTIN_LIST, suffix=r'\b'), Keyword.Type), 

51 (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word), 

52 (r'generic|private', Keyword.Declaration), 

53 (r'package', Keyword.Declaration, 'package'), 

54 (r'array\b', Keyword.Reserved, 'array_def'), 

55 (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 

56 (r'(\w+)(\s*)(:)(\s*)(constant)', 

57 bygroups(Name.Constant, Text, Punctuation, Text, 

58 Keyword.Reserved)), 

59 (r'<<\w+>>', Name.Label), 

60 (r'(\w+)(\s*)(:)(\s*)(declare|begin|loop|for|while)', 

61 bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)), 

62 # keywords 

63 (words(KEYWORD_LIST, prefix=r'\b', suffix=r'\b'), 

64 Keyword.Reserved), 

65 (r'"[^"]*"', String), 

66 include('attribute'), 

67 include('numbers'), 

68 (r"'[^']'", String.Character), 

69 (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), 

70 (r"(<>|=>|:=|@|[\[\]]|[()|:;,.'])", Punctuation), 

71 (r'[*<>+=/&-]', Operator), 

72 (r'\n+', Text), 

73 ], 

74 'numbers': [ 

75 (r'[0-9_]+#[0-9a-f_\.]+#', Number.Hex), 

76 (r'[0-9_]+\.[0-9_]*', Number.Float), 

77 (r'[0-9_]+', Number.Integer), 

78 ], 

79 'attribute': [ 

80 (r"(')(\w+)", bygroups(Punctuation, Name.Attribute)), 

81 ], 

82 'subprogram': [ 

83 (r'\(', Punctuation, ('#pop', 'formal_part')), 

84 (r';', Punctuation, '#pop'), 

85 (r'is\b', Keyword.Reserved, '#pop'), 

86 (r'"[^"]+"|\w+', Name.Function), 

87 include('root'), 

88 ], 

89 'end': [ 

90 ('(if|case|record|loop|select)', Keyword.Reserved), 

91 (r'"[^"]+"|[\w.]+', Name.Function), 

92 (r'\s+', Text), 

93 (';', Punctuation, '#pop'), 

94 ], 

95 'type_def': [ 

96 (r';', Punctuation, '#pop'), 

97 (r'\(', Punctuation, 'formal_part'), 

98 (r'\[', Punctuation, 'formal_part'), 

99 (r'with|and|use', Keyword.Reserved), 

100 (r'array\b', Keyword.Reserved, ('#pop', 'array_def')), 

101 (r'record\b', Keyword.Reserved, ('record_def')), 

102 (r'(null record)(;)', bygroups(Keyword.Reserved, Punctuation), '#pop'), 

103 include('root'), 

104 ], 

105 'array_def': [ 

106 (r';', Punctuation, '#pop'), 

107 (r'(\w+)(\s+)(range)', bygroups(Keyword.Type, Text, Keyword.Reserved)), 

108 include('root'), 

109 ], 

110 'record_def': [ 

111 (r'end record', Keyword.Reserved, '#pop'), 

112 include('root'), 

113 ], 

114 'import': [ 

115 # TODO: use Name.Namespace if appropriate. This needs 

116 # work to disinguish imports from aspects. 

117 (r'[\w.]+', Name, '#pop'), 

118 default('#pop'), 

119 ], 

120 'formal_part': [ 

121 (r'\)', Punctuation, '#pop'), 

122 (r'\]', Punctuation, '#pop'), 

123 (r'\w+', Name.Variable), 

124 (r',|:[^=]', Punctuation), 

125 (r'(in|not|null|out|access)\b', Keyword.Reserved), 

126 include('root'), 

127 ], 

128 'package': [ 

129 ('body', Keyword.Declaration), 

130 (r'is\s+new|renames', Keyword.Reserved), 

131 ('is', Keyword.Reserved, '#pop'), 

132 (';', Punctuation, '#pop'), 

133 (r'\(', Punctuation, 'package_instantiation'), 

134 (r'([\w.]+)', Name.Class), 

135 include('root'), 

136 ], 

137 'package_instantiation': [ 

138 (r'("[^"]+"|\w+)(\s+)(=>)', bygroups(Name.Variable, Text, Punctuation)), 

139 (r'[\w.\'"]', Text), 

140 (r'\)', Punctuation, '#pop'), 

141 include('root'), 

142 ], 

143 }