Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
carbon.py96 linesDownload Raw Back to lexers
1"""2    pygments.lexers.carbon3    ~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for the Carbon programming language.6 7    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10import re11 12from pygments.lexer import RegexLexer, words13from pygments.token import Text, Comment, Operator, Keyword, Name, String, \14    Number, Punctuation, Whitespace15 16__all__ = ['CarbonLexer']17 18 19class CarbonLexer(RegexLexer):20    """21    For Carbon source.22    """23    name = 'Carbon'24    url = 'https://github.com/carbon-language/carbon-lang'25    filenames = ['*.carbon']26    aliases = ['carbon']27    mimetypes = ['text/x-carbon']28    version_added = '2.15'29 30    flags = re.MULTILINE | re.DOTALL31 32    tokens = {33        'root': [34            (r'\n', Whitespace),35            (r'\s+', Whitespace),36            (r'\\\n', Text),37            # comments38            (r'//(.*?)\n', Comment.Single),39            (r'/(\\\n)?[*].*?[*](\\\n)?/', Comment.Multiline),40            # Declaration41            (r'(package|import|api|namespace|library)\b', Keyword.Namespace),42            (r'(abstract|alias|fn|class|interface|let|var|virtual|external|'43             r'base|addr|extends|choice|constraint|impl)\b', Keyword.Declaration),44            # Keywords45            (words(('as', 'or', 'not', 'and', 'break', 'continue', 'case',46                    'default', 'if', 'else', 'destructor', 'for', 'forall',47                    'while', 'where', 'then', 'in', 'is', 'return', 'returned',48                    'friend', 'partial', 'private', 'protected', 'observe', 'Self',49                    'override', 'final', 'match', 'type', 'like'), suffix=r'\b'), Keyword),50            (r'(self)\b', Keyword.Pseudo),51            (r'(true|false)\b', Keyword.Constant),52            (r'(auto|bool|string|i8|i16|i32|i64|u8|u16|u32|u64|'53             r'f8|f16|f32|f64)\b', Keyword.Type),54            # numeric literals55            (r'[0-9]*[.][0-9]+', Number.Double),56            (r'0b[01]+', Number.Bin),57            (r'0o[0-7]+', Number.Oct),58            (r'0x[0-9a-fA-F]+', Number.Hex),59            (r'[0-9]+', Number.Integer),60            # string literal61            (r'"(\\.|[^"\\])*"', String),62            # char literal63            (r'\'(\\.|[^\'\\])\'', String.Char),64            # tokens65            (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||'66             r'\+\+|--|\%|\^|\~|==|!=|::|[.]{3}|->|=>|[+\-*/&]', Operator),67            (r'[|<>=!()\[\]{}.,;:\?]', Punctuation),68            # identifiers69            (r'[^\W\d]\w*', Name.Other),70        ]71    }72 73    def analyse_text(text):74        result = 075        if 'forall' in text:76            result += 0.177        if 'type' in text:78            result += 0.179        if 'Self' in text:80            result += 0.181        if 'observe' in text:82            result += 0.183        if 'package' in text:84            result += 0.185        if 'library' in text:86            result += 0.187        if 'choice' in text:88            result += 0.189        if 'addr' in text:90            result += 0.191        if 'constraint' in text:92            result += 0.193        if 'impl' in text:94            result += 0.195        return result96 
codekingpro/portable-devtools · Team Ai