def Parse(self): # type: () -> List[printf_part_t] self._Next(lex_mode_e.PrintfOuter) parts = [] # type: List[printf_part_t] while True: if (self.token_kind == Kind.Char or self.token_type == Id.Format_EscapedPercent): # TODO: Could handle Char_BadBackslash. # Maybe make that a different kind? parts.append(printf_part.Literal(self.cur_token)) elif self.token_type == Id.Format_Percent: parts.append(self._ParseFormatStr()) elif self.token_type == Id.Eof_Real: break else: p_die('Invalid token %r', token=self.cur_token) self._Next(lex_mode_e.PrintfOuter) return parts
def Parse(self): # type: () -> List[printf_part_t] self._Next(lex_mode_e.PrintfOuter) parts = [] # type: List[printf_part_t] while True: if (self.token_kind == Kind.Char or self.token_type == Id.Format_EscapedPercent or self.token_type == Id.Unknown_Backslash): # Note: like in echo -e, we don't fail with Unknown_Backslash here # when shopt -u pasre_backslash because it's at runtime rather than # parse time. # Users should use $'' or the future static printf ${x %.3f}. parts.append(printf_part.Literal(self.cur_token)) elif self.token_type == Id.Format_Percent: parts.append(self._ParseFormatStr()) elif self.token_type == Id.Eof_Real: break else: raise AssertionError() self._Next(lex_mode_e.PrintfOuter) return parts
def Parse(self): # type: () -> List[printf_part_t] self._Next(lex_mode_e.PrintfOuter) parts = [] # type: List[printf_part_t] while True: if (self.token_kind == Kind.Char or self.token_type == Id.Format_EscapedPercent or self.token_type == Id.Unknown_Backslash): # TODO: Could fail on Unknown_Backslash with strict_backslash? But it # would happen at runtime rather than parse time. I'd rather have a # statically parsed printf like ${x %.3f} parts.append(printf_part.Literal(self.cur_token)) elif self.token_type == Id.Format_Percent: parts.append(self._ParseFormatStr()) elif self.token_type == Id.Eof_Real: break else: raise AssertionError() self._Next(lex_mode_e.PrintfOuter) return parts