diff options
author | Tim Hatch <tim@timhatch.com> | 2014-10-14 22:53:47 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2014-10-14 22:53:47 -0700 |
commit | 70fab11ec76811924a8d7784d9a7c87475767830 (patch) | |
tree | 8c0dca3bbab1eebaccf3798677fb3ff12d58b15f /pygments/lexers/resource.py | |
parent | a0f10d431548f956346a35a6facf8a9d2b75b1cb (diff) | |
download | pygments-70fab11ec76811924a8d7784d9a7c87475767830.tar.gz |
Add ResourceBundle lexer.
Fixes #1038
Diffstat (limited to 'pygments/lexers/resource.py')
-rw-r--r-- | pygments/lexers/resource.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pygments/lexers/resource.py b/pygments/lexers/resource.py new file mode 100644 index 00000000..7eabe51c --- /dev/null +++ b/pygments/lexers/resource.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.resource + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexer for resource definition files. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, bygroups, words +from pygments.token import Comment, String, Number, Operator, Text, Keyword, \ + Name, String + +__all__ = ['ResourceLexer'] + + +class ResourceLexer(RegexLexer): + name = 'ResourceBundle' + aliases = ['resource', 'resourcebundle', 'rb'] + filenames = ['*.txt'] + + _types = (':table', ':array', ':string', ':bin', ':import', ':intvector', + ':int', ':alias') + + flags = re.MULTILINE | re.IGNORECASE + tokens = { + 'root': [ + (r'//.*?$', Comment), + (r'"', String, 'string'), + (r'-?\d+', Number.Integer), + (r'[,{}]', Operator), + (r'([^\s{:]+)(\s*)(%s?)' % '|'.join(_types), + bygroups(Name, Text, Keyword)), + (r'\s+', Text), + (words(_types), Keyword), + ], + 'string': [ + (r'(\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\U00[0-9a-fA-F]{6}|' + r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\{|[^"{\\])+', String), + (r'{', String.Escape, 'msgname'), + (r'"', String, '#pop') + ], + 'msgname': [ + (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message')) + ], + 'message': [ + (r'{', String.Escape, 'msgname'), + (r'}', String.Escape, '#pop'), + (r'(,)(\s*)([a-zA-Z]+)(\s*})', + bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'), + (r'(,)(\s*)([a-zA-Z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)', + bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, + String.Escape, Operator.Word, String.Escape, Operator, + String.Escape, Number.Integer, String.Escape), 'choice'), + (r'(,)(\s*)([a-zA-Z]+)(\s*)(,)(\s*)', + bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, + String.Escape), 'choice'), + (r'\s+', String.Escape) + ], + 'choice': [ + (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*{)', + bygroups(Operator, Number.Integer, String.Escape), 'message'), + (r'([a-zA-Z]+)(\s*{)', bygroups(Keyword.Type, String.Escape), 'str'), + (r'}', String.Escape, ('#pop', '#pop')), + (r'\s+', String.Escape) + ], + 'str': [ + (r'}', String.Escape, '#pop'), + (r'{', String.Escape, 'msgname'), + (r'[^{}]+', String) + ] + } + + def analyse_text(text): + return text.startswith('root:table') |