""" pygments.lexers.tact ~~~~~~~~~~~~~~~~~~~~ Lexers for Tact. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ from pygments.lexer import RegexLexer, include, bygroups, words from pygments.token import Comment, Operator, Keyword, Name, String, \ Number, Whitespace, Punctuation __all__ = ['TactLexer'] class TactLexer(RegexLexer): """For Tact source code.""" name = 'Tact' aliases = ['tact'] filenames = ['*.tact'] url = "https://tact-lang.org" version_added = '2.18' tokens = { 'root': [ (r'\s+', Whitespace), (r'[.;(),\[\]{}]', Punctuation), (r'\?|!!', Operator), include('comments'), include('import-in'), include('struct-in'), include('contract-or-trait-in'), include('annotation-in'), include('fun-declaration-in'), include('const-declaration-in'), include('statements'), ], 'import-in': [ (r'((?<=\.\.\.)|(?', Punctuation, '#pop'), include('comments'), include('type-as-in'), (r'\b\w+', Keyword.Type), (r'\s+', Whitespace), (r',', Punctuation), ], 'type-as-in': [ (r'\b(as)(\s+)', bygroups(Keyword, Whitespace), 'type-as'), ], 'type-as': [ (r'(?=\{|\;|\=|\,|\)|\>)', Punctuation, '#pop'), include('comments'), (r'\b\w+', Keyword.Type), (r'\s+', Whitespace), ], 'keywords': [ (words(('if', 'else', 'while', 'do', 'until', 'repeat', 'return', 'extends', 'mutates', 'virtual', 'override', 'inline', 'native', 'let', 'const', 'fun', 'self', 'is', 'initOf', 'map', 'bounced', 'get', 'as'), prefix=r'\b', suffix=r'\b'), Keyword), (r'(<=>|>=|<=|!=|==|\^>>|~>>|>>|<<|\/%|\^%|~%|\^\/|~\/|\+=|-=|\*=|\/=|~\/=|\^\/=|%=|\^%=|<<=|>>=|~>>=|\^>>=|&=|\|=|\^=|\^|=|~|\/|%|-|\*|\+|>|<|&|\||:|\?)', Operator), (words(('true', 'false'), prefix=r'\b', suffix=r'\b'), Keyword.Constant), ], 'string-in': [ (r'"', String, 'string'), ], 'string': [ (r'"', String, '#pop'), (r'\\.', String.Escape), (r'[^\\"]+', String.Double), ], 'numeric': [ (r'(?:\b0[xX])[0-9a-fA-F][0-9a-fA-F_]*\b', Number.Hex), (r'(?:\b[0-9]+\b)', Number.Integer), ], 'comments': [ (r'//.*', Comment.Single), (r'/\*', Comment.Multiline, 'comments-multiline'), ], 'comments-multiline': [ (r'\*/', Comment.Multiline, '#pop'), (r'[^*]+', Comment.Multiline), (r'[*]', Comment.Multiline), ], 'variable': [ (r'\b\w+\b(?!\s*\()(?!\s*\{)', Name.Variable) ], 'function-call': [ (r'\b\w+\b(?=\s*\()(?!\s*\{)', Name.Function) ], }