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

changeset 8258
82b608e352ec
parent 8257
28146736bbfc
child 8259
2bbec88047dd
equal deleted inserted replaced
8257:28146736bbfc 8258:82b608e352ec
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.solidity
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for Solidity.
7
8 :copyright: Copyright 2006-2021 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, Whitespace
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, Whitespace, Name.Entity)),
48 (datatype + r'(\s+)((?:external|public|internal|private)\s+)?' +
49 r'([a-zA-Z_]\w*)',
50 bygroups(Keyword.Type, Whitespace, Keyword, Name.Variable)),
51 (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)',
52 bygroups(Keyword.Type, Whitespace, Name.Variable)),
53 (r'\b(msg|block|tx)\.([A-Za-z_][a-zA-Z0-9_]*)\b', Keyword),
54 (words((
55 'block', 'break', 'constant', 'constructor', 'continue',
56 'contract', 'do', 'else', 'external', 'false', 'for',
57 'function', 'if', 'import', 'inherited', 'internal', 'is',
58 'library', 'mapping', 'memory', 'modifier', 'msg', 'new',
59 'payable', 'private', 'public', 'require', 'return',
60 'returns', 'struct', 'suicide', 'throw', 'this', 'true',
61 'tx', 'var', 'while'), prefix=r'\b', suffix=r'\b'),
62 Keyword.Type),
63 (words(('keccak256',), prefix=r'\b', suffix=r'\b'), Name.Builtin),
64 (datatype, Keyword.Type),
65 include('constants'),
66 (r'[a-zA-Z_]\w*', Text),
67 (r'[!<=>+*/-]', Operator),
68 (r'[.;:{}(),\[\]]', Punctuation)
69 ],
70 'comments': [
71 (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),
72 (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),
73 (r'/(\\\n)?[*][\w\W]*', Comment.Multiline)
74 ],
75 'constants': [
76 (r'("(\\"|.)*?")', String.Double),
77 (r"('(\\'|.)*?')", String.Single),
78 (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex),
79 (r'\b\d+\b', Number.Decimal),
80 ],
81 'pragma': [
82 include('whitespace'),
83 include('comments'),
84 (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)',
85 bygroups(Operator, Whitespace, Keyword)),
86 (r';', Punctuation, '#pop')
87 ],
88 'whitespace': [
89 (r'\s+', Whitespace),
90 (r'\n', Whitespace)
91 ]
92 }

eric ide

mercurial