rql/pygments_ext.py
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 28 May 2015 01:13:28 +0200
changeset 761 d9762b5a4604
parent 725 pygments_ext.py@0c8840b3be04
child 826 c993c0593d6c
permissions -rw-r--r--
[pkg] Use setuptools Move sources to a 'rql' subdirectory, drop the NO_SETUPTOOLS code path (essentially rewriting all of setup.py). This avoids a conflict between our parser.py and the stdlib when running setup.py. Closes #278637.

# -*- 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',))