Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/tal.py: 100%
12 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.tal
3 ~~~~~~~~~~~~~~~~~~~
5 Lexer for Uxntal
7 .. versionadded:: 2.12
9 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details.
11"""
13from pygments.lexer import RegexLexer, words
14from pygments.token import Comment, Keyword, Name, String, Number, \
15 Punctuation, Whitespace, Literal
17__all__ = ['TalLexer']
20class TalLexer(RegexLexer):
21 """
22 For `Uxntal <https://wiki.xxiivv.com/site/uxntal.html>`_ source code.
24 .. versionadded:: 2.12
25 """
27 name = 'Tal'
28 aliases = ['tal', 'uxntal']
29 filenames = ['*.tal']
30 mimetypes = ['text/x-uxntal']
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 ]
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 also
42 # applies to nested comments.
43 'comment': [
44 (r'(?<!\S)\((?!\S)', Comment.Multiline, '#push'), # nested comments
45 (r'(?<!\S)\)(?!\S)', Comment.Multiline, '#pop'), # nested comments
46 (r'[^()]+', Comment.Multiline), # comments
47 (r'[()]+', Comment.Multiline), # comments
48 ],
49 'root': [
50 (r'\s+', Whitespace), # spaces
51 (r'(?<!\S)\((?!\S)', Comment.Multiline, 'comment'), # comments
52 (words(instructions, prefix=r'(?<!\S)', suffix=r'2?k?r?(?!\S)'),
53 Keyword.Reserved), # instructions
54 (r'[][{}](?!\S)', Punctuation), # delimiters
55 (r'#([0-9a-f]{2}){1,2}(?!\S)', Number.Hex), # integer
56 (r'"\S+', String), # raw string
57 (r'([0-9a-f]{2}){1,2}(?!\S)', Literal), # raw integer
58 (r'[|$][0-9a-f]{1,4}(?!\S)', Keyword.Declaration), # abs/rel pad
59 (r'%\S+', Name.Decorator), # macro
60 (r'@\S+', Name.Function), # label
61 (r'&\S+', Name.Label), # sublabel
62 (r'/\S+', Name.Tag), # spacer
63 (r'\.\S+', Name.Variable.Magic), # literal zero page addr
64 (r',\S+', Name.Variable.Instance), # literal rel addr
65 (r';\S+', Name.Variable.Global), # literal abs addr
66 (r'-\S+', Literal), # raw zero page addr
67 (r'_\S+', Literal), # raw relative addr
68 (r'=\S+', Literal), # raw absolute addr
69 (r'!\S+', Name.Function), # immediate jump
70 (r'\?\S+', Name.Function), # conditional immediate jump
71 (r'~\S+', Keyword.Namespace), # include
72 (r'\S+', Name.Function), # macro invocation, immediate subroutine
73 ]
74 }
76 def analyse_text(text):
77 return '|0100' in text[:500]