當前位置: 首頁>>代碼示例>>Python>>正文


Python pyparsing.Or方法代碼示例

本文整理匯總了Python中pyparsing.Or方法的典型用法代碼示例。如果您正苦於以下問題:Python pyparsing.Or方法的具體用法?Python pyparsing.Or怎麽用?Python pyparsing.Or使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyparsing的用法示例。


在下文中一共展示了pyparsing.Or方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: compile

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def compile(self, ignore_tags=False):
        super(AlternativeSet, self).compile()
        if self._weights:
            self._validate_weights()

            # Create a string with w=weight and e=compiled expansion
            # such that:
            # /<w 0>/ <e 0> | ... | /<w n-1>/ <e n-1>
            alt_set = "|".join([
                "/%.4f/ %s" % (float(self._weights[e]), e.compile(ignore_tags))
                for e in self.children
            ])
        else:
            # Or do the same thing without the weights
            alt_set = "|".join([
                e.compile(ignore_tags) for e in self.children
            ])

        if self.tag and not ignore_tags:
            return "(%s)%s" % (alt_set, self.compiled_tag)
        else:
            return "(%s)" % alt_set 
開發者ID:Danesprite,項目名稱:pyjsgf,代碼行數:24,代碼來源:expansions.py

示例2: _make_matcher_element

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def _make_matcher_element(self):
        # Return an element that can match the alternatives.
        if self._weights:
            self._validate_weights()

            # Exclude alternatives that have a weight value of 0.
            children = []
            for e, w in self._weights.items():
                if w > 0:
                    children.append((e, w))

            # Sort the list by weight (highest to lowest).
            children = [e for e, _ in sorted(children, key=lambda x: x[1])]
            children.reverse()
        else:
            children = self.children

        return self._set_matcher_element_attributes(pyparsing.Or([
            e.matcher_element for e in children
        ])) 
開發者ID:Danesprite,項目名稱:pyjsgf,代碼行數:22,代碼來源:expansions.py

示例3: _build_precedence

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def _build_precedence(self, precedence_table):
        # C's & dereference operator.
        precedence = []
        for operators, arity, associativity in precedence_table:
            operators = [pyparsing.Literal(x) for x in operators]

            if arity in [_UNARY, _BINARY]:
                operators = pyparsing.Or(operators)

            precedence.append((
                operators,
                arity,
                associativity,
                self._construct_operator(arity),
            ))
        return precedence 
開發者ID:google,項目名稱:rekall,代碼行數:18,代碼來源:expression_parser.py

示例4: complete_statement

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def complete_statement(self, line):
        """Keep accepting lines of input until the command is complete."""
        if (not line) or (
            not pyparsing.Or(self.commentGrammars).
                setParseAction(lambda x: '').transformString(line)):
            raise EmptyStatement()
        statement = self.parsed(line)
        while statement.parsed.multilineCommand and (statement.parsed.terminator == ''):
            statement = '%s\n%s' % (statement.parsed.raw,
                                    self.pseudo_raw_input(self.continuation_prompt))
            statement = self.parsed(statement)
        if not statement.parsed.command:
            raise EmptyStatement()
        return statement 
開發者ID:OpenTrading,項目名稱:OpenTrader,代碼行數:16,代碼來源:cmd2plus.py

示例5: complete_statement

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def complete_statement(self, line):
        """Keep accepting lines of input until the command is complete."""
        if (not line) or (
            not pyparsing.Or(self.commentGrammars).
            setParseAction(lambda x: '').transformString(line)):
            raise EmptyStatement()
        statement = self.parsed(line)
        while statement.parsed.multilineCommand and (statement.parsed.terminator == ''):
            statement = '%s\n%s' % (statement.parsed.raw,
                                    self.pseudo_raw_input(self.continuation_prompt))
            statement = self.parsed(statement)
        if not statement.parsed.command:
            raise EmptyStatement()
        return statement 
開發者ID:n0tr00t,項目名稱:Beehive,代碼行數:16,代碼來源:cmd2.py

示例6: test_none_name

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [as 別名]
def test_none_name(self):
        grammar = Or(["foo", "bar"])
        railroad = to_railroad(grammar)
        assert len(railroad) == 1
        assert railroad[0].name is not None 
開發者ID:pyparsing,項目名稱:pyparsing,代碼行數:7,代碼來源:test_diagram.py

示例7: _make_matcher_element

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import Or [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) 
開發者ID:Danesprite,項目名稱:pyjsgf,代碼行數:53,代碼來源:expansions.py


注:本文中的pyparsing.Or方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。