1""" 
    2    pygments.lexers.graphviz 
    3    ~~~~~~~~~~~~~~~~~~~~~~~~ 
    4 
    5    Lexer for the DOT language (graphviz). 
    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, bygroups 
    12from pygments.token import Comment, Keyword, Operator, Name, String, Number, \ 
    13    Punctuation, Whitespace 
    14 
    15 
    16__all__ = ['GraphvizLexer'] 
    17 
    18 
    19class GraphvizLexer(RegexLexer): 
    20    """ 
    21    For graphviz DOT graph description language. 
    22    """ 
    23    name = 'Graphviz' 
    24    url = 'https://www.graphviz.org/doc/info/lang.html' 
    25    aliases = ['graphviz', 'dot'] 
    26    filenames = ['*.gv', '*.dot'] 
    27    mimetypes = ['text/x-graphviz', 'text/vnd.graphviz'] 
    28    version_added = '2.8' 
    29    tokens = { 
    30        'root': [ 
    31            (r'\s+', Whitespace), 
    32            (r'(#|//).*?$', Comment.Single), 
    33            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 
    34            (r'(?i)(node|edge|graph|digraph|subgraph|strict)\b', Keyword), 
    35            (r'--|->', Operator), 
    36            (r'[{}[\]:;,]', Punctuation), 
    37            (r'(\b\D\w*)(\s*)(=)(\s*)', 
    38                bygroups(Name.Attribute, Whitespace, Punctuation, Whitespace), 
    39                'attr_id'), 
    40            (r'\b(n|ne|e|se|s|sw|w|nw|c|_)\b', Name.Builtin), 
    41            (r'\b\D\w*', Name.Tag),  # node 
    42            (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number), 
    43            (r'"(\\"|[^"])*?"', Name.Tag),  # quoted node 
    44            (r'<', Punctuation, 'xml'), 
    45        ], 
    46        'attr_id': [ 
    47            (r'\b\D\w*', String, '#pop'), 
    48            (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number, '#pop'), 
    49            (r'"(\\"|[^"])*?"', String.Double, '#pop'), 
    50            (r'<', Punctuation, ('#pop', 'xml')), 
    51        ], 
    52        'xml': [ 
    53            (r'<', Punctuation, '#push'), 
    54            (r'>', Punctuation, '#pop'), 
    55            (r'\s+', Whitespace), 
    56            (r'[^<>\s]', Name.Tag), 
    57        ] 
    58    }