codekingpro/portable-devtools
114k
1"""2 pygments.lexers.sophia3 ~~~~~~~~~~~~~~~~~~~~~~4 5 Lexer for Sophia.6 7 Derived from pygments/lexers/reason.py.8 9 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.10 :license: BSD, see LICENSE for details.11"""12 13from pygments.lexer import RegexLexer, include, default, words14from pygments.token import Comment, Keyword, Name, Number, Operator, \15 Punctuation, String, Text16 17__all__ = ['SophiaLexer']18 19class SophiaLexer(RegexLexer):20 """21 A Sophia lexer.22 """23 24 name = 'Sophia'25 aliases = ['sophia']26 filenames = ['*.aes']27 mimetypes = []28 url = 'https://docs.aeternity.com/aesophia'29 version_added = '2.11'30 31 keywords = (32 'contract', 'include', 'let', 'switch', 'type', 'record', 'datatype',33 'if', 'elif', 'else', 'function', 'stateful', 'payable', 'public',34 'entrypoint', 'private', 'indexed', 'namespace', 'interface', 'main',35 'using', 'as', 'for', 'hiding',36 )37 38 builtins = ('state', 'put', 'abort', 'require')39 40 word_operators = ('mod', 'band', 'bor', 'bxor', 'bnot')41 42 primitive_types = ('int', 'address', 'bool', 'bits', 'bytes', 'string',43 'list', 'option', 'char', 'unit', 'map', 'event',44 'hash', 'signature', 'oracle', 'oracle_query')45 46 tokens = {47 'escape-sequence': [48 (r'\\[\\"\'ntbr]', String.Escape),49 (r'\\[0-9]{3}', String.Escape),50 (r'\\x[0-9a-fA-F]{2}', String.Escape),51 ],52 'root': [53 (r'\s+', Text.Whitespace),54 (r'(true|false)\b', Keyword.Constant),55 (r'\b([A-Z][\w\']*)(?=\s*\.)', Name.Class, 'dotted'),56 (r'\b([A-Z][\w\']*)', Name.Function),57 (r'//.*?\n', Comment.Single),58 (r'\/\*(?!/)', Comment.Multiline, 'comment'),59 60 (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),61 (r'#[\da-fA-F][\da-fA-F_]*', Name.Label),62 (r'\d[\d_]*', Number.Integer),63 64 (words(keywords, suffix=r'\b'), Keyword),65 (words(builtins, suffix=r'\b'), Name.Builtin),66 (words(word_operators, prefix=r'\b', suffix=r'\b'), Operator.Word),67 (words(primitive_types, prefix=r'\b', suffix=r'\b'), Keyword.Type),68 69 (r'[=!<>+\\*/:&|?~@^-]', Operator.Word),70 (r'[.;:{}(),\[\]]', Punctuation),71 72 (r"(ak_|ok_|oq_|ct_)[\w']*", Name.Label),73 (r"[^\W\d][\w']*", Name),74 75 (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",76 String.Char),77 (r"'.'", String.Char),78 (r"'[a-z][\w]*", Name.Variable),79 80 (r'"', String.Double, 'string')81 ],82 'comment': [83 (r'[^/*]+', Comment.Multiline),84 (r'\/\*', Comment.Multiline, '#push'),85 (r'\*\/', Comment.Multiline, '#pop'),86 (r'\*', Comment.Multiline),87 ],88 'string': [89 (r'[^\\"]+', String.Double),90 include('escape-sequence'),91 (r'\\\n', String.Double),92 (r'"', String.Double, '#pop'),93 ],94 'dotted': [95 (r'\s+', Text),96 (r'\.', Punctuation),97 (r'[A-Z][\w\']*(?=\s*\.)', Name.Function),98 (r'[A-Z][\w\']*', Name.Function, '#pop'),99 (r'[a-z_][\w\']*', Name, '#pop'),100 default('#pop'),101 ],102 }103 