eric6/ThirdParty/Pygments/pygments/lexers/resource.py

changeset 6942
2602857055c5
parent 5713
6762afd9f963
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.resource
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexer for resource definition files.
7
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 import re
13
14 from pygments.lexer import RegexLexer, bygroups, words
15 from pygments.token import Comment, String, Number, Operator, Text, \
16 Keyword, Name
17
18 __all__ = ['ResourceLexer']
19
20
21 class ResourceLexer(RegexLexer):
22 """Lexer for `ICU Resource bundles
23 <http://userguide.icu-project.org/locale/resources>`_.
24
25 .. versionadded:: 2.0
26 """
27 name = 'ResourceBundle'
28 aliases = ['resource', 'resourcebundle']
29 filenames = ['*.txt']
30
31 _types = (':table', ':array', ':string', ':bin', ':import', ':intvector',
32 ':int', ':alias')
33
34 flags = re.MULTILINE | re.IGNORECASE
35 tokens = {
36 'root': [
37 (r'//.*?$', Comment),
38 (r'"', String, 'string'),
39 (r'-?\d+', Number.Integer),
40 (r'[,{}]', Operator),
41 (r'([^\s{:]+)(\s*)(%s?)' % '|'.join(_types),
42 bygroups(Name, Text, Keyword)),
43 (r'\s+', Text),
44 (words(_types), Keyword),
45 ],
46 'string': [
47 (r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|'
48 r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String),
49 (r'\{', String.Escape, 'msgname'),
50 (r'"', String, '#pop')
51 ],
52 'msgname': [
53 (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message'))
54 ],
55 'message': [
56 (r'\{', String.Escape, 'msgname'),
57 (r'\}', String.Escape, '#pop'),
58 (r'(,)(\s*)([a-z]+)(\s*\})',
59 bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'),
60 (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)',
61 bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
62 String.Escape, Operator.Word, String.Escape, Operator,
63 String.Escape, Number.Integer, String.Escape), 'choice'),
64 (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)',
65 bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
66 String.Escape), 'choice'),
67 (r'\s+', String.Escape)
68 ],
69 'choice': [
70 (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)',
71 bygroups(Operator, Number.Integer, String.Escape), 'message'),
72 (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'),
73 (r'\}', String.Escape, ('#pop', '#pop')),
74 (r'\s+', String.Escape)
75 ],
76 'str': [
77 (r'\}', String.Escape, '#pop'),
78 (r'\{', String.Escape, 'msgname'),
79 (r'[^{}]+', String)
80 ]
81 }
82
83 def analyse_text(text):
84 if text.startswith('root:table'):
85 return 1.0

eric ide

mercurial