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

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

17 statements  

1""" 

2 pygments.lexers.resource 

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

4 

5 Lexer for resource definition files. 

6 

7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, bygroups, words 

14from pygments.token import Comment, String, Number, Operator, Text, \ 

15 Keyword, Name 

16 

17__all__ = ['ResourceLexer'] 

18 

19 

20class ResourceLexer(RegexLexer): 

21 """Lexer for ICU Resource bundles. 

22 """ 

23 name = 'ResourceBundle' 

24 aliases = ['resourcebundle', 'resource'] 

25 filenames = [] 

26 url = 'https://unicode-org.github.io/icu/userguide/locale/resources.html' 

27 version_added = '2.0' 

28 

29 _types = (':table', ':array', ':string', ':bin', ':import', ':intvector', 

30 ':int', ':alias') 

31 

32 flags = re.MULTILINE | re.IGNORECASE 

33 tokens = { 

34 'root': [ 

35 (r'//.*?$', Comment), 

36 (r'"', String, 'string'), 

37 (r'-?\d+', Number.Integer), 

38 (r'[,{}]', Operator), 

39 (r'([^\s{{:]+)(\s*)({}?)'.format('|'.join(_types)), 

40 bygroups(Name, Text, Keyword)), 

41 (r'\s+', Text), 

42 (words(_types), Keyword), 

43 ], 

44 'string': [ 

45 (r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|' 

46 r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String), 

47 (r'\{', String.Escape, 'msgname'), 

48 (r'"', String, '#pop') 

49 ], 

50 'msgname': [ 

51 (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message')) 

52 ], 

53 'message': [ 

54 (r'\{', String.Escape, 'msgname'), 

55 (r'\}', String.Escape, '#pop'), 

56 (r'(,)(\s*)([a-z]+)(\s*\})', 

57 bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'), 

58 (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)', 

59 bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, 

60 String.Escape, Operator.Word, String.Escape, Operator, 

61 String.Escape, Number.Integer, String.Escape), 'choice'), 

62 (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)', 

63 bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, 

64 String.Escape), 'choice'), 

65 (r'\s+', String.Escape) 

66 ], 

67 'choice': [ 

68 (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)', 

69 bygroups(Operator, Number.Integer, String.Escape), 'message'), 

70 (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'), 

71 (r'\}', String.Escape, ('#pop', '#pop')), 

72 (r'\s+', String.Escape) 

73 ], 

74 'str': [ 

75 (r'\}', String.Escape, '#pop'), 

76 (r'\{', String.Escape, 'msgname'), 

77 (r'[^{}]+', String) 

78 ] 

79 } 

80 

81 def analyse_text(text): 

82 if text.startswith('root:table'): 

83 return 1.0