当前位置: 首页>>代码示例>>Python>>正文


Python lexers.CLexer方法代码示例

本文整理汇总了Python中pygments.lexers.CLexer方法的典型用法代码示例。如果您正苦于以下问题:Python lexers.CLexer方法的具体用法?Python lexers.CLexer怎么用?Python lexers.CLexer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.lexers的用法示例。


在下文中一共展示了lexers.CLexer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_guess_c_lexer

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def test_guess_c_lexer():
    code = '''
    #include <stdio.h>
    #include <stdlib.h>

    int main(void);

    int main(void) {
        uint8_t x = 42;
        uint8_t y = x + 1;

        /* exit 1 for success! */
        return 1;
    }
    '''
    lexer = guess_lexer(code)
    assert isinstance(lexer, CLexer) 
开发者ID:pygments,项目名称:pygments,代码行数:19,代码来源:test_cpp.py

示例2: testC

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def testC(self):
        """ Does the CompletionLexer work for C/C++?
        """
        lexer = CompletionLexer(CLexer())
        self.assertEqual(lexer.get_context("foo.bar"), [ "foo", "bar" ])
        self.assertEqual(lexer.get_context("foo->bar"), [ "foo", "bar" ])

        lexer = CompletionLexer(CppLexer())
        self.assertEqual(lexer.get_context("Foo::Bar"), [ "Foo", "Bar" ]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_completion_lexer.py

示例3: get_highlighted_code

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def get_highlighted_code(text, python=False):
    try:
        from pygments import highlight
    except ImportError:
        return text
    else:
        from pygments.lexers import CLexer, PythonLexer
        from pygments.formatters import TerminalFormatter

        return highlight(text, CLexer() if not python else PythonLexer(),
                         TerminalFormatter()) 
开发者ID:inducer,项目名称:loopy,代码行数:13,代码来源:execution.py

示例4: lexer

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def lexer():
    yield CLexer() 
开发者ID:pygments,项目名称:pygments,代码行数:4,代码来源:test_clexer.py

示例5: color_line

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def color_line(self, line):
        """
        """
        lexer = CLexer()
        tokens = list(lexer.get_tokens(line))
        new_line = ""
        for t in tokens:
            ttype = t[0]
            ttext = str(t[1])
            if ttype == Token.Text:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_INSN)

            elif ttype == Token.Text.Whitespace:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_INSN)

            elif ttype == Token.Error:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_ERROR)

            elif ttype == Token.Other:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_DSTR)

            elif ttype == Token.Keyword:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_KEYWORD)

            elif ttype == Token.Name:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_LIBNAME)

            elif ttype == Token.Literal:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_LOCNAME)

            elif ttype == Token.Literal.String:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_STRING)

            elif ttype == Token.Literal.Number:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_DNUM)

            elif ttype == Token.Operator:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_ALTOP)

            elif ttype == Token.Punctuation:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_SYMBOL)

            elif ttype == Token.Comment:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_REGCMT)

            elif ttype == Token.Comment.Single:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_REGCMT)

            elif ttype == Token.Generic:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_CREFTAIL)

            else:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_CREFTAIL)
        return new_line 
开发者ID:Cisco-Talos,项目名称:GhIDA,代码行数:56,代码来源:ghida.py

示例6: add_comment

# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import CLexer [as 别名]
def add_comment(self):
        """
        Add a commment to the selected line
        """
        print("GhIDA:: [DEBUG] add_comment called")
        colored_line = self.GetCurrentLine(notags=1)
        if not colored_line:
            idaapi.warning("Select a line")
            return False

        # Use pygments to parse the line to check if there are comments
        line = idaapi.tag_remove(colored_line)
        lexer = CLexer()
        tokens = list(lexer.get_tokens(line))
        text = ""
        text_comment = ""
        for t in tokens:
            ttype = t[0]
            ttext = str(t[1])
            if ttype == Token.Comment.Single:
                text_comment = ttext.replace('//', '').strip()
            else:
                text += ttext

        # Get the new comment
        comment = gl.display_comment_form(text_comment)
        if not comment or len(comment) == 0:
            return False
        comment = comment.replace("//", "").replace("\n", " ")
        comment = comment.strip()

        # Create the new text
        full_comment = "\t// %s" % comment
        text = text.rstrip()
        new_text = text + full_comment
        text_colored = self.color_line(new_text)

        num_line = self.GetLineNo()
        self.EditLine(num_line, text_colored)
        self.RefreshCurrent()

        # Add comment to cache
        COMMENTS_CACHE.add_comment_to_cache(self.__ea, num_line, full_comment)

        print("GhIDA:: [DEBUG] Added comment to #line: %d (%s)" %
              (num_line, new_text))
        return 
开发者ID:Cisco-Talos,项目名称:GhIDA,代码行数:49,代码来源:ghida.py


注:本文中的pygments.lexers.CLexer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。