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, got %r (3 args)', a1)
def ParseTerm(self): """ Term : Negated (AND Negated)* Right recursion: Term : Negated (AND Term)? """ left = self.ParseNegatedFactor() # [[ uses && but [ uses -a if self.op_id in (Id.Op_DAmp, Id.BoolUnary_a): self._Next() right = self.ParseTerm() return ast.LogicalAnd(left, right) else: return left
def ParseTerm(self): """ Term : Negated (AND Negated)* Right recursion: Term : Negated (AND Term)? """ left = self.ParseNegatedFactor() if not left: return None # TODO: An exception should handle this case. # [[ uses && while [ uses -a if self.op_id in (Id.Op_DAmp, Id.BoolUnary_a): if not self._Next(): return None right = self.ParseTerm() if not right: return None return ast.LogicalAnd(left, right) else: return left