|
""" |
|
pygments.lexers.tal |
|
~~~~~~~~~~~~~~~~~~~ |
|
|
|
Lexer for Uxntal |
|
|
|
.. versionadded:: 2.12 |
|
|
|
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. |
|
:license: BSD, see LICENSE for details. |
|
""" |
|
|
|
from pygments.lexer import RegexLexer, words |
|
from pygments.token import Comment, Keyword, Name, String, Number, \ |
|
Punctuation, Whitespace, Literal |
|
|
|
__all__ = ['TalLexer'] |
|
|
|
|
|
class TalLexer(RegexLexer): |
|
""" |
|
For Uxntal source code. |
|
""" |
|
|
|
name = 'Tal' |
|
aliases = ['tal', 'uxntal'] |
|
filenames = ['*.tal'] |
|
mimetypes = ['text/x-uxntal'] |
|
url = 'https://wiki.xxiivv.com/site/uxntal.html' |
|
version_added = '2.12' |
|
|
|
instructions = [ |
|
'BRK', 'LIT', 'INC', 'POP', 'DUP', 'NIP', 'SWP', 'OVR', 'ROT', |
|
'EQU', 'NEQ', 'GTH', 'LTH', 'JMP', 'JCN', 'JSR', 'STH', |
|
'LDZ', 'STZ', 'LDR', 'STR', 'LDA', 'STA', 'DEI', 'DEO', |
|
'ADD', 'SUB', 'MUL', 'DIV', 'AND', 'ORA', 'EOR', 'SFT' |
|
] |
|
|
|
tokens = { |
|
|
|
|
|
|
|
'comment': [ |
|
(r'(?<!\S)\((?!\S)', Comment.Multiline, '#push'), |
|
(r'(?<!\S)\)(?!\S)', Comment.Multiline, '#pop'), |
|
(r'[^()]+', Comment.Multiline), |
|
(r'[()]+', Comment.Multiline), |
|
], |
|
'root': [ |
|
(r'\s+', Whitespace), |
|
(r'(?<!\S)\((?!\S)', Comment.Multiline, 'comment'), |
|
(words(instructions, prefix=r'(?<!\S)', suffix=r'2?k?r?(?!\S)'), |
|
Keyword.Reserved), |
|
(r'[][{}](?!\S)', Punctuation), |
|
(r'#([0-9a-f]{2}){1,2}(?!\S)', Number.Hex), |
|
(r'"\S+', String), |
|
(r'([0-9a-f]{2}){1,2}(?!\S)', Literal), |
|
(r'[|$][0-9a-f]{1,4}(?!\S)', Keyword.Declaration), |
|
(r'%\S+', Name.Decorator), |
|
(r'@\S+', Name.Function), |
|
(r'&\S+', Name.Label), |
|
(r'/\S+', Name.Tag), |
|
(r'\.\S+', Name.Variable.Magic), |
|
(r',\S+', Name.Variable.Instance), |
|
(r';\S+', Name.Variable.Global), |
|
(r'-\S+', Literal), |
|
(r'_\S+', Literal), |
|
(r'=\S+', Literal), |
|
(r'!\S+', Name.Function), |
|
(r'\?\S+', Name.Function), |
|
(r'~\S+', Keyword.Namespace), |
|
(r'\S+', Name.Function), |
|
] |
|
} |
|
|
|
def analyse_text(text): |
|
return '|0100' in text[:500] |
|
|