We are permissive than the original implementation because we would allow whitespace between the expression and the suffix while the IPython implementation doesn't allow it. For example, `foo ?` would be valid in our case but invalid for IPython.
(parser: &mut Parser, expr: &Expr, buffer: &mut String)
| 1138 | // between the expression and the suffix while the IPython implementation doesn't allow it. |
| 1139 | // For example, `foo ?` would be valid in our case but invalid for IPython. |
| 1140 | fn unparse_expr(parser: &mut Parser, expr: &Expr, buffer: &mut String) { |
| 1141 | match expr { |
| 1142 | Expr::Name(ast::ExprName { id, .. }) => { |
| 1143 | buffer.push_str(id.as_str()); |
| 1144 | } |
| 1145 | Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { |
| 1146 | unparse_expr(parser, value, buffer); |
| 1147 | buffer.push('['); |
| 1148 | |
| 1149 | if let Expr::NumberLiteral(ast::ExprNumberLiteral { |
| 1150 | value: ast::Number::Int(integer), |
| 1151 | .. |
| 1152 | }) = &**slice |
| 1153 | { |
| 1154 | let _ = write!(buffer, "{integer}"); |
| 1155 | } else { |
| 1156 | parser.add_error( |
| 1157 | ParseErrorType::OtherError( |
| 1158 | "Only integer literals are allowed in subscript expressions \ |
| 1159 | in help end escape command" |
| 1160 | .to_string(), |
| 1161 | ), |
| 1162 | slice.range(), |
| 1163 | ); |
| 1164 | buffer.push_str(parser.src_text(slice.range())); |
| 1165 | } |
| 1166 | |
| 1167 | buffer.push(']'); |
| 1168 | } |
| 1169 | Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => { |
| 1170 | unparse_expr(parser, value, buffer); |
| 1171 | buffer.push('.'); |
| 1172 | buffer.push_str(attr.as_str()); |
| 1173 | } |
| 1174 | _ => { |
| 1175 | parser.add_error( |
| 1176 | ParseErrorType::OtherError( |
| 1177 | "Expected name, subscript or attribute expression \ |
| 1178 | in help end escape command" |
| 1179 | .to_string(), |
| 1180 | ), |
| 1181 | expr, |
| 1182 | ); |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | let start = self.node_start(); |
| 1188 | self.bump(TokenKind::Question); |