chapel.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.chapel
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for the Chapel language.
  6. :copyright: Copyright 2006-2019 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',
  36. 'begin', 'borrowed', 'break', 'by',
  37. 'catch', 'cobegin', 'coforall', 'continue',
  38. 'delete', 'dmapped', 'do', 'domain',
  39. 'else', 'enum', 'except', 'export', 'extern',
  40. 'for', 'forall',
  41. 'if', 'index', 'inline',
  42. 'label', 'lambda', 'let', 'local',
  43. 'new', 'noinit',
  44. 'on', 'only', 'otherwise', 'override', 'owned',
  45. 'pragma', 'private', 'prototype', 'public',
  46. 'reduce', 'require', 'return',
  47. 'scan', 'select', 'serial', 'shared', 'single', 'sparse', 'subdomain', 'sync',
  48. 'then', 'throw', 'throws', 'try',
  49. 'unmanaged', 'use',
  50. 'when', 'where', 'while', 'with',
  51. 'yield',
  52. 'zip'), suffix=r'\b'),
  53. Keyword),
  54. (r'(iter)((?:\s)+)', bygroups(Keyword, Text), 'procname'),
  55. (r'(proc)((?:\s)+)', bygroups(Keyword, Text), 'procname'),
  56. (r'(class|module|record|union)(\s+)', bygroups(Keyword, Text),
  57. 'classname'),
  58. # imaginary integers
  59. (r'\d+i', Number),
  60. (r'\d+\.\d*([Ee][-+]\d+)?i', Number),
  61. (r'\.\d+([Ee][-+]\d+)?i', Number),
  62. (r'\d+[Ee][-+]\d+i', Number),
  63. # reals cannot end with a period due to lexical ambiguity with
  64. # .. operator. See reference for rationale.
  65. (r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float),
  66. (r'\d+[eE][+-]?[0-9]+i?', Number.Float),
  67. # integer literals
  68. # -- binary
  69. (r'0[bB][01]+', Number.Bin),
  70. # -- hex
  71. (r'0[xX][0-9a-fA-F]+', Number.Hex),
  72. # -- octal
  73. (r'0[oO][0-7]+', Number.Oct),
  74. # -- decimal
  75. (r'[0-9]+', Number.Integer),
  76. # strings
  77. (r'"(\\\\|\\"|[^"])*"', String),
  78. (r"'(\\\\|\\'|[^'])*'", String),
  79. # tokens
  80. (r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|'
  81. r'<=>|<~>|\.\.|by|#|\.\.\.|'
  82. r'&&|\|\||!|&|\||\^|~|<<|>>|'
  83. r'==|!=|<=|>=|<|>|'
  84. r'[+\-*/%]|\*\*)', Operator),
  85. (r'[:;,.?()\[\]{}]', Punctuation),
  86. # identifiers
  87. (r'[a-zA-Z_][\w$]*', Name.Other),
  88. ],
  89. 'classname': [
  90. (r'[a-zA-Z_][\w$]*', Name.Class, '#pop'),
  91. ],
  92. 'procname': [
  93. (r'([a-zA-Z_][.\w$]*|\~[a-zA-Z_][.\w$]*|[+*/!~%<>=&^|\-]{1,2})',
  94. Name.Function, '#pop'),
  95. ],
  96. }