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

20 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 07:45 +0000

1""" 

2 pygments.lexers.felix 

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

4 

5 Lexer for the Felix language. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, include, bygroups, default, words, \ 

12 combined 

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

14 Number, Punctuation, Whitespace 

15 

16__all__ = ['FelixLexer'] 

17 

18 

19class FelixLexer(RegexLexer): 

20 """ 

21 For Felix source code. 

22 

23 .. versionadded:: 1.2 

24 """ 

25 

26 name = 'Felix' 

27 url = 'http://www.felix-lang.org' 

28 aliases = ['felix', 'flx'] 

29 filenames = ['*.flx', '*.flxh'] 

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

31 

32 preproc = ( 

33 'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef', 

34 ) 

35 

36 keywords = ( 

37 '_', '_deref', 'all', 'as', 

38 'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass', 

39 'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else', 

40 'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except', 

41 'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork', 

42 'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance', 

43 'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace', 

44 'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise', 

45 'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then', 

46 'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto', 

47 'when', 'whilst', 'with', 'yield', 

48 ) 

49 

50 keyword_directives = ( 

51 '_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export', 

52 'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn', 

53 'package', 'private', 'pod', 'property', 'public', 'publish', 

54 'requires', 'todo', 'virtual', 'use', 

55 ) 

56 

57 keyword_declarations = ( 

58 'def', 'let', 'ref', 'val', 'var', 

59 ) 

60 

61 keyword_types = ( 

62 'unit', 'void', 'any', 'bool', 

63 'byte', 'offset', 

64 'address', 'caddress', 'cvaddress', 'vaddress', 

65 'tiny', 'short', 'int', 'long', 'vlong', 

66 'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong', 

67 'int8', 'int16', 'int32', 'int64', 

68 'uint8', 'uint16', 'uint32', 'uint64', 

69 'float', 'double', 'ldouble', 

70 'complex', 'dcomplex', 'lcomplex', 

71 'imaginary', 'dimaginary', 'limaginary', 

72 'char', 'wchar', 'uchar', 

73 'charp', 'charcp', 'ucharp', 'ucharcp', 

74 'string', 'wstring', 'ustring', 

75 'cont', 

76 'array', 'varray', 'list', 

77 'lvalue', 'opt', 'slice', 

78 ) 

79 

80 keyword_constants = ( 

81 'false', 'true', 

82 ) 

83 

84 operator_words = ( 

85 'and', 'not', 'in', 'is', 'isin', 'or', 'xor', 

86 ) 

87 

88 name_builtins = ( 

89 '_svc', 'while', 

90 ) 

91 

92 name_pseudo = ( 

93 'root', 'self', 'this', 

94 ) 

95 

96 decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?' 

97 

98 tokens = { 

99 'root': [ 

100 include('whitespace'), 

101 

102 # Keywords 

103 (words(('axiom', 'ctor', 'fun', 'gen', 'proc', 'reduce', 

104 'union'), suffix=r'\b'), 

105 Keyword, 'funcname'), 

106 (words(('class', 'cclass', 'cstruct', 'obj', 'struct'), suffix=r'\b'), 

107 Keyword, 'classname'), 

108 (r'(instance|module|typeclass)\b', Keyword, 'modulename'), 

109 

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

111 (words(keyword_directives, suffix=r'\b'), Name.Decorator), 

112 (words(keyword_declarations, suffix=r'\b'), Keyword.Declaration), 

113 (words(keyword_types, suffix=r'\b'), Keyword.Type), 

114 (words(keyword_constants, suffix=r'\b'), Keyword.Constant), 

115 

116 # Operators 

117 include('operators'), 

118 

119 # Float Literal 

120 # -- Hex Float 

121 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)' 

122 r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float), 

123 # -- DecimalFloat 

124 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|' 

125 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float), 

126 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?', 

127 Number.Float), 

128 

129 # IntegerLiteral 

130 # -- Binary 

131 (r'0[Bb][01_]+%s' % decimal_suffixes, Number.Bin), 

132 # -- Octal 

133 (r'0[0-7_]+%s' % decimal_suffixes, Number.Oct), 

134 # -- Hexadecimal 

135 (r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex), 

136 # -- Decimal 

137 (r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer), 

138 

139 # Strings 

140 ('([rR][cC]?|[cC][rR])"""', String, 'tdqs'), 

141 ("([rR][cC]?|[cC][rR])'''", String, 'tsqs'), 

142 ('([rR][cC]?|[cC][rR])"', String, 'dqs'), 

143 ("([rR][cC]?|[cC][rR])'", String, 'sqs'), 

144 ('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')), 

145 ("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')), 

146 ('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')), 

147 ("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')), 

148 

149 # Punctuation 

150 (r'[\[\]{}:(),;?]', Punctuation), 

151 

152 # Labels 

153 (r'[a-zA-Z_]\w*:>', Name.Label), 

154 

155 # Identifiers 

156 (r'(%s)\b' % '|'.join(name_builtins), Name.Builtin), 

157 (r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo), 

158 (r'[a-zA-Z_]\w*', Name), 

159 ], 

160 'whitespace': [ 

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

162 

163 include('comment'), 

164 

165 # Preprocessor 

166 (r'(#)(\s*)(if)(\s+)(0)', 

167 bygroups(Comment.Preproc, Whitespace, Comment.Preproc, 

168 Whitespace, Comment.Preproc), 'if0'), 

169 (r'#', Comment.Preproc, 'macro'), 

170 ], 

171 'operators': [ 

172 (r'(%s)\b' % '|'.join(operator_words), Operator.Word), 

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

174 ], 

175 'comment': [ 

176 (r'//(.*?)$', Comment.Single), 

177 (r'/[*]', Comment.Multiline, 'comment2'), 

178 ], 

179 'comment2': [ 

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

181 (r'/[*]', Comment.Multiline, '#push'), 

182 (r'[*]/', Comment.Multiline, '#pop'), 

183 (r'[/*]', Comment.Multiline), 

184 ], 

185 'if0': [ 

186 (r'^(\s*)(#if.*?(?<!\\))(\n)', 

187 bygroups(Whitespace, Comment, Whitespace), '#push'), 

188 (r'^(\s*)(#endif.*?(?<!\\))(\n)', 

189 bygroups(Whitespace, Comment, Whitespace), '#pop'), 

190 (r'(.*?)(\n)', bygroups(Comment, Whitespace)), 

191 ], 

192 'macro': [ 

193 include('comment'), 

194 (r'(import|include)(\s+)(<[^>]*?>)', 

195 bygroups(Comment.Preproc, Whitespace, String), '#pop'), 

196 (r'(import|include)(\s+)("[^"]*?")', 

197 bygroups(Comment.Preproc, Whitespace, String), '#pop'), 

198 (r"(import|include)(\s+)('[^']*?')", 

199 bygroups(Comment.Preproc, Whitespace, String), '#pop'), 

200 (r'[^/\n]+', Comment.Preproc), 

201 # (r'/[*](.|\n)*?[*]/', Comment), 

202 # (r'//.*?\n', Comment, '#pop'), 

203 (r'/', Comment.Preproc), 

204 (r'(?<=\\)\n', Comment.Preproc), 

205 (r'\n', Whitespace, '#pop'), 

206 ], 

207 'funcname': [ 

208 include('whitespace'), 

209 (r'[a-zA-Z_]\w*', Name.Function, '#pop'), 

210 # anonymous functions 

211 (r'(?=\()', Text, '#pop'), 

212 ], 

213 'classname': [ 

214 include('whitespace'), 

215 (r'[a-zA-Z_]\w*', Name.Class, '#pop'), 

216 # anonymous classes 

217 (r'(?=\{)', Text, '#pop'), 

218 ], 

219 'modulename': [ 

220 include('whitespace'), 

221 (r'\[', Punctuation, ('modulename2', 'tvarlist')), 

222 default('modulename2'), 

223 ], 

224 'modulename2': [ 

225 include('whitespace'), 

226 (r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'), 

227 ], 

228 'tvarlist': [ 

229 include('whitespace'), 

230 include('operators'), 

231 (r'\[', Punctuation, '#push'), 

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

233 (r',', Punctuation), 

234 (r'(with|where)\b', Keyword), 

235 (r'[a-zA-Z_]\w*', Name), 

236 ], 

237 'stringescape': [ 

238 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|' 

239 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) 

240 ], 

241 'strings': [ 

242 (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' 

243 '[hlL]?[E-GXc-giorsux%]', String.Interpol), 

244 (r'[^\\\'"%\n]+', String), 

245 # quotes, percents and backslashes must be parsed one at a time 

246 (r'[\'"\\]', String), 

247 # unhandled string formatting sign 

248 (r'%', String) 

249 # newlines are an error (use "nl" state) 

250 ], 

251 'nl': [ 

252 (r'\n', String) 

253 ], 

254 'dqs': [ 

255 (r'"', String, '#pop'), 

256 # included here again for raw strings 

257 (r'\\\\|\\"|\\\n', String.Escape), 

258 include('strings') 

259 ], 

260 'sqs': [ 

261 (r"'", String, '#pop'), 

262 # included here again for raw strings 

263 (r"\\\\|\\'|\\\n", String.Escape), 

264 include('strings') 

265 ], 

266 'tdqs': [ 

267 (r'"""', String, '#pop'), 

268 include('strings'), 

269 include('nl') 

270 ], 

271 'tsqs': [ 

272 (r"'''", String, '#pop'), 

273 include('strings'), 

274 include('nl') 

275 ], 

276 }