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