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

12 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.ada 

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

4 

5 Lexers for Ada family languages. 

6 

7 :copyright: Copyright 2006-2023 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 .. versionadded:: 1.3 

27 """ 

28 

29 name = 'Ada' 

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

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

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

33 

34 flags = re.MULTILINE | re.IGNORECASE 

35 

36 tokens = { 

37 'root': [ 

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

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

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

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

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

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

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

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

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

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

48 Comment.Preproc)), 

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

50 # builtin types 

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

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

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

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

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

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

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

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

59 Keyword.Reserved)), 

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

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

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

63 # keywords 

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

65 Keyword.Reserved), 

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

67 include('attribute'), 

68 include('numbers'), 

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

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

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

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

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

74 ], 

75 'numbers': [ 

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

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

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

79 ], 

80 'attribute': [ 

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

82 ], 

83 'subprogram': [ 

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

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

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

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

88 include('root'), 

89 ], 

90 'end': [ 

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

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

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

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

95 ], 

96 'type_def': [ 

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

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

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

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

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

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

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

104 include('root'), 

105 ], 

106 'array_def': [ 

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

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

109 include('root'), 

110 ], 

111 'record_def': [ 

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

113 include('root'), 

114 ], 

115 'import': [ 

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

117 # work to disinguish imports from aspects. 

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

119 default('#pop'), 

120 ], 

121 'formal_part': [ 

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

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

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

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

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

127 include('root'), 

128 ], 

129 'package': [ 

130 ('body', Keyword.Declaration), 

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

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

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

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

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

136 include('root'), 

137 ], 

138 'package_instantiation': [ 

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

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

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

142 include('root'), 

143 ], 

144 }