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

changeset 7701
25f42e208e08
parent 7547
21b0534faebc
child 7983
54c5cfbb1e29
equal deleted inserted replaced
7700:a3cf077a8db3 7701:25f42e208e08
3 pygments.lexers.solidity 3 pygments.lexers.solidity
4 ~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for Solidity. 6 Lexers for Solidity.
7 7
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
14 from pygments.lexer import RegexLexer, bygroups, include, words 14 from pygments.lexer import RegexLexer, bygroups, include, words
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation 16 Number, Punctuation, Whitespace
17 17
18 __all__ = ['SolidityLexer'] 18 __all__ = ['SolidityLexer']
19 19
20 20
21 class SolidityLexer(RegexLexer): 21 class SolidityLexer(RegexLexer):
31 mimetypes = [] 31 mimetypes = []
32 32
33 flags = re.MULTILINE | re.UNICODE 33 flags = re.MULTILINE | re.UNICODE
34 34
35 datatype = ( 35 datatype = (
36 r'\b(address|bool|((bytes|hash|int|string|uint)(8|16|24|32|40|48|56|64' 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' 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' 38 r'|216|224|232|240|248|256)?))\b'
39 ) 39 )
40 40
41 tokens = { 41 tokens = {
42 'root': [ 42 'root': [
43 include('whitespace'), 43 include('whitespace'),
44 include('comments'), 44 include('comments'),
45 (r'\bpragma\s+solidity\b', Keyword, 'pragma'), 45 (r'\bpragma\s+solidity\b', Keyword, 'pragma'),
46 (r'\b(contract)(\s+)([a-zA-Z_]\w*)', 46 (r'\b(contract)(\s+)([a-zA-Z_]\w*)',
47 bygroups(Keyword, Text.WhiteSpace, Name.Entity)), 47 bygroups(Keyword, Whitespace, Name.Entity)),
48 (datatype + r'(\s+)((external|public|internal|private)\s+)?' + 48 (datatype + r'(\s+)((?:external|public|internal|private)\s+)?' +
49 r'([a-zA-Z_]\w*)', 49 r'([a-zA-Z_]\w*)',
50 bygroups(Keyword.Type, None, None, None, Text.WhiteSpace, Keyword, 50 bygroups(Keyword.Type, Whitespace, Keyword, Name.Variable)),
51 None, Name.Variable)),
52 (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)', 51 (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)',
53 bygroups(Keyword.Type, Text.WhiteSpace, Name.Variable)), 52 bygroups(Keyword.Type, Whitespace, Name.Variable)),
54 (r'\b(msg|block|tx)\.([A-Za-z_][A-Za-z0-9_]*)\b', Keyword), 53 (r'\b(msg|block|tx)\.([A-Za-z_][a-zA-Z0-9_]*)\b', Keyword),
55 (words(( 54 (words((
56 'block', 'break', 'constant', 'constructor', 'continue', 55 'block', 'break', 'constant', 'constructor', 'continue',
57 'contract', 'do', 'else', 'external', 'false', 'for', 56 'contract', 'do', 'else', 'external', 'false', 'for',
58 'function', 'if', 'import', 'inherited', 'internal', 'is', 57 'function', 'if', 'import', 'inherited', 'internal', 'is',
59 'library', 'mapping', 'memory', 'modifier', 'msg', 'new', 58 'library', 'mapping', 'memory', 'modifier', 'msg', 'new',
72 (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single), 71 (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),
73 (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline), 72 (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),
74 (r'/(\\\n)?[*][\w\W]*', Comment.Multiline) 73 (r'/(\\\n)?[*][\w\W]*', Comment.Multiline)
75 ], 74 ],
76 'constants': [ 75 'constants': [
77 (r'("([\\]"|.)*?")', String.Double), 76 (r'("(\\"|.)*?")', String.Double),
78 (r"('([\\]'|.)*?')", String.Single), 77 (r"('(\\'|.)*?')", String.Single),
79 (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex), 78 (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex),
80 (r'\b\d+\b', Number.Decimal), 79 (r'\b\d+\b', Number.Decimal),
81 ], 80 ],
82 'pragma': [ 81 'pragma': [
83 include('whitespace'), 82 include('whitespace'),
84 include('comments'), 83 include('comments'),
85 (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)', 84 (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)',
86 bygroups(Operator, Text.WhiteSpace, Keyword)), 85 bygroups(Operator, Whitespace, Keyword)),
87 (r';', Punctuation, '#pop') 86 (r';', Punctuation, '#pop')
88 ], 87 ],
89 'whitespace': [ 88 'whitespace': [
90 (r'\s+', Text.WhiteSpace), 89 (r'\s+', Whitespace),
91 (r'\n', Text.WhiteSpace) 90 (r'\n', Whitespace)
92 ] 91 ]
93 } 92 }

eric ide

mercurial