codekingpro/portable-devtools
114k
1"""2 pygments.lexers.tal3 ~~~~~~~~~~~~~~~~~~~4 5 Lexer for Uxntal6 7 .. versionadded:: 2.128 9 :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.10 :license: BSD, see LICENSE for details.11"""12 13from pygments.lexer import RegexLexer, words14from pygments.token import Comment, Keyword, Name, String, Number, \15 Punctuation, Whitespace, Literal16 17__all__ = ['TalLexer']18 19 20class TalLexer(RegexLexer):21 """22 For Uxntal source code.23 """24 25 name = 'Tal'26 aliases = ['tal', 'uxntal']27 filenames = ['*.tal']28 mimetypes = ['text/x-uxntal']29 url = 'https://wiki.xxiivv.com/site/uxntal.html'30 version_added = '2.12'31 32 instructions = [33 'BRK', 'LIT', 'INC', 'POP', 'DUP', 'NIP', 'SWP', 'OVR', 'ROT',34 'EQU', 'NEQ', 'GTH', 'LTH', 'JMP', 'JCN', 'JSR', 'STH',35 'LDZ', 'STZ', 'LDR', 'STR', 'LDA', 'STA', 'DEI', 'DEO',36 'ADD', 'SUB', 'MUL', 'DIV', 'AND', 'ORA', 'EOR', 'SFT'37 ]38 39 tokens = {40 # the comment delimiters must not be adjacent to non-space characters.41 # this means ( foo ) is a valid comment but (foo) is not. this also42 # applies to nested comments.43 'comment': [44 (r'(?<!\S)\((?!\S)', Comment.Multiline, '#push'), # nested comments45 (r'(?<!\S)\)(?!\S)', Comment.Multiline, '#pop'), # nested comments46 (r'[^()]+', Comment.Multiline), # comments47 (r'[()]+', Comment.Multiline), # comments48 ],49 'root': [50 (r'\s+', Whitespace), # spaces51 (r'(?<!\S)\((?!\S)', Comment.Multiline, 'comment'), # comments52 (words(instructions, prefix=r'(?<!\S)', suffix=r'2?k?r?(?!\S)'),53 Keyword.Reserved), # instructions54 (r'[][{}](?!\S)', Punctuation), # delimiters55 (r'#([0-9a-f]{2}){1,2}(?!\S)', Number.Hex), # integer56 (r'"\S+', String), # raw string57 (r'([0-9a-f]{2}){1,2}(?!\S)', Literal), # raw integer58 (r'[|$][0-9a-f]{1,4}(?!\S)', Keyword.Declaration), # abs/rel pad59 (r'%\S+', Name.Decorator), # macro60 (r'@\S+', Name.Function), # label61 (r'&\S+', Name.Label), # sublabel62 (r'/\S+', Name.Tag), # spacer63 (r'\.\S+', Name.Variable.Magic), # literal zero page addr64 (r',\S+', Name.Variable.Instance), # literal rel addr65 (r';\S+', Name.Variable.Global), # literal abs addr66 (r'-\S+', Literal), # raw zero page addr67 (r'_\S+', Literal), # raw relative addr68 (r'=\S+', Literal), # raw absolute addr69 (r'!\S+', Name.Function), # immediate jump70 (r'\?\S+', Name.Function), # conditional immediate jump71 (r'~\S+', Keyword.Namespace), # include72 (r'\S+', Name.Function), # macro invocation, immediate subroutine73 ]74 }75 76 def analyse_text(text):77 return '|0100' in text[:500]78 