numbair.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. pygments.lexers.numbair
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for other Numba Intermediate Representation.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include, bygroups, words
  9. from pygments.token import Whitespace, Name, String, Punctuation, Keyword, \
  10. Operator, Number
  11. __all__ = ["NumbaIRLexer"]
  12. class NumbaIRLexer(RegexLexer):
  13. """
  14. Lexer for Numba IR
  15. """
  16. name = 'Numba_IR'
  17. url = "https://numba.readthedocs.io/en/stable/developer/architecture.html#stage-2-generate-the-numba-ir"
  18. aliases = ['numba_ir', 'numbair']
  19. filenames = ['*.numba_ir']
  20. mimetypes = ['text/x-numba_ir', 'text/x-numbair']
  21. version_added = '2.19'
  22. identifier = r'\$[a-zA-Z0-9._]+'
  23. fun_or_var = r'([a-zA-Z_]+[a-zA-Z0-9]*)'
  24. tokens = {
  25. 'root' : [
  26. (r'(label)(\ [0-9]+)(:)$',
  27. bygroups(Keyword, Name.Label, Punctuation)),
  28. (r'=', Operator),
  29. include('whitespace'),
  30. include('keyword'),
  31. (identifier, Name.Variable),
  32. (fun_or_var + r'(\()',
  33. bygroups(Name.Function, Punctuation)),
  34. (fun_or_var + r'(\=)',
  35. bygroups(Name.Attribute, Punctuation)),
  36. (fun_or_var, Name.Constant),
  37. (r'[0-9]+', Number),
  38. # <built-in function some>
  39. (r'<[^>\n]*>', String),
  40. (r'[=<>{}\[\]()*.,!\':]|x\b', Punctuation)
  41. ],
  42. 'keyword':[
  43. (words((
  44. 'del', 'jump', 'call', 'branch',
  45. ), suffix=' '), Keyword),
  46. ],
  47. 'whitespace': [
  48. (r'(\n|\s)+', Whitespace),
  49. ],
  50. }