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