x10.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """
  2. pygments.lexers.x10
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexers for the X10 programming language.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer
  9. from pygments.token import Text, Comment, Keyword, String
  10. __all__ = ['X10Lexer']
  11. class X10Lexer(RegexLexer):
  12. """
  13. For the X10 language.
  14. """
  15. name = 'X10'
  16. url = 'http://x10-lang.org/'
  17. aliases = ['x10', 'xten']
  18. filenames = ['*.x10']
  19. mimetypes = ['text/x-x10']
  20. version_added = '2.2'
  21. keywords = (
  22. 'as', 'assert', 'async', 'at', 'athome', 'ateach', 'atomic',
  23. 'break', 'case', 'catch', 'class', 'clocked', 'continue',
  24. 'def', 'default', 'do', 'else', 'final', 'finally', 'finish',
  25. 'for', 'goto', 'haszero', 'here', 'if', 'import', 'in',
  26. 'instanceof', 'interface', 'isref', 'new', 'offer',
  27. 'operator', 'package', 'return', 'struct', 'switch', 'throw',
  28. 'try', 'type', 'val', 'var', 'when', 'while'
  29. )
  30. types = (
  31. 'void'
  32. )
  33. values = (
  34. 'false', 'null', 'self', 'super', 'this', 'true'
  35. )
  36. modifiers = (
  37. 'abstract', 'extends', 'implements', 'native', 'offers',
  38. 'private', 'property', 'protected', 'public', 'static',
  39. 'throws', 'transient'
  40. )
  41. tokens = {
  42. 'root': [
  43. (r'[^\S\n]+', Text),
  44. (r'//.*?\n', Comment.Single),
  45. (r'/\*(.|\n)*?\*/', Comment.Multiline),
  46. (r'\b({})\b'.format('|'.join(keywords)), Keyword),
  47. (r'\b({})\b'.format('|'.join(types)), Keyword.Type),
  48. (r'\b({})\b'.format('|'.join(values)), Keyword.Constant),
  49. (r'\b({})\b'.format('|'.join(modifiers)), Keyword.Declaration),
  50. (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
  51. (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
  52. (r'.', Text)
  53. ],
  54. }