x10.py 1.9 KB

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