123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- """
- pygments.lexers.teraterm
- ~~~~~~~~~~~~~~~~~~~~~~~~
- Lexer for Tera Term macro files.
- :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
- :license: BSD, see LICENSE for details.
- """
- import re
- from pygments.lexer import RegexLexer, include, bygroups
- from pygments.token import Text, Comment, Operator, Name, String, \
- Number, Keyword
- __all__ = ['TeraTermLexer']
- class TeraTermLexer(RegexLexer):
- """
- For `Tera Term <https://ttssh2.osdn.jp/>`_ macro source code.
- .. versionadded:: 2.4
- """
- name = 'Tera Term macro'
- aliases = ['teratermmacro', 'teraterm', 'ttl']
- filenames = ['*.ttl']
- mimetypes = ['text/x-teratermmacro']
- tokens = {
- 'root': [
- include('comments'),
- include('labels'),
- include('commands'),
- include('builtin-variables'),
- include('user-variables'),
- include('operators'),
- include('numeric-literals'),
- include('string-literals'),
- include('all-whitespace'),
- (r'\S', Text),
- ],
- 'comments': [
- (r';[^\r\n]*', Comment.Single),
- (r'/\*', Comment.Multiline, 'in-comment'),
- ],
- 'in-comment': [
- (r'\*/', Comment.Multiline, '#pop'),
- (r'[^*/]+', Comment.Multiline),
- (r'[*/]', Comment.Multiline)
- ],
- 'labels': [
- (r'(?i)^(\s*)(:[a-z0-9_]+)', bygroups(Text, Name.Label)),
- ],
- 'commands': [
- (
- r'(?i)\b('
- r'basename|'
- r'beep|'
- r'bplusrecv|'
- r'bplussend|'
- r'break|'
- r'bringupbox|'
- # 'call' is handled separately.
- r'callmenu|'
- r'changedir|'
- r'checksum16|'
- r'checksum16file|'
- r'checksum32|'
- r'checksum32file|'
- r'checksum8|'
- r'checksum8file|'
- r'clearscreen|'
- r'clipb2var|'
- r'closesbox|'
- r'closett|'
- r'code2str|'
- r'connect|'
- r'continue|'
- r'crc16|'
- r'crc16file|'
- r'crc32|'
- r'crc32file|'
- r'cygconnect|'
- r'delpassword|'
- r'dirname|'
- r'dirnamebox|'
- r'disconnect|'
- r'dispstr|'
- r'do|'
- r'else|'
- r'elseif|'
- r'enablekeyb|'
- r'end|'
- r'endif|'
- r'enduntil|'
- r'endwhile|'
- r'exec|'
- r'execcmnd|'
- r'exit|'
- r'expandenv|'
- r'fileclose|'
- r'fileconcat|'
- r'filecopy|'
- r'filecreate|'
- r'filedelete|'
- r'filelock|'
- r'filemarkptr|'
- r'filenamebox|'
- r'fileopen|'
- r'fileread|'
- r'filereadln|'
- r'filerename|'
- r'filesearch|'
- r'fileseek|'
- r'fileseekback|'
- r'filestat|'
- r'filestrseek|'
- r'filestrseek2|'
- r'filetruncate|'
- r'fileunlock|'
- r'filewrite|'
- r'filewriteln|'
- r'findclose|'
- r'findfirst|'
- r'findnext|'
- r'flushrecv|'
- r'foldercreate|'
- r'folderdelete|'
- r'foldersearch|'
- r'for|'
- r'getdate|'
- r'getdir|'
- r'getenv|'
- r'getfileattr|'
- r'gethostname|'
- r'getipv4addr|'
- r'getipv6addr|'
- r'getmodemstatus|'
- r'getpassword|'
- r'getspecialfolder|'
- r'gettime|'
- r'gettitle|'
- r'getttdir|'
- r'getver|'
- # 'goto' is handled separately.
- r'if|'
- r'ifdefined|'
- r'include|'
- r'inputbox|'
- r'int2str|'
- r'intdim|'
- r'ispassword|'
- r'kmtfinish|'
- r'kmtget|'
- r'kmtrecv|'
- r'kmtsend|'
- r'listbox|'
- r'loadkeymap|'
- r'logautoclosemode|'
- r'logclose|'
- r'loginfo|'
- r'logopen|'
- r'logpause|'
- r'logrotate|'
- r'logstart|'
- r'logwrite|'
- r'loop|'
- r'makepath|'
- r'messagebox|'
- r'mpause|'
- r'next|'
- r'passwordbox|'
- r'pause|'
- r'quickvanrecv|'
- r'quickvansend|'
- r'random|'
- r'recvln|'
- r'regexoption|'
- r'restoresetup|'
- r'return|'
- r'rotateleft|'
- r'rotateright|'
- r'scprecv|'
- r'scpsend|'
- r'send|'
- r'sendbreak|'
- r'sendbroadcast|'
- r'sendfile|'
- r'sendkcode|'
- r'sendln|'
- r'sendlnbroadcast|'
- r'sendlnmulticast|'
- r'sendmulticast|'
- r'setbaud|'
- r'setdate|'
- r'setdebug|'
- r'setdir|'
- r'setdlgpos|'
- r'setdtr|'
- r'setecho|'
- r'setenv|'
- r'setexitcode|'
- r'setfileattr|'
- r'setflowctrl|'
- r'setmulticastname|'
- r'setpassword|'
- r'setrts|'
- r'setspeed|'
- r'setsync|'
- r'settime|'
- r'settitle|'
- r'show|'
- r'showtt|'
- r'sprintf|'
- r'sprintf2|'
- r'statusbox|'
- r'str2code|'
- r'str2int|'
- r'strcompare|'
- r'strconcat|'
- r'strcopy|'
- r'strdim|'
- r'strinsert|'
- r'strjoin|'
- r'strlen|'
- r'strmatch|'
- r'strremove|'
- r'strreplace|'
- r'strscan|'
- r'strspecial|'
- r'strsplit|'
- r'strtrim|'
- r'testlink|'
- r'then|'
- r'tolower|'
- r'toupper|'
- r'unlink|'
- r'until|'
- r'uptime|'
- r'var2clipb|'
- r'wait|'
- r'wait4all|'
- r'waitevent|'
- r'waitln|'
- r'waitn|'
- r'waitrecv|'
- r'waitregex|'
- r'while|'
- r'xmodemrecv|'
- r'xmodemsend|'
- r'yesnobox|'
- r'ymodemrecv|'
- r'ymodemsend|'
- r'zmodemrecv|'
- r'zmodemsend'
- r')\b',
- Keyword,
- ),
- (r'(?i)(call|goto)([ \t]+)([a-z0-9_]+)',
- bygroups(Keyword, Text, Name.Label)),
- ],
- 'builtin-variables': [
- (
- r'(?i)('
- r'groupmatchstr1|'
- r'groupmatchstr2|'
- r'groupmatchstr3|'
- r'groupmatchstr4|'
- r'groupmatchstr5|'
- r'groupmatchstr6|'
- r'groupmatchstr7|'
- r'groupmatchstr8|'
- r'groupmatchstr9|'
- r'inputstr|'
- r'matchstr|'
- r'mtimeout|'
- r'param1|'
- r'param2|'
- r'param3|'
- r'param4|'
- r'param5|'
- r'param6|'
- r'param7|'
- r'param8|'
- r'param9|'
- r'paramcnt|'
- r'params|'
- r'result|'
- r'timeout'
- r')\b',
- Name.Builtin
- ),
- ],
- 'user-variables': [
- (r'(?i)[a-z_][a-z0-9_]*', Name.Variable),
- ],
- 'numeric-literals': [
- (r'(-?)([0-9]+)', bygroups(Operator, Number.Integer)),
- (r'(?i)\$[0-9a-f]+', Number.Hex),
- ],
- 'string-literals': [
- (r'(?i)#(?:[0-9]+|\$[0-9a-f]+)', String.Char),
- (r"'", String.Single, 'in-single-string'),
- (r'"', String.Double, 'in-double-string'),
- ],
- 'in-general-string': [
- (r'\\[\\nt]', String.Escape), # Only three escapes are supported.
- (r'.', String),
- ],
- 'in-single-string': [
- (r"'", String.Single, '#pop'),
- include('in-general-string'),
- ],
- 'in-double-string': [
- (r'"', String.Double, '#pop'),
- include('in-general-string'),
- ],
- 'operators': [
- (r'and|not|or|xor', Operator.Word),
- (r'[!%&*+<=>^~\|\/-]+', Operator),
- (r'[()]', String.Symbol),
- ],
- 'all-whitespace': [
- (r'\s+', Text),
- ],
- }
- # Turtle and Tera Term macro files share the same file extension
- # but each has a recognizable and distinct syntax.
- def analyse_text(text):
- if re.search(TeraTermLexer.tokens['commands'][0][0], text):
- return 0.01
|