Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
solidity.py88 linesDownload Raw Back to lexers
1"""2    pygments.lexers.solidity3    ~~~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for Solidity.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups, include, words12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \13    Number, Punctuation, Whitespace14 15__all__ = ['SolidityLexer']16 17 18class SolidityLexer(RegexLexer):19    """20    For Solidity source code.21    """22 23    name = 'Solidity'24    aliases = ['solidity']25    filenames = ['*.sol']26    mimetypes = []27    url = 'https://soliditylang.org'28    version_added = '2.5'29 30    datatype = (31        r'\b(address|bool|(?:(?:bytes|hash|int|string|uint)(?:8|16|24|32|40|48|56|64'32        r'|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208'33        r'|216|224|232|240|248|256)?))\b'34    )35 36    tokens = {37        'root': [38            include('whitespace'),39            include('comments'),40            (r'\bpragma\s+solidity\b', Keyword, 'pragma'),41            (r'\b(contract)(\s+)([a-zA-Z_]\w*)',42             bygroups(Keyword, Whitespace, Name.Entity)),43            (datatype + r'(\s+)((?:external|public|internal|private)\s+)?' +44             r'([a-zA-Z_]\w*)',45             bygroups(Keyword.Type, Whitespace, Keyword, Name.Variable)),46            (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)',47             bygroups(Keyword.Type, Whitespace, Name.Variable)),48            (r'\b(msg|block|tx)\.([A-Za-z_][a-zA-Z0-9_]*)\b', Keyword),49            (words((50                'block', 'break', 'constant', 'constructor', 'continue',51                'contract', 'do', 'else', 'external', 'false', 'for',52                'function', 'if', 'import', 'inherited', 'internal', 'is',53                'library', 'mapping', 'memory', 'modifier', 'msg', 'new',54                'payable', 'private', 'public', 'require', 'return',55                'returns', 'struct', 'suicide', 'throw', 'this', 'true',56                'tx', 'var', 'while'), prefix=r'\b', suffix=r'\b'),57             Keyword.Type),58            (words(('keccak256',), prefix=r'\b', suffix=r'\b'), Name.Builtin),59            (datatype, Keyword.Type),60            include('constants'),61            (r'[a-zA-Z_]\w*', Text),62            (r'[~!%^&*+=|?:<>/-]', Operator),63            (r'[.;{}(),\[\]]', Punctuation)64        ],65        'comments': [66            (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),67            (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),68            (r'/(\\\n)?[*][\w\W]*', Comment.Multiline)69        ],70        'constants': [71            (r'("(\\"|.)*?")', String.Double),72            (r"('(\\'|.)*?')", String.Single),73            (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex),74            (r'\b\d+\b', Number.Decimal),75        ],76        'pragma': [77            include('whitespace'),78            include('comments'),79            (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)',80             bygroups(Operator, Whitespace, Keyword)),81            (r';', Punctuation, '#pop')82        ],83        'whitespace': [84            (r'\s+', Whitespace),85            (r'\n', Whitespace)86        ]87    }88 
codekingpro/portable-devtools · Team Ai