1""" 
    2    pygments.lexers.berry 
    3    ~~~~~~~~~~~~~~~~~~~~~ 
    4 
    5    Lexer for Berry. 
    6 
    7    :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. 
    8    :license: BSD, see LICENSE for details. 
    9""" 
    10 
    11from pygments.lexer import RegexLexer, words, include, bygroups 
    12from pygments.token import Comment, Whitespace, Operator, Keyword, Name, \ 
    13    String, Number, Punctuation 
    14 
    15__all__ = ['BerryLexer'] 
    16 
    17 
    18class BerryLexer(RegexLexer): 
    19    """ 
    20    For Berry source code. 
    21    """ 
    22    name = 'Berry' 
    23    aliases = ['berry', 'be'] 
    24    filenames = ['*.be'] 
    25    mimetypes = ['text/x-berry', 'application/x-berry'] 
    26    url = 'https://berry-lang.github.io' 
    27    version_added = '2.12' 
    28 
    29    _name = r'\b[^\W\d]\w*' 
    30 
    31    tokens = { 
    32        'root': [ 
    33            include('whitespace'), 
    34            include('numbers'), 
    35            include('keywords'), 
    36            (rf'(def)(\s+)({_name})', 
    37             bygroups(Keyword.Declaration, Whitespace, Name.Function)), 
    38            (rf'\b(class)(\s+)({_name})', 
    39             bygroups(Keyword.Declaration, Whitespace, Name.Class)), 
    40            (rf'\b(import)(\s+)({_name})', 
    41             bygroups(Keyword.Namespace, Whitespace, Name.Namespace)), 
    42            include('expr') 
    43        ], 
    44        'expr': [ 
    45            (r'[^\S\n]+', Whitespace), 
    46            (r'\.\.|[~!%^&*+=|?:<>/-]', Operator), 
    47            (r'[(){}\[\],.;]', Punctuation), 
    48            include('controls'), 
    49            include('builtins'), 
    50            include('funccall'), 
    51            include('member'), 
    52            include('name'), 
    53            include('strings') 
    54        ], 
    55        'whitespace': [ 
    56            (r'\s+', Whitespace), 
    57            (r'#-(.|\n)*?-#', Comment.Multiline), 
    58            (r'#.*?$', Comment.Single) 
    59        ], 
    60        'keywords': [ 
    61            (words(( 
    62                'as', 'break', 'continue', 'import', 'static', 'self', 'super'), 
    63                suffix=r'\b'), Keyword.Reserved), 
    64            (r'(true|false|nil)\b', Keyword.Constant), 
    65            (r'(var|def)\b', Keyword.Declaration) 
    66        ], 
    67        'controls': [ 
    68            (words(( 
    69                'if', 'elif', 'else', 'for', 'while', 'do', 'end', 'break', 
    70                'continue', 'return', 'try', 'except', 'raise'), 
    71                suffix=r'\b'), Keyword) 
    72        ], 
    73        'builtins': [ 
    74            (words(( 
    75                'assert', 'bool', 'input', 'classname', 'classof', 'number', 'real', 
    76                'bytes', 'compile', 'map', 'list', 'int', 'isinstance', 'print', 
    77                'range', 'str', 'super', 'module', 'size', 'issubclass', 'open', 
    78                'file', 'type', 'call'), 
    79                suffix=r'\b'), Name.Builtin) 
    80        ], 
    81        'numbers': [ 
    82            (r'0[xX][a-fA-F0-9]+', Number.Hex), 
    83            (r'-?\d+', Number.Integer), 
    84            (r'(-?\d+\.?|\.\d)\d*([eE][+-]?\d+)?', Number.Float) 
    85        ], 
    86        'name': [ 
    87            (_name, Name) 
    88        ], 
    89        'funccall': [ 
    90            (rf'{_name}(?=\s*\()', Name.Function, '#pop') 
    91        ], 
    92        'member': [ 
    93            (rf'(?<=\.){_name}\b(?!\()', Name.Attribute, '#pop') 
    94        ], 
    95        'strings': [ 
    96            (r'"([^\\]|\\.)*?"', String.Double, '#pop'), 
    97            (r'\'([^\\]|\\.)*?\'', String.Single, '#pop') 
    98        ] 
    99    }