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

9 statements  

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

1""" 

2 pygments.lexers.kuin 

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

4 

5 Lexers for the Kuin 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 RegexLexer, include, using, this, bygroups, words 

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

13 Number, Punctuation, Whitespace 

14 

15__all__ = ['KuinLexer'] 

16 

17 

18class KuinLexer(RegexLexer): 

19 """ 

20 For Kuin source code. 

21 

22 .. versionadded:: 2.9 

23 """ 

24 name = 'Kuin' 

25 url = 'https://github.com/kuina/Kuin' 

26 aliases = ['kuin'] 

27 filenames = ['*.kn'] 

28 

29 tokens = { 

30 'root': [ 

31 include('statement'), 

32 ], 

33 'statement': [ 

34 # Whitespace / Comment 

35 include('whitespace'), 

36 

37 # Block-statement 

38 (r'(\+?)([ \t]*)(\*?)([ \t]*)(\bfunc)([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*)', 

39 bygroups(Keyword,Whitespace, Keyword, Whitespace, Keyword, 

40 using(this), Name.Function), 'func_'), 

41 (r'\b(class)([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*)', 

42 bygroups(Keyword, using(this), Name.Class), 'class_'), 

43 (r'\b(enum)([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*)', 

44 bygroups(Keyword, using(this), Name.Constant), 'enum_'), 

45 (r'\b(block)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

46 bygroups(Keyword, using(this), Name.Other), 'block_'), 

47 (r'\b(ifdef)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

48 bygroups(Keyword, using(this), Name.Other), 'ifdef_'), 

49 (r'\b(if)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

50 bygroups(Keyword, using(this), Name.Other), 'if_'), 

51 (r'\b(switch)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

52 bygroups(Keyword, using(this), Name.Other), 'switch_'), 

53 (r'\b(while)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

54 bygroups(Keyword, using(this), Name.Other), 'while_'), 

55 (r'\b(for)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

56 bygroups(Keyword, using(this), Name.Other), 'for_'), 

57 (r'\b(foreach)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

58 bygroups(Keyword, using(this), Name.Other), 'foreach_'), 

59 (r'\b(try)\b(?:([ \t]+(?:\n\s*\|)*[ \t]*)([a-zA-Z_][0-9a-zA-Z_]*))?', 

60 bygroups(Keyword, using(this), Name.Other), 'try_'), 

61 

62 # Line-statement 

63 (r'\b(do)\b', Keyword, 'do'), 

64 (r'(\+?[ \t]*\bvar)\b', Keyword, 'var'), 

65 (r'\b(const)\b', Keyword, 'const'), 

66 (r'\b(ret)\b', Keyword, 'ret'), 

67 (r'\b(throw)\b', Keyword, 'throw'), 

68 (r'\b(alias)\b', Keyword, 'alias'), 

69 (r'\b(assert)\b', Keyword, 'assert'), 

70 (r'\|', Text, 'continued_line'), 

71 (r'[ \t]*\n', Whitespace), 

72 ], 

73 

74 # Whitespace / Comment 

75 'whitespace': [ 

76 (r'^([ \t]*)(;.*)', bygroups(Comment.Single, Whitespace)), 

77 (r'[ \t]+(?![; \t])', Whitespace), 

78 (r'\{', Comment.Multiline, 'multiline_comment'), 

79 ], 

80 'multiline_comment': [ 

81 (r'\{', Comment.Multiline, 'multiline_comment'), 

82 (r'(?:\s*;.*|[^{}\n]+)', Comment.Multiline), 

83 (r'\n', Comment.Multiline), 

84 (r'\}', Comment.Multiline, '#pop'), 

85 ], 

86 

87 # Block-statement 

88 'func_': [ 

89 include('expr'), 

90 (r'\n', Whitespace, 'func'), 

91 ], 

92 'func': [ 

93 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(func)\b', 

94 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

95 include('statement'), 

96 ], 

97 'class_': [ 

98 include('expr'), 

99 (r'\n', Whitespace, 'class'), 

100 ], 

101 'class': [ 

102 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(class)\b', 

103 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

104 include('statement'), 

105 ], 

106 'enum_': [ 

107 include('expr'), 

108 (r'\n', Whitespace, 'enum'), 

109 ], 

110 'enum': [ 

111 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(enum)\b', 

112 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

113 include('expr'), 

114 (r'\n', Whitespace), 

115 ], 

116 'block_': [ 

117 include('expr'), 

118 (r'\n', Whitespace, 'block'), 

119 ], 

120 'block': [ 

121 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(block)\b', 

122 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

123 include('statement'), 

124 include('break'), 

125 include('skip'), 

126 ], 

127 'ifdef_': [ 

128 include('expr'), 

129 (r'\n', Whitespace, 'ifdef'), 

130 ], 

131 'ifdef': [ 

132 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(ifdef)\b', 

133 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

134 (words(('rls', 'dbg'), prefix=r'\b', suffix=r'\b'), 

135 Keyword.Constant, 'ifdef_sp'), 

136 include('statement'), 

137 include('break'), 

138 include('skip'), 

139 ], 

140 'ifdef_sp': [ 

141 include('expr'), 

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

143 ], 

144 'if_': [ 

145 include('expr'), 

146 (r'\n', Whitespace, 'if'), 

147 ], 

148 'if': [ 

149 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(if)\b', 

150 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

151 (words(('elif', 'else'), prefix=r'\b', suffix=r'\b'), Keyword, 'if_sp'), 

152 include('statement'), 

153 include('break'), 

154 include('skip'), 

155 ], 

156 'if_sp': [ 

157 include('expr'), 

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

159 ], 

160 'switch_': [ 

161 include('expr'), 

162 (r'\n', Whitespace, 'switch'), 

163 ], 

164 'switch': [ 

165 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(switch)\b', 

166 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

167 (words(('case', 'default', 'to'), prefix=r'\b', suffix=r'\b'), 

168 Keyword, 'switch_sp'), 

169 include('statement'), 

170 include('break'), 

171 include('skip'), 

172 ], 

173 'switch_sp': [ 

174 include('expr'), 

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

176 ], 

177 'while_': [ 

178 include('expr'), 

179 (r'\n', Whitespace, 'while'), 

180 ], 

181 'while': [ 

182 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(while)\b', 

183 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

184 include('statement'), 

185 include('break'), 

186 include('skip'), 

187 ], 

188 'for_': [ 

189 include('expr'), 

190 (r'\n', Whitespace, 'for'), 

191 ], 

192 'for': [ 

193 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(for)\b', 

194 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

195 include('statement'), 

196 include('break'), 

197 include('skip'), 

198 ], 

199 'foreach_': [ 

200 include('expr'), 

201 (r'\n', Whitespace, 'foreach'), 

202 ], 

203 'foreach': [ 

204 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(foreach)\b', 

205 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

206 include('statement'), 

207 include('break'), 

208 include('skip'), 

209 ], 

210 'try_': [ 

211 include('expr'), 

212 (r'\n', Whitespace, 'try'), 

213 ], 

214 'try': [ 

215 (r'\b(end)([ \t]+(?:\n\s*\|)*[ \t]*)(try)\b', 

216 bygroups(Keyword, using(this), Keyword), '#pop:2'), 

217 (words(('catch', 'finally', 'to'), prefix=r'\b', suffix=r'\b'), 

218 Keyword, 'try_sp'), 

219 include('statement'), 

220 include('break'), 

221 include('skip'), 

222 ], 

223 'try_sp': [ 

224 include('expr'), 

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

226 ], 

227 

228 # Line-statement 

229 'break': [ 

230 (r'\b(break)\b([ \t]+)([a-zA-Z_][0-9a-zA-Z_]*)', 

231 bygroups(Keyword, using(this), Name.Other)), 

232 ], 

233 'skip': [ 

234 (r'\b(skip)\b([ \t]+)([a-zA-Z_][0-9a-zA-Z_]*)', 

235 bygroups(Keyword, using(this), Name.Other)), 

236 ], 

237 'alias': [ 

238 include('expr'), 

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

240 ], 

241 'assert': [ 

242 include('expr'), 

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

244 ], 

245 'const': [ 

246 include('expr'), 

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

248 ], 

249 'do': [ 

250 include('expr'), 

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

252 ], 

253 'ret': [ 

254 include('expr'), 

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

256 ], 

257 'throw': [ 

258 include('expr'), 

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

260 ], 

261 'var': [ 

262 include('expr'), 

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

264 ], 

265 'continued_line': [ 

266 include('expr'), 

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

268 ], 

269 

270 'expr': [ 

271 # Whitespace / Comment 

272 include('whitespace'), 

273 

274 # Punctuation 

275 (r'\(', Punctuation,), 

276 (r'\)', Punctuation,), 

277 (r'\[', Punctuation,), 

278 (r'\]', Punctuation,), 

279 (r',', Punctuation), 

280 

281 # Keyword 

282 (words(( 

283 'true', 'false', 'null', 'inf' 

284 ), prefix=r'\b', suffix=r'\b'), Keyword.Constant), 

285 (words(( 

286 'me' 

287 ), prefix=r'\b', suffix=r'\b'), Keyword), 

288 (words(( 

289 'bit16', 'bit32', 'bit64', 'bit8', 'bool', 

290 'char', 'class', 'dict', 'enum', 'float', 'func', 

291 'int', 'list', 'queue', 'stack' 

292 ), prefix=r'\b', suffix=r'\b'), Keyword.Type), 

293 

294 # Number 

295 (r'\b[0-9]\.[0-9]+(?!\.)(:?e[\+-][0-9]+)?\b', Number.Float), 

296 (r'\b2#[01]+(?:b(?:8|16|32|64))?\b', Number.Bin), 

297 (r'\b8#[0-7]+(?:b(?:8|16|32|64))?\b', Number.Oct), 

298 (r'\b16#[0-9A-F]+(?:b(?:8|16|32|64))?\b', Number.Hex), 

299 (r'\b[0-9]+(?:b(?:8|16|32|64))?\b', Number.Decimal), 

300 

301 # String / Char 

302 (r'"', String.Double, 'string'), 

303 (r"'(?:\\.|.)+?'", String.Char), 

304 

305 # Operator 

306 (r'(?:\.|\$(?:>|<)?)', Operator), 

307 (r'(?:\^)', Operator), 

308 (r'(?:\+|-|!|##?)', Operator), 

309 (r'(?:\*|/|%)', Operator), 

310 (r'(?:~)', Operator), 

311 (r'(?:(?:=|<>)(?:&|\$)?|<=?|>=?)', Operator), 

312 (r'(?:&)', Operator), 

313 (r'(?:\|)', Operator), 

314 (r'(?:\?)', Operator), 

315 (r'(?::(?::|\+|-|\*|/|%|\^|~)?)', Operator), 

316 

317 # Identifier 

318 (r"\b([a-zA-Z_][0-9a-zA-Z_]*)(?=@)\b", Name), 

319 (r"(@)?\b([a-zA-Z_][0-9a-zA-Z_]*)\b", 

320 bygroups(Name.Other, Name.Variable)), 

321 ], 

322 

323 # String 

324 'string': [ 

325 (r'(?:\\[^{\n]|[^"\\])+', String.Double), 

326 (r'\\\{', String.Double, 'toStrInString'), 

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

328 ], 

329 'toStrInString': [ 

330 include('expr'), 

331 (r'\}', String.Double, '#pop'), 

332 ], 

333 }