Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/sophia.py: 100%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.sophia
3 ~~~~~~~~~~~~~~~~~~~~~~
5 Lexer for Sophia.
7 Derived from pygments/lexers/reason.py.
9 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details.
11"""
13from pygments.lexer import RegexLexer, include, default, words
14from pygments.token import Comment, Keyword, Name, Number, Operator, \
15 Punctuation, String, Text
17__all__ = ['SophiaLexer']
19class SophiaLexer(RegexLexer):
20 """
21 A Sophia lexer.
23 .. versionadded:: 2.11
24 """
26 name = 'Sophia'
27 aliases = ['sophia']
28 filenames = ['*.aes']
29 mimetypes = []
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 )
38 builtins = ('state', 'put', 'abort', 'require')
40 word_operators = ('mod', 'band', 'bor', 'bxor', 'bnot')
42 primitive_types = ('int', 'address', 'bool', 'bits', 'bytes', 'string',
43 'list', 'option', 'char', 'unit', 'map', 'event',
44 'hash', 'signature', 'oracle', 'oracle_query')
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'),
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),
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),
69 (r'[=!<>+\\*/:&|?~@^-]', Operator.Word),
70 (r'[.;:{}(),\[\]]', Punctuation),
72 (r"(ak_|ok_|oq_|ct_)[\w']*", Name.Label),
73 (r"[^\W\d][\w']*", Name),
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),
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 }