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

14 statements  

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

1""" 

2 pygments.lexers.teraterm 

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

4 

5 Lexer for Tera Term macro files. 

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 

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

15 Number, Keyword, Error 

16 

17__all__ = ['TeraTermLexer'] 

18 

19 

20class TeraTermLexer(RegexLexer): 

21 """ 

22 For Tera Term macro source code. 

23 

24 .. versionadded:: 2.4 

25 """ 

26 name = 'Tera Term macro' 

27 url = 'https://ttssh2.osdn.jp/' 

28 aliases = ['teratermmacro', 'teraterm', 'ttl'] 

29 filenames = ['*.ttl'] 

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

31 

32 tokens = { 

33 'root': [ 

34 include('comments'), 

35 include('labels'), 

36 include('commands'), 

37 include('builtin-variables'), 

38 include('user-variables'), 

39 include('operators'), 

40 include('numeric-literals'), 

41 include('string-literals'), 

42 include('all-whitespace'), 

43 (r'\S', Text), 

44 ], 

45 'comments': [ 

46 (r';[^\r\n]*', Comment.Single), 

47 (r'/\*', Comment.Multiline, 'in-comment'), 

48 ], 

49 'in-comment': [ 

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

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

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

53 ], 

54 'labels': [ 

55 (r'(?i)^(\s*)(:[a-z0-9_]+)', bygroups(Text.Whitespace, Name.Label)), 

56 ], 

57 'commands': [ 

58 ( 

59 r'(?i)\b(' 

60 r'basename|' 

61 r'beep|' 

62 r'bplusrecv|' 

63 r'bplussend|' 

64 r'break|' 

65 r'bringupbox|' 

66 # 'call' is handled separately. 

67 r'callmenu|' 

68 r'changedir|' 

69 r'checksum16|' 

70 r'checksum16file|' 

71 r'checksum32|' 

72 r'checksum32file|' 

73 r'checksum8|' 

74 r'checksum8file|' 

75 r'clearscreen|' 

76 r'clipb2var|' 

77 r'closesbox|' 

78 r'closett|' 

79 r'code2str|' 

80 r'connect|' 

81 r'continue|' 

82 r'crc16|' 

83 r'crc16file|' 

84 r'crc32|' 

85 r'crc32file|' 

86 r'cygconnect|' 

87 r'delpassword|' 

88 r'dirname|' 

89 r'dirnamebox|' 

90 r'disconnect|' 

91 r'dispstr|' 

92 r'do|' 

93 r'else|' 

94 r'elseif|' 

95 r'enablekeyb|' 

96 r'end|' 

97 r'endif|' 

98 r'enduntil|' 

99 r'endwhile|' 

100 r'exec|' 

101 r'execcmnd|' 

102 r'exit|' 

103 r'expandenv|' 

104 r'fileclose|' 

105 r'fileconcat|' 

106 r'filecopy|' 

107 r'filecreate|' 

108 r'filedelete|' 

109 r'filelock|' 

110 r'filemarkptr|' 

111 r'filenamebox|' 

112 r'fileopen|' 

113 r'fileread|' 

114 r'filereadln|' 

115 r'filerename|' 

116 r'filesearch|' 

117 r'fileseek|' 

118 r'fileseekback|' 

119 r'filestat|' 

120 r'filestrseek|' 

121 r'filestrseek2|' 

122 r'filetruncate|' 

123 r'fileunlock|' 

124 r'filewrite|' 

125 r'filewriteln|' 

126 r'findclose|' 

127 r'findfirst|' 

128 r'findnext|' 

129 r'flushrecv|' 

130 r'foldercreate|' 

131 r'folderdelete|' 

132 r'foldersearch|' 

133 r'for|' 

134 r'getdate|' 

135 r'getdir|' 

136 r'getenv|' 

137 r'getfileattr|' 

138 r'gethostname|' 

139 r'getipv4addr|' 

140 r'getipv6addr|' 

141 r'getmodemstatus|' 

142 r'getpassword|' 

143 r'getspecialfolder|' 

144 r'gettime|' 

145 r'gettitle|' 

146 r'getttdir|' 

147 r'getver|' 

148 # 'goto' is handled separately. 

149 r'if|' 

150 r'ifdefined|' 

151 r'include|' 

152 r'inputbox|' 

153 r'int2str|' 

154 r'intdim|' 

155 r'ispassword|' 

156 r'kmtfinish|' 

157 r'kmtget|' 

158 r'kmtrecv|' 

159 r'kmtsend|' 

160 r'listbox|' 

161 r'loadkeymap|' 

162 r'logautoclosemode|' 

163 r'logclose|' 

164 r'loginfo|' 

165 r'logopen|' 

166 r'logpause|' 

167 r'logrotate|' 

168 r'logstart|' 

169 r'logwrite|' 

170 r'loop|' 

171 r'makepath|' 

172 r'messagebox|' 

173 r'mpause|' 

174 r'next|' 

175 r'passwordbox|' 

176 r'pause|' 

177 r'quickvanrecv|' 

178 r'quickvansend|' 

179 r'random|' 

180 r'recvln|' 

181 r'regexoption|' 

182 r'restoresetup|' 

183 r'return|' 

184 r'rotateleft|' 

185 r'rotateright|' 

186 r'scprecv|' 

187 r'scpsend|' 

188 r'send|' 

189 r'sendbreak|' 

190 r'sendbroadcast|' 

191 r'sendfile|' 

192 r'sendkcode|' 

193 r'sendln|' 

194 r'sendlnbroadcast|' 

195 r'sendlnmulticast|' 

196 r'sendmulticast|' 

197 r'setbaud|' 

198 r'setdate|' 

199 r'setdebug|' 

200 r'setdir|' 

201 r'setdlgpos|' 

202 r'setdtr|' 

203 r'setecho|' 

204 r'setenv|' 

205 r'setexitcode|' 

206 r'setfileattr|' 

207 r'setflowctrl|' 

208 r'setmulticastname|' 

209 r'setpassword|' 

210 r'setrts|' 

211 r'setspeed|' 

212 r'setsync|' 

213 r'settime|' 

214 r'settitle|' 

215 r'show|' 

216 r'showtt|' 

217 r'sprintf|' 

218 r'sprintf2|' 

219 r'statusbox|' 

220 r'str2code|' 

221 r'str2int|' 

222 r'strcompare|' 

223 r'strconcat|' 

224 r'strcopy|' 

225 r'strdim|' 

226 r'strinsert|' 

227 r'strjoin|' 

228 r'strlen|' 

229 r'strmatch|' 

230 r'strremove|' 

231 r'strreplace|' 

232 r'strscan|' 

233 r'strspecial|' 

234 r'strsplit|' 

235 r'strtrim|' 

236 r'testlink|' 

237 r'then|' 

238 r'tolower|' 

239 r'toupper|' 

240 r'unlink|' 

241 r'until|' 

242 r'uptime|' 

243 r'var2clipb|' 

244 r'wait|' 

245 r'wait4all|' 

246 r'waitevent|' 

247 r'waitln|' 

248 r'waitn|' 

249 r'waitrecv|' 

250 r'waitregex|' 

251 r'while|' 

252 r'xmodemrecv|' 

253 r'xmodemsend|' 

254 r'yesnobox|' 

255 r'ymodemrecv|' 

256 r'ymodemsend|' 

257 r'zmodemrecv|' 

258 r'zmodemsend' 

259 r')\b', 

260 Keyword, 

261 ), 

262 (r'(?i)(call|goto)([ \t]+)([a-z0-9_]+)', 

263 bygroups(Keyword, Text.Whitespace, Name.Label)), 

264 ], 

265 'builtin-variables': [ 

266 ( 

267 r'(?i)(' 

268 r'groupmatchstr1|' 

269 r'groupmatchstr2|' 

270 r'groupmatchstr3|' 

271 r'groupmatchstr4|' 

272 r'groupmatchstr5|' 

273 r'groupmatchstr6|' 

274 r'groupmatchstr7|' 

275 r'groupmatchstr8|' 

276 r'groupmatchstr9|' 

277 r'inputstr|' 

278 r'matchstr|' 

279 r'mtimeout|' 

280 r'param1|' 

281 r'param2|' 

282 r'param3|' 

283 r'param4|' 

284 r'param5|' 

285 r'param6|' 

286 r'param7|' 

287 r'param8|' 

288 r'param9|' 

289 r'paramcnt|' 

290 r'params|' 

291 r'result|' 

292 r'timeout' 

293 r')\b', 

294 Name.Builtin 

295 ), 

296 ], 

297 'user-variables': [ 

298 (r'(?i)[a-z_][a-z0-9_]*', Name.Variable), 

299 ], 

300 'numeric-literals': [ 

301 (r'(-?)([0-9]+)', bygroups(Operator, Number.Integer)), 

302 (r'(?i)\$[0-9a-f]+', Number.Hex), 

303 ], 

304 'string-literals': [ 

305 (r'(?i)#(?:[0-9]+|\$[0-9a-f]+)', String.Char), 

306 (r"'[^'\n]*'", String.Single), 

307 (r'"[^"\n]*"', String.Double), 

308 # Opening quotes without a closing quote on the same line are errors. 

309 (r"('[^']*)(\n)", bygroups(Error, Text.Whitespace)), 

310 (r'("[^"]*)(\n)', bygroups(Error, Text.Whitespace)), 

311 ], 

312 'operators': [ 

313 (r'and|not|or|xor', Operator.Word), 

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

315 (r'[()]', String.Symbol), 

316 ], 

317 'all-whitespace': [ 

318 (r'\s+', Text.Whitespace), 

319 ], 

320 } 

321 

322 # Turtle and Tera Term macro files share the same file extension 

323 # but each has a recognizable and distinct syntax. 

324 def analyse_text(text): 

325 if re.search(TeraTermLexer.tokens['commands'][0][0], text): 

326 return 0.01