本文整理汇总了Python中pyparsing.NoMatch方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.NoMatch方法的具体用法?Python pyparsing.NoMatch怎么用?Python pyparsing.NoMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing
的用法示例。
在下文中一共展示了pyparsing.NoMatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_matcher_element
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import NoMatch [as 别名]
def _make_matcher_element(self):
return self._set_matcher_element_attributes(pyparsing.NoMatch())
示例2: _make_matcher_element
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import NoMatch [as 别名]
def _make_matcher_element(self):
# Handle the case where use_current_match is True.
if self.use_current_match is True:
current_match = self.current_match
if current_match is None:
result = pyparsing.NoMatch()
elif current_match == "":
result = pyparsing.Empty()
else:
result = pyparsing.Literal(self.current_match)
# Set the parse action and return the element.
return result.setParseAction(self._parse_action)
# Otherwise build a list of next possible literals. Make the required stack
# of child-parent pairs.
stack = []
p1, p2 = self, self.parent
while p1 and p2:
stack.append((p1, p2))
# Move both pivots further up the tree.
p1 = p1.parent
p2 = p2.parent
# Build a list of next literals using the stack.
next_literals, _ = _collect_next_literals(stack, 0, True, False)
# De-duplicate the list.
next_literals = set(next_literals)
word = pyparsing.Regex(_word_regex_str, re.UNICODE)
if next_literals:
# Check if there is a next dictation literal. If there is, only match
# one word for this expansion.
if _word_regex_str in next_literals:
result = word
# Otherwise build an element to match one or more words stopping on
# any of the next literals so that they aren't matched as dictation.
else:
next_literals = list(map(pyparsing.Literal, next_literals))
result = pyparsing.OneOrMore(
word, stopOn=pyparsing.Or(next_literals)
)
else:
# Handle the case of no literals ahead by allowing one or more Unicode
# words without restrictions.
result = pyparsing.OneOrMore(word)
return self._set_matcher_element_attributes(result)