def ReadWord(self, unused_lex_mode): # type: (lex_mode_t) -> word__String """Interface for bool_parse.py. TODO: This should probably be word_t """ if self.i == self.n: # Does it make sense to define Eof_Argv or something? # TODO: Add a way to show this location. Show 1 char past the right-most # spid of the last word? But we only have the left-most spid. w = word.String(Id.Eof_Real, '', runtime.NO_SPID) return w #log('ARGV %s i %d', self.argv, self.i) s = self.cmd_val.argv[self.i] left_spid = self.cmd_val.arg_spids[self.i] self.i += 1 # default is an operand word id_ = match.BracketUnary(s) if id_ == Id.Undefined_Tok: id_ = match.BracketBinary(s) if id_ == Id.Undefined_Tok: id_ = match.BracketOther(s) if id_ == Id.Undefined_Tok: id_ = Id.Word_Compound # NOTE: We only have the left spid now. It might be useful to add the # right one. w = word.String(id_, s, left_spid) return w
def _TwoArgs(w_parser): # type: (_StringWordEmitter) -> bool_expr_t """Returns an expression tree to be evaluated.""" w0 = w_parser.Read() w1 = w_parser.Read() s0 = w0.s if s0 == '!': return bool_expr.LogicalNot(bool_expr.WordTest(w1)) unary_id = Id.Undefined_Tok # Oil's preferred long flags if w0.s.startswith('--'): if s0 == '--dir': unary_id = Id.BoolUnary_d elif s0 == '--exists': unary_id = Id.BoolUnary_e elif s0 == '--file': unary_id = Id.BoolUnary_f elif s0 == '--symlink': unary_id = Id.BoolUnary_L if unary_id == Id.Undefined_Tok: unary_id = match.BracketUnary(w0.s) if unary_id == Id.Undefined_Tok: p_die('Expected unary operator, got %r (2 args)', w0.s, word=w0) return bool_expr.Unary(unary_id, w1)
def _TwoArgs(w_parser): # type: (_StringWordEmitter) -> bool_expr_t """Returns an expression tree to be evaluated.""" w0 = w_parser.Read() w1 = w_parser.Read() if w0.s == '!': return bool_expr.LogicalNot(bool_expr.WordTest(w1)) unary_id = match.BracketUnary(w0.s) if unary_id == -1: # TODO: # - separate lookup by unary p_die('Expected unary operator, got %r (2 args)', w0.s, word=w0) return bool_expr.Unary(unary_id, w1)
def _TwoArgs(w_parser): # type: (_StringWordEmitter) -> bool_expr_t """Returns an expression tree to be evaluated.""" w0 = w_parser.Read() # TODO: Implement --dir, --file, --exists here # --symlink, maybe --executable w1 = w_parser.Read() if w0.s == '!': return bool_expr.LogicalNot(bool_expr.WordTest(w1)) unary_id = match.BracketUnary(w0.s) if unary_id == Id.Undefined_Tok: # TODO: # - separate lookup by unary p_die('Expected unary operator, got %r (2 args)', w0.s, word=w0) return bool_expr.Unary(unary_id, w1)