本文整理汇总了Python中prompt_toolkit.contrib.regular_languages.compiler.compile方法的典型用法代码示例。如果您正苦于以下问题:Python compiler.compile方法的具体用法?Python compiler.compile怎么用?Python compiler.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.contrib.regular_languages.compiler
的用法示例。
在下文中一共展示了compiler.compile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grammar
# 需要导入模块: from prompt_toolkit.contrib.regular_languages import compiler [as 别名]
# 或者: from prompt_toolkit.contrib.regular_languages.compiler import compile [as 别名]
def grammar():
grams = getClientGrams() + getNewClientGrams()
return compile("".join(grams))
示例2: __init__
# 需要导入模块: from prompt_toolkit.contrib.regular_languages import compiler [as 别名]
# 或者: from prompt_toolkit.contrib.regular_languages.compiler import compile [as 别名]
def __init__(self):
# Compile grammar.
g = compile(
r"""
# First we have an executable.
(?P<executable>[^\s]+)
# Ignore literals in between.
(
\s+
("[^"]*" | '[^']*' | [^'"]+ )
)*
\s+
# Filename as parameters.
(
(?P<filename>[^\s]+) |
"(?P<double_quoted_filename>[^\s]+)" |
'(?P<single_quoted_filename>[^\s]+)'
)
""",
escape_funcs={
'double_quoted_filename': (lambda string: string.replace('"', '\\"')),
'single_quoted_filename': (lambda string: string.replace("'", "\\'")),
},
unescape_funcs={
'double_quoted_filename': (lambda string: string.replace('\\"', '"')), # XXX: not enterily correct.
'single_quoted_filename': (lambda string: string.replace("\\'", "'")),
})
# Create GrammarCompleter
super(SystemCompleter, self).__init__(
g,
{
'executable': ExecutableCompleter(),
'filename': PathCompleter(only_directories=False, expanduser=True),
'double_quoted_filename': PathCompleter(only_directories=False, expanduser=True),
'single_quoted_filename': PathCompleter(only_directories=False, expanduser=True),
})
示例3: _create_grammar
# 需要导入模块: from prompt_toolkit.contrib.regular_languages import compiler [as 别名]
# 或者: from prompt_toolkit.contrib.regular_languages.compiler import compile [as 别名]
def _create_grammar():
patterns = map(_build_pattern, [
(command, operand_pattern)
for (command, (_, operand_pattern, _)) in COMMANDS.items()])
patterns = '|'.join(patterns)
return compiler.compile(patterns)
示例4: initializeGrammar
# 需要导入模块: from prompt_toolkit.contrib.regular_languages import compiler [as 别名]
# 或者: from prompt_toolkit.contrib.regular_languages.compiler import compile [as 别名]
def initializeGrammar(self):
# TODO Do we really need both self.allGrams and self.grams
self.grams = getAllGrams(*self.allGrams)
self.grammar = compile("".join(self.grams))
示例5: grammar
# 需要导入模块: from prompt_toolkit.contrib.regular_languages import compiler [as 别名]
# 或者: from prompt_toolkit.contrib.regular_languages.compiler import compile [as 别名]
def grammar():
utilGrams = getUtilGrams()
nodeGrams = getNodeGrams()
clientGrams = getClientGrams()
grams = getAllGrams(utilGrams, nodeGrams, clientGrams)
return compile("".join(grams))