# HG changeset patch
# User Nicolas Chauvat <nicolas.chauvat@logilab.fr>
# Date 1387204316 -3600
#      Mon Dec 16 15:31:56 2013 +0100
# Node ID 0c8840b3be045db84fc57edb7122e954afe7b321
# Parent  3d5a9d57cf951e7cb3fb537190e5b57ea1f86fe0
add pygments lexer to colorize query strings (closes #34252)

diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -22,6 +22,7 @@
          python-logilab-database (>= 1.6.0)
 Conflicts: cubicweb-common (<= 3.13.9)
 Provides: ${python:Provides}
+Suggests: python-pygments
 Description: relationship query language (RQL) utilities
  A library providing the base utilities to handle RQL queries,
  such as a parser, a type inferencer.
diff --git a/pygments_ext.py b/pygments_ext.py
new file mode 100644
--- /dev/null
+++ b/pygments_ext.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+"""
+    pygments.lexers.rql
+    ~~~~~~~~~~~~~~~~~~~
+
+    Lexer for RQL the relation query language
+
+    http://www.logilab.org/project/rql
+"""
+
+import re
+
+from pygments.lexer import RegexLexer, _mapping
+from pygments.token import Punctuation, \
+     Text, Comment, Operator, Keyword, Name, String, Number
+
+__all__ = ['RqlLexer']
+
+class RqlLexer(RegexLexer):
+    """
+    Lexer for Relation Query Language.
+    """
+
+    name = 'RQL'
+    aliases = ['rql']
+    filenames = ['*.rql']
+    mimetypes = ['text/x-rql']
+
+    flags = re.IGNORECASE
+    tokens = {
+        'root': [
+            (r'\s+', Text),
+            (r'(DELETE|SET|INSERT|UNION|DISTINCT|WITH|WHERE|BEING|OR'
+             r'|AND|NOT|GROUPBY|HAVING|ORDERBY|ASC|DESC|LIMIT|OFFSET'
+             r'|TODAY|NOW|TRUE|FALSE|NULL|EXISTS)\b', Keyword),
+            (r'[+*/<>=%-]', Operator),
+            (r'(Any|is|instance_of)\b', Name.Builtin),
+            (r'[0-9]+', Number.Integer),
+            (r'[A-Z_][A-Z0-9_]*\??', Name),
+            (r"'(''|[^'])*'", String.Single),
+            (r'"(""|[^"])*"', String.Single),
+            (r'[;:()\[\],\.]', Punctuation)
+        ],
+    }
+
+_mapping.LEXERS['RqlLexer'] = ('rql.pygments_ext', 'RQL', ('rql',), ('*.rql',), ('text/x-rql',))
+