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

9 statements  

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

1""" 

2 pygments.lexers.rnc 

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

4 

5 Lexer for Relax-NG Compact syntax 

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 

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 .. versionadded:: 2.2 

23 """ 

24 

25 name = 'Relax-NG Compact' 

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

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

28 filenames = ['*.rnc'] 

29 

30 tokens = { 

31 'root': [ 

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

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

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

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

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

37 # TODO single quoted strings and escape sequences outside of 

38 # double-quoted strings 

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

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

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

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

43 (r'.', Text), 

44 ], 

45 

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

47 'variable': [ 

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

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

50 ], 

51 

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

53 'maybe_xsdattributes': [ 

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

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

56 (r'.', Text), 

57 ], 

58 

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

60 'xsdattributes': [ 

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

62 (r'=', Operator), 

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

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

65 (r'.', Text), 

66 ], 

67 }