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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1""" 

2 pygments.lexers.rnc 

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

4 

5 Lexer for Relax-NG Compact syntax 

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 

12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

13 Punctuation 

14 

15__all__ = ['RNCCompactLexer'] 

16 

17 

18class RNCCompactLexer(RegexLexer): 

19 """ 

20 For RelaxNG-compact syntax. 

21 """ 

22 

23 name = 'Relax-NG Compact' 

24 url = 'http://relaxng.org' 

25 aliases = ['rng-compact', 'rnc'] 

26 filenames = ['*.rnc'] 

27 version_added = '2.2' 

28 

29 tokens = { 

30 'root': [ 

31 (r'namespace\b', Keyword.Namespace), 

32 (r'(?:default|datatypes)\b', Keyword.Declaration), 

33 (r'##.*$', Comment.Preproc), 

34 (r'#.*$', Comment.Single), 

35 (r'"[^"]*"', String.Double), 

36 # TODO single quoted strings and escape sequences outside of 

37 # double-quoted strings 

38 (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'), 

39 (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'), 

40 (r'[,?&*=|~]|>>', Operator), 

41 (r'[(){}]', Punctuation), 

42 (r'.', Text), 

43 ], 

44 

45 # a variable has been declared using `element` or `attribute` 

46 'variable': [ 

47 (r'[^{]+', Name.Variable), 

48 (r'\{', Punctuation, '#pop'), 

49 ], 

50 

51 # after an xsd:<datatype> declaration there may be attributes 

52 'maybe_xsdattributes': [ 

53 (r'\{', Punctuation, 'xsdattributes'), 

54 (r'\}', Punctuation, '#pop'), 

55 (r'.', Text), 

56 ], 

57 

58 # attributes take the form { key1 = value1 key2 = value2 ... } 

59 'xsdattributes': [ 

60 (r'[^ =}]', Name.Attribute), 

61 (r'=', Operator), 

62 (r'"[^"]*"', String.Double), 

63 (r'\}', Punctuation, '#pop'), 

64 (r'.', Text), 

65 ], 

66 }