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


Python lexer.Lexer方法代码示例

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


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

示例1: print_lexer

# 需要导入模块: from pygments import lexer [as 别名]
# 或者: from pygments.lexer import Lexer [as 别名]
def print_lexer(
    body: str, lexer: Lexer, label: str = None, prefix: str = None, indent: int = None
):
    if COLORIZE:
        prefix_str = prefix + " " if prefix else ""
        if prefix_str or indent:
            prefix_body = prefix_str + " " * (indent or 0)
            lexer.add_filter(PrefixFilter(prefix=prefix_body))
        tokens = list(pygments.lex(body, lexer=lexer))
        if label:
            fmt_label = [("fg:ansimagenta", label)]
            if prefix_str:
                fmt_label.insert(0, ("", prefix_str))
            print_formatted(FormattedText(fmt_label))
        print_formatted(PygmentsTokens(tokens))
    else:
        print_ext(body, label=label, prefix=prefix) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:19,代码来源:utils.py

示例2: get_lexers

# 需要导入模块: from pygments import lexer [as 别名]
# 或者: from pygments.lexer import Lexer [as 别名]
def get_lexers(main_lex, exam_lex, tool_lex):
    """ gets all the lexer wrappers """
    if not main_lex:
        return None, None, None
    lexer = None
    if issubclass(main_lex, PromptLex):
        lexer = main_lex
    elif issubclass(main_lex, PygLex):
        lexer = PygmentsLexer(main_lex)

    if exam_lex:
        if issubclass(exam_lex, PygLex):
            exam_lex = PygmentsLexer(exam_lex)
    if tool_lex:
        if issubclass(tool_lex, PygLex):
            tool_lex = PygmentsLexer(tool_lex)
    return lexer, exam_lex, tool_lex 
开发者ID:Azure,项目名称:azure-cli-shell,代码行数:19,代码来源:layout.py

示例3: from_pygments_lexer_cls

# 需要导入模块: from pygments import lexer [as 别名]
# 或者: from pygments.lexer import Lexer [as 别名]
def from_pygments_lexer_cls(cls, lexer_cls: "PygmentsLexerCls") -> "RegexSync":
        """
        Create a :class:`.RegexSync` instance for this Pygments lexer class.
        """
        patterns = {
            # For Python, start highlighting at any class/def block.
            "Python": r"^\s*(class|def)\s+",
            "Python 3": r"^\s*(class|def)\s+",
            # For HTML, start at any open/close tag definition.
            "HTML": r"<[/a-zA-Z]",
            # For javascript, start at a function.
            "JavaScript": r"\bfunction\b"
            # TODO: Add definitions for other languages.
            #       By default, we start at every possible line.
        }
        p = patterns.get(lexer_cls.name, "^")
        return cls(p) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:19,代码来源:pygments.py

示例4: __init__

# 需要导入模块: from pygments import lexer [as 别名]
# 或者: from pygments.lexer import Lexer [as 别名]
def __init__(
        self,
        pygments_lexer_cls: Type["PygmentsLexerCls"],
        sync_from_start: FilterOrBool = True,
        syntax_sync: Optional[SyntaxSync] = None,
    ) -> None:

        self.pygments_lexer_cls = pygments_lexer_cls
        self.sync_from_start = to_filter(sync_from_start)

        # Instantiate the Pygments lexer.
        self.pygments_lexer = pygments_lexer_cls(
            stripnl=False, stripall=False, ensurenl=False
        )

        # Create syntax sync instance.
        self.syntax_sync = syntax_sync or RegexSync.from_pygments_lexer_cls(
            pygments_lexer_cls
        ) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:21,代码来源:pygments.py

示例5: fetch_lexer

# 需要导入模块: from pygments import lexer [as 别名]
# 或者: from pygments.lexer import Lexer [as 别名]
def fetch_lexer(
        source: str,
        language: str = None,
        filename: str = None,
        mime_type: str = None
) -> Lexer:
    """

    :param source:
    :param language:
    :param filename:
    :param mime_type:
    :return:
    """

    environ.abort_thread()

    try:
        if language:
            return get_lexer_by_name(language, stripall=True)
    except ClassNotFound:
        pass

    if filename:
        try:
            return get_lexer_for_filename(filename, stripall=True)
        except ClassNotFound:
            pass

        try:
            return guess_lexer_for_filename(filename, source, stripall=True)
        except ClassNotFound:
            pass

    try:
        if mime_type:
            return get_lexer_for_mimetype(mime_type, stripall=True)
    except ClassNotFound:
        pass

    try:
        return guess_lexer(source, stripall=True)
    except ClassNotFound:
        return TextLexer() 
开发者ID:sernst,项目名称:cauldron,代码行数:46,代码来源:syntax_highlighting.py


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