コード例 #1
0
def _ThreeArgs(argv):
    """Returns an expression tree to be evaluated."""
    a0, a1, a2 = argv

    # NOTE: Order is important here.

    binary_id = _BINARY_LOOKUP.get(a1)
    if binary_id is not None:
        left = ast.StringWord(Id.Word_Compound, a0)
        right = ast.StringWord(Id.Word_Compound, a2)
        return ast.BoolBinary(binary_id, left, right)

    if a1 == '-a':
        left = _StringWordTest(a0)
        right = _StringWordTest(a2)
        return ast.LogicalAnd(left, right)

    if a1 == '-o':
        left = _StringWordTest(a0)
        right = _StringWordTest(a2)
        return ast.LogicalOr(left, right)

    if a0 == '!':
        child = _TwoArgs(argv[1:])
        return ast.LogicalNot(child)

    if a0 == '(' and a2 == ')':
        return _StringWordTest(a1)

    util.p_die('Syntax error: binary operator expected')
コード例 #2
0
ファイル: bool_parse.py プロジェクト: optionalg/oil
    def ParseExpr(self):
        """
    Iterative:
    Expr    : Term (OR Term)*

    Right recursion:
    Expr    : Term (OR Expr)?
    """
        left = self.ParseTerm()
        if self.op_id == Id.Op_DPipe:
            if not self._Next(): return None
            right = self.ParseExpr()
            return ast.LogicalOr(left, right)
        else:
            return left
コード例 #3
0
    def ParseExpr(self):
        """
    Iterative:
    Expr    : Term (OR Term)*

    Right recursion:
    Expr    : Term (OR Expr)?
    """
        left = self.ParseTerm()
        # [[ uses || while [ uses -o
        if self.op_id in (Id.Op_DPipe, Id.BoolUnary_o):
            if not self._Next(): return None
            right = self.ParseExpr()
            if not right: return None
            return ast.LogicalOr(left, right)
        else:
            return left