本文整理匯總了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))