x10.py 1.9 KB

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