eric6/ThirdParty/Pygments/pygments/lexers/solidity.py

changeset 7547
21b0534faebc
child 7701
25f42e208e08
equal deleted inserted replaced
7546:bf5f777260a6 7547:21b0534faebc
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.solidity
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for Solidity.
7
8 :copyright: Copyright 2006-2019 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, bygroups, include, words
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation
17
18 __all__ = ['SolidityLexer']
19
20
21 class SolidityLexer(RegexLexer):
22 """
23 For Solidity source code.
24
25 .. versionadded:: 2.5
26 """
27
28 name = 'Solidity'
29 aliases = ['solidity']
30 filenames = ['*.sol']
31 mimetypes = []
32
33 flags = re.MULTILINE | re.UNICODE
34
35 datatype = (
36 r'\b(address|bool|((bytes|hash|int|string|uint)(8|16|24|32|40|48|56|64'
37 r'|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208'
38 r'|216|224|232|240|248|256)?))\b'
39 )
40
41 tokens = {
42 'root': [
43 include('whitespace'),
44 include('comments'),
45 (r'\bpragma\s+solidity\b', Keyword, 'pragma'),
46 (r'\b(contract)(\s+)([a-zA-Z_]\w*)',
47 bygroups(Keyword, Text.WhiteSpace, Name.Entity)),
48 (datatype + r'(\s+)((external|public|internal|private)\s+)?' +
49 r'([a-zA-Z_]\w*)',
50 bygroups(Keyword.Type, None, None, None, Text.WhiteSpace, Keyword,
51 None, Name.Variable)),
52 (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)',
53 bygroups(Keyword.Type, Text.WhiteSpace, Name.Variable)),
54 (r'\b(msg|block|tx)\.([A-Za-z_][A-Za-z0-9_]*)\b', Keyword),
55 (words((
56 'block', 'break', 'constant', 'constructor', 'continue',
57 'contract', 'do', 'else', 'external', 'false', 'for',
58 'function', 'if', 'import', 'inherited', 'internal', 'is',
59 'library', 'mapping', 'memory', 'modifier', 'msg', 'new',
60 'payable', 'private', 'public', 'require', 'return',
61 'returns', 'struct', 'suicide', 'throw', 'this', 'true',
62 'tx', 'var', 'while'), prefix=r'\b', suffix=r'\b'),
63 Keyword.Type),
64 (words(('keccak256',), prefix=r'\b', suffix=r'\b'), Name.Builtin),
65 (datatype, Keyword.Type),
66 include('constants'),
67 (r'[a-zA-Z_]\w*', Text),
68 (r'[!<=>+*/-]', Operator),
69 (r'[.;:{}(),\[\]]', Punctuation)
70 ],
71 'comments': [
72 (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),
73 (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),
74 (r'/(\\\n)?[*][\w\W]*', Comment.Multiline)
75 ],
76 'constants': [
77 (r'("([\\]"|.)*?")', String.Double),
78 (r"('([\\]'|.)*?')", String.Single),
79 (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex),
80 (r'\b\d+\b', Number.Decimal),
81 ],
82 'pragma': [
83 include('whitespace'),
84 include('comments'),
85 (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)',
86 bygroups(Operator, Text.WhiteSpace, Keyword)),
87 (r';', Punctuation, '#pop')
88 ],
89 'whitespace': [
90 (r'\s+', Text.WhiteSpace),
91 (r'\n', Text.WhiteSpace)
92 ]
93 }

eric ide

mercurial