|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.parasail |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for ParaSail. |
|
7 |
|
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation, Literal |
|
17 |
|
18 __all__ = ['ParaSailLexer'] |
|
19 |
|
20 |
|
21 class ParaSailLexer(RegexLexer): |
|
22 """ |
|
23 For `ParaSail <http://www.parasail-lang.org>`_ source code. |
|
24 |
|
25 .. versionadded:: 2.1 |
|
26 """ |
|
27 |
|
28 name = 'ParaSail' |
|
29 aliases = ['parasail'] |
|
30 filenames = ['*.psi', '*.psl'] |
|
31 mimetypes = ['text/x-parasail'] |
|
32 |
|
33 flags = re.MULTILINE |
|
34 |
|
35 tokens = { |
|
36 'root': [ |
|
37 (r'[^\S\n]+', Text), |
|
38 (r'//.*?\n', Comment.Single), |
|
39 (r'\b(and|or|xor)=', Operator.Word), |
|
40 (r'\b(and(\s+then)?|or(\s+else)?|xor|rem|mod|' |
|
41 r'(is|not)\s+null)\b', |
|
42 Operator.Word), |
|
43 # Keywords |
|
44 (r'\b(abs|abstract|all|block|class|concurrent|const|continue|' |
|
45 r'each|end|exit|extends|exports|forward|func|global|implements|' |
|
46 r'import|in|interface|is|lambda|locked|new|not|null|of|op|' |
|
47 r'optional|private|queued|ref|return|reverse|separate|some|' |
|
48 r'type|until|var|with|' |
|
49 # Control flow |
|
50 r'if|then|else|elsif|case|for|while|loop)\b', |
|
51 Keyword.Reserved), |
|
52 (r'(abstract\s+)?(interface|class|op|func|type)', |
|
53 Keyword.Declaration), |
|
54 # Literals |
|
55 (r'"[^"]*"', String), |
|
56 (r'\\[\'ntrf"0]', String.Escape), |
|
57 (r'#[a-zA-Z]\w*', Literal), # Enumeration |
|
58 include('numbers'), |
|
59 (r"'[^']'", String.Char), |
|
60 (r'[a-zA-Z]\w*', Name), |
|
61 # Operators and Punctuation |
|
62 (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|' |
|
63 r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\|=|\||/=|\+|-|\*|/|' |
|
64 r'\.\.|<\.\.|\.\.<|<\.\.<)', |
|
65 Operator), |
|
66 (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)', |
|
67 Punctuation), |
|
68 (r'\n+', Text), |
|
69 ], |
|
70 'numbers': [ |
|
71 (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex), # any base |
|
72 (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex), # C-like hex |
|
73 (r'0[bB][01][01_]*', Number.Bin), # C-like bin |
|
74 (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*', # float exp |
|
75 Number.Float), |
|
76 (r'\d[0-9_]*\.\d[0-9_]*', Number.Float), # float |
|
77 (r'\d[0-9_]*', Number.Integer), # integer |
|
78 ], |
|
79 } |