Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/chapel.py: 100%
16 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-18 06:13 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-18 06:13 +0000
1"""
2 pygments.lexers.chapel
3 ~~~~~~~~~~~~~~~~~~~~~~
5 Lexer for the Chapel language.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, bygroups, words
12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 Number, Punctuation, Whitespace
15__all__ = ['ChapelLexer']
18class ChapelLexer(RegexLexer):
19 """
20 For Chapel source.
22 .. versionadded:: 2.0
23 """
24 name = 'Chapel'
25 url = 'https://chapel-lang.org/'
26 filenames = ['*.chpl']
27 aliases = ['chapel', 'chpl']
28 # mimetypes = ['text/x-chapel']
30 known_types = ('bool', 'bytes', 'complex', 'imag', 'int', 'locale',
31 'nothing', 'opaque', 'range', 'real', 'string', 'uint',
32 'void')
34 type_modifiers_par = ('atomic', 'single', 'sync')
35 type_modifiers_mem = ('borrowed', 'owned', 'shared', 'unmanaged')
36 type_modifiers = (*type_modifiers_par, *type_modifiers_mem)
38 declarations = ('config', 'const', 'in', 'inout', 'out', 'param', 'ref',
39 'type', 'var')
41 constants = ('false', 'nil', 'none', 'true')
43 other_keywords = ('align', 'as',
44 'begin', 'break', 'by',
45 'catch', 'cobegin', 'coforall', 'continue',
46 'defer', 'delete', 'dmapped', 'do', 'domain',
47 'else', 'enum', 'except', 'export', 'extern',
48 'for', 'forall', 'foreach', 'forwarding',
49 'if', 'implements', 'import', 'index', 'init', 'inline',
50 'label', 'lambda', 'let', 'lifetime', 'local',
51 'new', 'noinit',
52 'on', 'only', 'otherwise', 'override',
53 'pragma', 'primitive', 'private', 'prototype', 'public',
54 'reduce', 'require', 'return',
55 'scan', 'select', 'serial', 'sparse', 'subdomain',
56 'then', 'this', 'throw', 'throws', 'try',
57 'use',
58 'when', 'where', 'while', 'with',
59 'yield',
60 'zip')
62 tokens = {
63 'root': [
64 (r'\n', Whitespace),
65 (r'\s+', Whitespace),
66 (r'\\\n', Text),
68 (r'//(.*?)\n', Comment.Single),
69 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
71 (words(declarations, suffix=r'\b'), Keyword.Declaration),
72 (words(constants, suffix=r'\b'), Keyword.Constant),
73 (words(known_types, suffix=r'\b'), Keyword.Type),
74 (words((*type_modifiers, *other_keywords), suffix=r'\b'), Keyword),
76 (r'@', Keyword, 'attributename'),
77 (r'(iter)(\s+)', bygroups(Keyword, Whitespace), 'procname'),
78 (r'(proc)(\s+)', bygroups(Keyword, Whitespace), 'procname'),
79 (r'(operator)(\s+)', bygroups(Keyword, Whitespace), 'procname'),
80 (r'(class|interface|module|record|union)(\s+)', bygroups(Keyword, Whitespace),
81 'classname'),
83 # imaginary integers
84 (r'\d+i', Number),
85 (r'\d+\.\d*([Ee][-+]\d+)?i', Number),
86 (r'\.\d+([Ee][-+]\d+)?i', Number),
87 (r'\d+[Ee][-+]\d+i', Number),
89 # reals cannot end with a period due to lexical ambiguity with
90 # .. operator. See reference for rationale.
91 (r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float),
92 (r'\d+[eE][+-]?[0-9]+i?', Number.Float),
94 # integer literals
95 # -- binary
96 (r'0[bB][01]+', Number.Bin),
97 # -- hex
98 (r'0[xX][0-9a-fA-F]+', Number.Hex),
99 # -- octal
100 (r'0[oO][0-7]+', Number.Oct),
101 # -- decimal
102 (r'[0-9]+', Number.Integer),
104 # strings
105 (r'"(\\\\|\\"|[^"])*"', String),
106 (r"'(\\\\|\\'|[^'])*'", String),
108 # tokens
109 (r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|'
110 r'<=>|<~>|\.\.|by|#|\.\.\.|'
111 r'&&|\|\||!|&|\||\^|~|<<|>>|'
112 r'==|!=|<=|>=|<|>|'
113 r'[+\-*/%]|\*\*)', Operator),
114 (r'[:;,.?()\[\]{}]', Punctuation),
116 # identifiers
117 (r'[a-zA-Z_][\w$]*', Name.Other),
118 ],
119 'classname': [
120 (r'[a-zA-Z_][\w$]*', Name.Class, '#pop'),
121 ],
122 'procname': [
123 (r'([a-zA-Z_][.\w$]*|' # regular function name, including secondary
124 r'\~[a-zA-Z_][.\w$]*|' # support for legacy destructors
125 r'[+*/!~%<>=&^|\-:]{1,2})', # operators
126 Name.Function, '#pop'),
128 # allow `proc (atomic T).foo`
129 (r'\(', Punctuation, "receivertype"),
130 (r'\)+\.', Punctuation),
131 ],
132 'receivertype': [
133 (words(type_modifiers, suffix=r'\b'), Keyword),
134 (words(known_types, suffix=r'\b'), Keyword.Type),
135 (r'[^()]*', Name.Other, '#pop'),
136 ],
137 'attributename': [
138 (r'[a-zA-Z_][.\w$]*', Name.Decorator, '#pop'),
139 ],
140 }