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


Python pyparsing.infixNotation方法代码示例

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


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

示例1: expression_parser

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import infixNotation [as 别名]
def expression_parser(self):
        """A function returning a (pyparsing) parser for parsing C expressions.

        Returns:
            a (pyparsing) parser for parsing C expressions.
        """
        precedence = (self._build_precedence(_UNARY_MACROS) +
                      self._build_precedence(_PRECEDENCE))

        self.expression = pyparsing.Forward()

        # pylint: disable=expression-not-assigned
        self.expression << (
            pyparsing.infixNotation(
                baseExpr=self._base_or_array_expression(),
                opList=precedence,
            )
        )

        return self.expression 
开发者ID:google,项目名称:rekall,代码行数:22,代码来源:expression_parser.py

示例2: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import infixNotation [as 别名]
def __init__(self):
        # create parsing grammer
        sQStringLiteral = pyparsing.QuotedString("'")
        sQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, False))

        dQStringLiteral = pyparsing.QuotedString('"', '\\')
        dQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, True))

        stringLiteral = sQStringLiteral | dQStringLiteral

        functionCall = pyparsing.Forward()
        functionArg = stringLiteral | functionCall
        functionCall << pyparsing.Word(pyparsing.alphas, pyparsing.alphanums+'-') + \
            pyparsing.Suppress('(') + \
            pyparsing.Optional(functionArg +
                pyparsing.ZeroOrMore(pyparsing.Suppress(',') + functionArg)) + \
            pyparsing.Suppress(')')
        functionCall.setParseAction(
            lambda s, loc, toks: FunctionCall(s, loc, toks))

        predExpr = pyparsing.infixNotation(
            stringLiteral ^ functionCall ,
            [
                ('!',  1, pyparsing.opAssoc.RIGHT, lambda s, loc, toks: NotOperator(s, loc, toks)),
                ('<',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('<=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('==', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('!=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('&&', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator)),
                ('||', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator))
            ])

        self.__ifgrammer = predExpr 
开发者ID:BobBuildTool,项目名称:bob,代码行数:39,代码来源:stringparser.py

示例3: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import infixNotation [as 别名]
def __init__(self):
        """
        Create a parser that parse arithmetic expressions. They can
        contains variable identifiers or raw numbers. The meaning
        for the identifiers is left to the
        """
        number = p.Regex(r'\d+(\.\d*)?([eE]\d+)?')
        identifier = p.Word(p.alphas)
        terminal = identifier | number
        self._expr = p.infixNotation(terminal, [
            (p.oneOf('* /'), 2, p.opAssoc.LEFT),
            (p.oneOf('+ -'), 2, p.opAssoc.LEFT)
        ]) + p.stringEnd() 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:15,代码来源:expression.py


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