Python pygments.lexer 模块,include() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用pygments.lexer.include()

项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def gen_elixir_sigil_rules():
        states = {}

        states['strings'] = [
            (r'(%[A-Ba-z])?"""(?:.|\n)*?"""', String.Doc),
            (r"'''(?:.|\n)*?'''", String.Doc),
            (r'"', String.Double, 'dqs'),
            (r"'.*'", String.Single),
            (r'(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b|'
             r'[^x0MC])|(\\[MC]-)+\w|[^\s\\])', String.Other)
        ]

        for lbrace, rbrace, name, in ('\\{', '\\}', 'cb'), \
                                     ('\\[', '\\]', 'sb'), \
                                     ('\\(', '\\)', 'pa'), \
                                     ('\\<', '\\>', 'lt'):

            states['strings'] += [
                (r'%[a-z]' + lbrace, String.Double, name + 'intp'),
                (r'%[A-Z]' + lbrace, String.Double, name + 'no-intp')
            ]

            states[name +'intp'] = [
                (r'' + rbrace + '[a-z]*', String.Double, "#pop"),
                include('enddoublestr')
            ]

            states[name +'no-intp'] = [
                (r'.*' + rbrace + '[a-z]*', String.Double , "#pop")
            ]

        return states
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def gen_elixir_sigil_rules():
        states = {}

        states['strings'] = [
            (r'(%[A-Ba-z])?"""(?:.|\n)*?"""', String.Doc),
            (r"'''(?:.|\n)*?'''", String.Doc),
            (r'"', String.Double, 'dqs'),
            (r"'.*'", String.Single),
            (r'(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b|'
             r'[^x0MC])|(\\[MC]-)+\w|[^\s\\])', String.Other)
        ]

        for lbrace, rbrace, name, in ('\\{', '\\}', 'cb'), \
                                     ('\\[', '\\]', 'sb'), \
                                     ('\\(', '\\)', 'pa'), \
                                     ('\\<', '\\>', 'lt'):

            states['strings'] += [
                (r'%[a-z]' + lbrace, String.Double, name + 'intp'),
                (r'%[A-Z]' + lbrace, String.Double, name + 'no-intp')
            ]

            states[name +'intp'] = [
                (r'' + rbrace + '[a-z]*', String.Double, "#pop"),
                include('enddoublestr')
            ]

            states[name +'no-intp'] = [
                (r'.*' + rbrace + '[a-z]*', String.Double , "#pop")
            ]

        return states