eric6/ThirdParty/Pygments/pygments/lexers/teraterm.py

changeset 8258
82b608e352ec
parent 8257
28146736bbfc
child 8259
2bbec88047dd
equal deleted inserted replaced
8257:28146736bbfc 8258:82b608e352ec
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.teraterm
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexer for Tera Term macro files.
7
8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 import re
13
14 from pygments.lexer import RegexLexer, include, bygroups
15 from pygments.token import Text, Comment, Operator, Name, String, \
16 Number, Keyword
17
18 __all__ = ['TeraTermLexer']
19
20
21 class TeraTermLexer(RegexLexer):
22 """
23 For `Tera Term <https://ttssh2.osdn.jp/>`_ macro source code.
24
25 .. versionadded:: 2.4
26 """
27 name = 'Tera Term macro'
28 aliases = ['ttl', 'teraterm', 'teratermmacro']
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, 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, 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"'", String.Single, 'in-single-string'),
307 (r'"', String.Double, 'in-double-string'),
308 ],
309 'in-general-string': [
310 (r'\\[\\nt]', String.Escape), # Only three escapes are supported.
311 (r'.', String),
312 ],
313 'in-single-string': [
314 (r"'", String.Single, '#pop'),
315 include('in-general-string'),
316 ],
317 'in-double-string': [
318 (r'"', String.Double, '#pop'),
319 include('in-general-string'),
320 ],
321 'operators': [
322 (r'and|not|or|xor', Operator.Word),
323 (r'[!%&*+<=>^~\|\/-]+', Operator),
324 (r'[()]', String.Symbol),
325 ],
326 'all-whitespace': [
327 (r'\s+', Text),
328 ],
329 }
330
331 # Turtle and Tera Term macro files share the same file extension
332 # but each has a recognizable and distinct syntax.
333 def analyse_text(text):
334 if re.search(TeraTermLexer.tokens['commands'][0][0], text):
335 return 0.01

eric ide

mercurial