本文整理汇总了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
示例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
示例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()