Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/graphviz.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.graphviz 

3 ~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for the DOT language (graphviz). 

6 

7 :copyright: Copyright 2006-2023 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 .. versionadded:: 2.8 

24 """ 

25 name = 'Graphviz' 

26 url = 'https://www.graphviz.org/doc/info/lang.html' 

27 aliases = ['graphviz', 'dot'] 

28 filenames = ['*.gv', '*.dot'] 

29 mimetypes = ['text/x-graphviz', 'text/vnd.graphviz'] 

30 tokens = { 

31 'root': [ 

32 (r'\s+', Whitespace), 

33 (r'(#|//).*?$', Comment.Single), 

34 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 

35 (r'(?i)(node|edge|graph|digraph|subgraph|strict)\b', Keyword), 

36 (r'--|->', Operator), 

37 (r'[{}[\]:;,]', Punctuation), 

38 (r'(\b\D\w*)(\s*)(=)(\s*)', 

39 bygroups(Name.Attribute, Whitespace, Punctuation, Whitespace), 

40 'attr_id'), 

41 (r'\b(n|ne|e|se|s|sw|w|nw|c|_)\b', Name.Builtin), 

42 (r'\b\D\w*', Name.Tag), # node 

43 (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number), 

44 (r'"(\\"|[^"])*?"', Name.Tag), # quoted node 

45 (r'<', Punctuation, 'xml'), 

46 ], 

47 'attr_id': [ 

48 (r'\b\D\w*', String, '#pop'), 

49 (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number, '#pop'), 

50 (r'"(\\"|[^"])*?"', String.Double, '#pop'), 

51 (r'<', Punctuation, ('#pop', 'xml')), 

52 ], 

53 'xml': [ 

54 (r'<', Punctuation, '#push'), 

55 (r'>', Punctuation, '#pop'), 

56 (r'\s+', Whitespace), 

57 (r'[^<>\s]', Name.Tag), 

58 ] 

59 }