def _ThreeArgs(w_parser): # type: (_StringWordEmitter) -> bool_expr_t """Returns an expression tree to be evaluated.""" w0 = w_parser.Read() w1 = w_parser.Read() w2 = w_parser.Read() # NOTE: Order is important here. binary_id = match.BracketBinary(w1.s) if binary_id != Id.Undefined_Tok: return bool_expr.Binary(binary_id, w0, w2) if w1.s == '-a': return bool_expr.LogicalAnd(bool_expr.WordTest(w0), bool_expr.WordTest(w2)) if w1.s == '-o': return bool_expr.LogicalOr(bool_expr.WordTest(w0), bool_expr.WordTest(w2)) if w0.s == '!': w_parser.Rewind(2) child = _TwoArgs(w_parser) return bool_expr.LogicalNot(child) if w0.s == '(' and w2.s == ')': return bool_expr.WordTest(w1) p_die('Expected binary operator, got %r (3 args)', w1.s, word=w1)
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 = word.StringWord(Id.Word_Compound, a0) right = word.StringWord(Id.Word_Compound, a2) return bool_expr.BoolBinary(IdInstance(binary_id), left, right) if a1 == '-a': left = _StringWordTest(a0) right = _StringWordTest(a2) return bool_expr.LogicalAnd(left, right) if a1 == '-o': left = _StringWordTest(a0) right = _StringWordTest(a2) return bool_expr.LogicalOr(left, right) if a0 == '!': child = _TwoArgs(argv[1:]) return bool_expr.LogicalNot(child) if a0 == '(' and a2 == ')': return _StringWordTest(a1) p_die('Syntax error: binary operator expected, got %r (3 args)', a1)
def _ThreeArgs(w_parser): """Returns an expression tree to be evaluated.""" w0 = w_parser.Read() w1 = w_parser.Read() w2 = w_parser.Read() # NOTE: Order is important here. binary_id = _BINARY_LOOKUP.get(w1.s) if binary_id is not None: return bool_expr.BoolBinary(IdInstance(binary_id), w0, w2) if w1.s == '-a': return bool_expr.LogicalAnd(bool_expr.WordTest(w0), bool_expr.WordTest(w2)) if w1.s == '-o': return bool_expr.LogicalOr(bool_expr.WordTest(w0), bool_expr.WordTest(w2)) if w0.s == '!': w_parser.Rewind(2) child = _TwoArgs(w_parser) return bool_expr.LogicalNot(child) if w0.s == '(' and w2.s == ')': return bool_expr.WordTest(w1) p_die('Expected binary operator, got %r (3 args)', w1.s, word=w1)
def ParseTerm(self): # type: () -> bool_expr_t """ 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 bool_expr.LogicalAnd(left, right) else: return left