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

18 statements  

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

1""" 

2 pygments.lexers.clean 

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

4 

5 Lexer for the Clean language. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import ExtendedRegexLexer, words, default, include, bygroups 

12from pygments.token import Comment, Error, Keyword, Literal, Name, Number, \ 

13 Operator, Punctuation, String, Whitespace 

14 

15__all__ = ['CleanLexer'] 

16 

17 

18class CleanLexer(ExtendedRegexLexer): 

19 """ 

20 Lexer for the general purpose, state-of-the-art, pure and lazy functional 

21 programming language Clean. 

22 

23 .. versionadded: 2.2 

24 """ 

25 name = 'Clean' 

26 url = 'http://clean.cs.ru.nl/Clean' 

27 aliases = ['clean'] 

28 filenames = ['*.icl', '*.dcl'] 

29 

30 keywords = ( 

31 'case', 'ccall', 'class', 'code', 'code inline', 'derive', 'export', 

32 'foreign', 'generic', 'if', 'in', 'infix', 'infixl', 'infixr', 

33 'instance', 'let', 'of', 'otherwise', 'special', 'stdcall', 'where', 

34 'with') 

35 

36 modulewords = ('implementation', 'definition', 'system') 

37 

38 lowerId = r'[a-z`][\w`]*' 

39 upperId = r'[A-Z`][\w`]*' 

40 funnyId = r'[~@#$%\^?!+\-*<>\\/|&=:]+' 

41 scoreUpperId = r'_' + upperId 

42 scoreLowerId = r'_' + lowerId 

43 moduleId = r'[a-zA-Z_][a-zA-Z0-9_.`]+' 

44 classId = '|'.join([lowerId, upperId, funnyId]) 

45 

46 tokens = { 

47 'root': [ 

48 include('comments'), 

49 include('keywords'), 

50 include('module'), 

51 include('import'), 

52 include('whitespace'), 

53 include('literals'), 

54 include('operators'), 

55 include('delimiters'), 

56 include('names'), 

57 ], 

58 'whitespace': [ 

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

60 ], 

61 'comments': [ 

62 (r'//.*\n', Comment.Single), 

63 (r'/\*', Comment.Multiline, 'comments.in'), 

64 (r'/\*\*', Comment.Special, 'comments.in'), 

65 ], 

66 'comments.in': [ 

67 (r'\*\/', Comment.Multiline, '#pop'), 

68 (r'/\*', Comment.Multiline, '#push'), 

69 (r'[^*/]+', Comment.Multiline), 

70 (r'\*(?!/)', Comment.Multiline), 

71 (r'/', Comment.Multiline), 

72 ], 

73 'keywords': [ 

74 (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword), 

75 ], 

76 'module': [ 

77 (words(modulewords, prefix=r'\b', suffix=r'\b'), Keyword.Namespace), 

78 (r'\bmodule\b', Keyword.Namespace, 'module.name'), 

79 ], 

80 'module.name': [ 

81 include('whitespace'), 

82 (moduleId, Name.Class, '#pop'), 

83 ], 

84 'import': [ 

85 (r'\b(import)\b(\s*)', bygroups(Keyword, Whitespace), 'import.module'), 

86 (r'\b(from)\b(\s*)\b(' + moduleId + r')\b(\s*)\b(import)\b', 

87 bygroups(Keyword, Whitespace, Name.Class, Whitespace, Keyword), 

88 'import.what'), 

89 ], 

90 'import.module': [ 

91 (r'\b(qualified)\b(\s*)', bygroups(Keyword, Whitespace)), 

92 (r'(\s*)\b(as)\b', bygroups(Whitespace, Keyword), ('#pop', 'import.module.as')), 

93 (moduleId, Name.Class), 

94 (r'(\s*)(,)(\s*)', bygroups(Whitespace, Punctuation, Whitespace)), 

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

96 default('#pop'), 

97 ], 

98 'import.module.as': [ 

99 include('whitespace'), 

100 (lowerId, Name.Class, '#pop'), 

101 (upperId, Name.Class, '#pop'), 

102 ], 

103 'import.what': [ 

104 (r'\b(class)\b(\s+)(' + classId + r')', 

105 bygroups(Keyword, Whitespace, Name.Class), 'import.what.class'), 

106 (r'\b(instance)(\s+)(' + classId + r')(\s+)', 

107 bygroups(Keyword, Whitespace, Name.Class, Whitespace), 'import.what.instance'), 

108 (r'(::)(\s*)\b(' + upperId + r')\b', 

109 bygroups(Punctuation, Whitespace, Name.Class), 'import.what.type'), 

110 (r'\b(generic)\b(\s+)\b(' + lowerId + '|' + upperId + r')\b', 

111 bygroups(Keyword, Whitespace, Name)), 

112 include('names'), 

113 (r'(,)(\s+)', bygroups(Punctuation, Whitespace)), 

114 (r'$', Whitespace, '#pop'), 

115 include('whitespace'), 

116 ], 

117 'import.what.class': [ 

118 (r',', Punctuation, '#pop'), 

119 (r'\(', Punctuation, 'import.what.class.members'), 

120 (r'$', Whitespace, '#pop:2'), 

121 include('whitespace'), 

122 ], 

123 'import.what.class.members': [ 

124 (r',', Punctuation), 

125 (r'\.\.', Punctuation), 

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

127 include('names'), 

128 ], 

129 'import.what.instance': [ 

130 (r'[,)]', Punctuation, '#pop'), 

131 (r'\(', Punctuation, 'import.what.instance'), 

132 (r'$', Whitespace, '#pop:2'), 

133 include('whitespace'), 

134 include('names'), 

135 ], 

136 'import.what.type': [ 

137 (r',', Punctuation, '#pop'), 

138 (r'[({]', Punctuation, 'import.what.type.consesandfields'), 

139 (r'$', Whitespace, '#pop:2'), 

140 include('whitespace'), 

141 ], 

142 'import.what.type.consesandfields': [ 

143 (r',', Punctuation), 

144 (r'\.\.', Punctuation), 

145 (r'[)}]', Punctuation, '#pop'), 

146 include('names'), 

147 ], 

148 'literals': [ 

149 (r'\'([^\'\\]|\\(x[\da-fA-F]+|\d+|.))\'', Literal.Char), 

150 (r'[+~-]?0[0-7]+\b', Number.Oct), 

151 (r'[+~-]?\d+\.\d+(E[+-]?\d+)?', Number.Float), 

152 (r'[+~-]?\d+\b', Number.Integer), 

153 (r'[+~-]?0x[\da-fA-F]+\b', Number.Hex), 

154 (r'True|False', Literal), 

155 (r'"', String.Double, 'literals.stringd'), 

156 ], 

157 'literals.stringd': [ 

158 (r'[^\\"\n]+', String.Double), 

159 (r'"', String.Double, '#pop'), 

160 (r'\\.', String.Double), 

161 (r'[$\n]', Error, '#pop'), 

162 ], 

163 'operators': [ 

164 (r'[-~@#$%\^?!+*<>\\/|&=:.]+', Operator), 

165 (r'\b_+\b', Operator), 

166 ], 

167 'delimiters': [ 

168 (r'[,;(){}\[\]]', Punctuation), 

169 (r'(\')([\w`.]+)(\')', 

170 bygroups(Punctuation, Name.Class, Punctuation)), 

171 ], 

172 'names': [ 

173 (lowerId, Name), 

174 (scoreLowerId, Name), 

175 (funnyId, Name.Function), 

176 (upperId, Name.Class), 

177 (scoreUpperId, Name.Class), 

178 ] 

179 }