chapel.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.chapel
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for the Chapel language.
  6. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer, bygroups, words
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation
  12. __all__ = ['ChapelLexer']
  13. class ChapelLexer(RegexLexer):
  14. """
  15. For `Chapel <http://chapel.cray.com/>`_ source.
  16. .. versionadded:: 2.0
  17. """
  18. name = 'Chapel'
  19. filenames = ['*.chpl']
  20. aliases = ['chapel', 'chpl']
  21. # mimetypes = ['text/x-chapel']
  22. tokens = {
  23. 'root': [
  24. (r'\n', Text),
  25. (r'\s+', Text),
  26. (r'\\\n', Text),
  27. (r'//(.*?)\n', Comment.Single),
  28. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  29. (r'(config|const|in|inout|out|param|ref|type|var)\b',
  30. Keyword.Declaration),
  31. (r'(false|nil|true)\b', Keyword.Constant),
  32. (r'(bool|complex|imag|int|opaque|range|real|string|uint)\b',
  33. Keyword.Type),
  34. (words((
  35. 'align', 'as', 'atomic', 'begin', 'break', 'by', 'cobegin',
  36. 'coforall', 'continue', 'delete', 'dmapped', 'do', 'domain',
  37. 'else', 'enum', 'except', 'export', 'extern', 'for', 'forall',
  38. 'if', 'index', 'inline', 'iter', 'label', 'lambda', 'let',
  39. 'local', 'new', 'noinit', 'on', 'only', 'otherwise', 'pragma',
  40. 'private', 'public', 'reduce', 'require', 'return', 'scan',
  41. 'select', 'serial', 'single', 'sparse', 'subdomain', 'sync',
  42. 'then', 'use', 'when', 'where', 'while', 'with', 'yield',
  43. 'zip'), suffix=r'\b'),
  44. Keyword),
  45. (r'(proc)((?:\s)+)', bygroups(Keyword, Text), 'procname'),
  46. (r'(class|module|record|union)(\s+)', bygroups(Keyword, Text),
  47. 'classname'),
  48. # imaginary integers
  49. (r'\d+i', Number),
  50. (r'\d+\.\d*([Ee][-+]\d+)?i', Number),
  51. (r'\.\d+([Ee][-+]\d+)?i', Number),
  52. (r'\d+[Ee][-+]\d+i', Number),
  53. # reals cannot end with a period due to lexical ambiguity with
  54. # .. operator. See reference for rationale.
  55. (r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float),
  56. (r'\d+[eE][+-]?[0-9]+i?', Number.Float),
  57. # integer literals
  58. # -- binary
  59. (r'0[bB][01]+', Number.Bin),
  60. # -- hex
  61. (r'0[xX][0-9a-fA-F]+', Number.Hex),
  62. # -- octal
  63. (r'0[oO][0-7]+', Number.Oct),
  64. # -- decimal
  65. (r'[0-9]+', Number.Integer),
  66. # strings
  67. (r'"(\\\\|\\"|[^"])*"', String),
  68. (r"'(\\\\|\\'|[^'])*'", String),
  69. # tokens
  70. (r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|'
  71. r'<=>|<~>|\.\.|by|#|\.\.\.|'
  72. r'&&|\|\||!|&|\||\^|~|<<|>>|'
  73. r'==|!=|<=|>=|<|>|'
  74. r'[+\-*/%]|\*\*)', Operator),
  75. (r'[:;,.?()\[\]{}]', Punctuation),
  76. # identifiers
  77. (r'[a-zA-Z_][\w$]*', Name.Other),
  78. ],
  79. 'classname': [
  80. (r'[a-zA-Z_][\w$]*', Name.Class, '#pop'),
  81. ],
  82. 'procname': [
  83. (r'([a-zA-Z_][\w$]+|\~[a-zA-Z_][\w$]+|[+*/!~%<>=&^|\-]{1,2})',
  84. Name.Function, '#pop'),
  85. ],
  86. }