tal.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. pygments.lexers.tal
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for Uxntal
  5. .. versionadded:: 2.12
  6. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer, words
  10. from pygments.token import Comment, Keyword, Name, String, Number, \
  11. Punctuation, Whitespace, Literal
  12. __all__ = ['TalLexer']
  13. class TalLexer(RegexLexer):
  14. """
  15. For Uxntal source code.
  16. """
  17. name = 'Tal'
  18. aliases = ['tal', 'uxntal']
  19. filenames = ['*.tal']
  20. mimetypes = ['text/x-uxntal']
  21. url = 'https://wiki.xxiivv.com/site/uxntal.html'
  22. version_added = '2.12'
  23. instructions = [
  24. 'BRK', 'LIT', 'INC', 'POP', 'DUP', 'NIP', 'SWP', 'OVR', 'ROT',
  25. 'EQU', 'NEQ', 'GTH', 'LTH', 'JMP', 'JCN', 'JSR', 'STH',
  26. 'LDZ', 'STZ', 'LDR', 'STR', 'LDA', 'STA', 'DEI', 'DEO',
  27. 'ADD', 'SUB', 'MUL', 'DIV', 'AND', 'ORA', 'EOR', 'SFT'
  28. ]
  29. tokens = {
  30. # the comment delimiters must not be adjacent to non-space characters.
  31. # this means ( foo ) is a valid comment but (foo) is not. this also
  32. # applies to nested comments.
  33. 'comment': [
  34. (r'(?<!\S)\((?!\S)', Comment.Multiline, '#push'), # nested comments
  35. (r'(?<!\S)\)(?!\S)', Comment.Multiline, '#pop'), # nested comments
  36. (r'[^()]+', Comment.Multiline), # comments
  37. (r'[()]+', Comment.Multiline), # comments
  38. ],
  39. 'root': [
  40. (r'\s+', Whitespace), # spaces
  41. (r'(?<!\S)\((?!\S)', Comment.Multiline, 'comment'), # comments
  42. (words(instructions, prefix=r'(?<!\S)', suffix=r'2?k?r?(?!\S)'),
  43. Keyword.Reserved), # instructions
  44. (r'[][{}](?!\S)', Punctuation), # delimiters
  45. (r'#([0-9a-f]{2}){1,2}(?!\S)', Number.Hex), # integer
  46. (r'"\S+', String), # raw string
  47. (r'([0-9a-f]{2}){1,2}(?!\S)', Literal), # raw integer
  48. (r'[|$][0-9a-f]{1,4}(?!\S)', Keyword.Declaration), # abs/rel pad
  49. (r'%\S+', Name.Decorator), # macro
  50. (r'@\S+', Name.Function), # label
  51. (r'&\S+', Name.Label), # sublabel
  52. (r'/\S+', Name.Tag), # spacer
  53. (r'\.\S+', Name.Variable.Magic), # literal zero page addr
  54. (r',\S+', Name.Variable.Instance), # literal rel addr
  55. (r';\S+', Name.Variable.Global), # literal abs addr
  56. (r'-\S+', Literal), # raw zero page addr
  57. (r'_\S+', Literal), # raw relative addr
  58. (r'=\S+', Literal), # raw absolute addr
  59. (r'!\S+', Name.Function), # immediate jump
  60. (r'\?\S+', Name.Function), # conditional immediate jump
  61. (r'~\S+', Keyword.Namespace), # include
  62. (r'\S+', Name.Function), # macro invocation, immediate subroutine
  63. ]
  64. }
  65. def analyse_text(text):
  66. return '|0100' in text[:500]