rana-cli/wakatime/packages/pygments/lexers/chapel.py

103 lines
3.4 KiB
Python
Raw Normal View History

2014-12-01 06:10:30 +00:00
# -*- coding: utf-8 -*-
"""
pygments.lexers.chapel
~~~~~~~~~~~~~~~~~~~~~~
Lexer for the Chapel language.
2017-02-14 07:25:51 +00:00
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
2014-12-01 06:10:30 +00:00
:license: BSD, see LICENSE for details.
"""
from pygments.lexer import RegexLexer, bygroups, words
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation
__all__ = ['ChapelLexer']
class ChapelLexer(RegexLexer):
"""
For `Chapel <http://chapel.cray.com/>`_ source.
.. versionadded:: 2.0
"""
name = 'Chapel'
filenames = ['*.chpl']
aliases = ['chapel', 'chpl']
# mimetypes = ['text/x-chapel']
tokens = {
'root': [
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text),
(r'//(.*?)\n', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'(config|const|in|inout|out|param|ref|type|var)\b',
Keyword.Declaration),
(r'(false|nil|true)\b', Keyword.Constant),
(r'(bool|complex|imag|int|opaque|range|real|string|uint)\b',
Keyword.Type),
(words((
2017-02-14 07:25:51 +00:00
'align', 'as', 'atomic', 'begin', 'break', 'by', 'cobegin',
'coforall', 'continue', 'delete', 'dmapped', 'do', 'domain',
'else', 'enum', 'except', 'export', 'extern', 'for', 'forall',
'if', 'index', 'inline', 'iter', 'label', 'lambda', 'let',
'local', 'new', 'noinit', 'on', 'only', 'otherwise', 'pragma',
'private', 'public', 'reduce', 'require', 'return', 'scan',
'select', 'serial', 'single', 'sparse', 'subdomain', 'sync',
'then', 'use', 'when', 'where', 'while', 'with', 'yield',
'zip'), suffix=r'\b'),
2014-12-01 06:10:30 +00:00
Keyword),
2017-02-14 07:25:51 +00:00
(r'(proc)((?:\s)+)', bygroups(Keyword, Text), 'procname'),
2014-12-01 06:10:30 +00:00
(r'(class|module|record|union)(\s+)', bygroups(Keyword, Text),
'classname'),
# imaginary integers
(r'\d+i', Number),
(r'\d+\.\d*([Ee][-+]\d+)?i', Number),
(r'\.\d+([Ee][-+]\d+)?i', Number),
(r'\d+[Ee][-+]\d+i', Number),
# reals cannot end with a period due to lexical ambiguity with
# .. operator. See reference for rationale.
(r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float),
(r'\d+[eE][+-]?[0-9]+i?', Number.Float),
# integer literals
# -- binary
(r'0[bB][01]+', Number.Bin),
# -- hex
(r'0[xX][0-9a-fA-F]+', Number.Hex),
# -- octal
(r'0[oO][0-7]+', Number.Oct),
# -- decimal
(r'[0-9]+', Number.Integer),
# strings
2016-06-13 14:41:17 +00:00
(r'"(\\\\|\\"|[^"])*"', String),
(r"'(\\\\|\\'|[^'])*'", String),
2014-12-01 06:10:30 +00:00
# tokens
(r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|'
r'<=>|<~>|\.\.|by|#|\.\.\.|'
r'&&|\|\||!|&|\||\^|~|<<|>>|'
r'==|!=|<=|>=|<|>|'
r'[+\-*/%]|\*\*)', Operator),
(r'[:;,.?()\[\]{}]', Punctuation),
# identifiers
(r'[a-zA-Z_][\w$]*', Name.Other),
],
'classname': [
(r'[a-zA-Z_][\w$]*', Name.Class, '#pop'),
],
'procname': [
2017-02-14 07:25:51 +00:00
(r'([a-zA-Z_][\w$]+|\~[a-zA-Z_][\w$]+|[+*/!~%<>=&^|\-]{1,2})',
Name.Function, '#pop'),
2014-12-01 06:10:30 +00:00
],
}