@@ -241,6 +241,135 @@ _resize_tokens_array(Parser *p) {
241241 return 0 ;
242242}
243243
244+ // Fast path attached to the expression precedence chain's entry rules via
245+ // the @fastpath meta in the grammar. A bare NAME/NUMBER atom followed by a
246+ // token that cannot start or continue a binary/postfix expression is a
247+ // complete expression, so it is built directly instead of descending the
248+ // whole chain. Returns 1 if it produced a result (stored in *result), 0 to
249+ // fall through to the rule's alternatives. The second token is only
250+ // examined when the first is NAME/NUMBER: the precedence chain fills it
251+ // too in that case, so error reporting (which keys off p->fill) observes
252+ // an identical token fill state.
253+ int
254+ _PyPegen_atom_fast_path (Parser * p , void * result )
255+ {
256+ if (p -> mark == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
257+ p -> error_indicator = 1 ;
258+ * (void * * )result = NULL ;
259+ return 1 ;
260+ }
261+ Token * t = p -> tokens [p -> mark ];
262+ if (t -> type != NAME && t -> type != NUMBER ) {
263+ return 0 ;
264+ }
265+ if (p -> mark + 1 == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
266+ p -> error_indicator = 1 ;
267+ * (void * * )result = NULL ;
268+ return 1 ;
269+ }
270+ switch (p -> tokens [p -> mark + 1 ]-> type ) {
271+ case COMMA :
272+ case RPAR :
273+ case RSQB :
274+ case RBRACE :
275+ case COLON :
276+ case NEWLINE :
277+ case SEMI :
278+ case EQUAL :
279+ case ENDMARKER :
280+ break ;
281+ default :
282+ return 0 ;
283+ }
284+ expr_ty res = (t -> type == NAME )
285+ ? _PyPegen_name_token (p ) : _PyPegen_number_token (p );
286+ * (void * * )result = res ;
287+ return 1 ;
288+ }
289+
290+ // Fast path for subscript elements, attached to the slice rule via the
291+ // (fastpath=function) grammar flag: a bare NAME/NUMBER atom followed by
292+ // ',' or ']' is a complete slice, so it is built directly instead of
293+ // trying the subscript alternative (which fails and backtracks) first.
294+ // Same contract and token-fill discipline as _PyPegen_atom_fast_path().
295+ int
296+ _PyPegen_slice_fast_path (Parser * p , void * result )
297+ {
298+ if (p -> mark == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
299+ p -> error_indicator = 1 ;
300+ * (void * * )result = NULL ;
301+ return 1 ;
302+ }
303+ Token * t = p -> tokens [p -> mark ];
304+ if (t -> type != NAME && t -> type != NUMBER ) {
305+ return 0 ;
306+ }
307+ if (p -> mark + 1 == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
308+ p -> error_indicator = 1 ;
309+ * (void * * )result = NULL ;
310+ return 1 ;
311+ }
312+ switch (p -> tokens [p -> mark + 1 ]-> type ) {
313+ case COMMA :
314+ case RSQB :
315+ break ;
316+ default :
317+ return 0 ;
318+ }
319+ expr_ty res = (t -> type == NAME )
320+ ? _PyPegen_name_token (p ) : _PyPegen_number_token (p );
321+ * (void * * )result = res ;
322+ return 1 ;
323+ }
324+
325+ // Fast path for assignment targets, attached to target_with_star_atom via
326+ // the (fastpath=function) grammar flag: a bare NAME followed by a token
327+ // that cannot extend a target parses to that name in Store context,
328+ // skipping the t_primary attribute/subscript attempts. NAME only: literals
329+ // must keep failing through the normal path so "cannot assign to literal"
330+ // errors are unaffected. Same contract and token-fill discipline as
331+ // _PyPegen_atom_fast_path().
332+ int
333+ _PyPegen_target_fast_path (Parser * p , void * result )
334+ {
335+ if (p -> mark == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
336+ p -> error_indicator = 1 ;
337+ * (void * * )result = NULL ;
338+ return 1 ;
339+ }
340+ Token * t = p -> tokens [p -> mark ];
341+ if (t -> type != NAME ) {
342+ return 0 ;
343+ }
344+ if (p -> mark + 1 == p -> fill && _PyPegen_fill_token (p ) < 0 ) {
345+ p -> error_indicator = 1 ;
346+ * (void * * )result = NULL ;
347+ return 1 ;
348+ }
349+ switch (p -> tokens [p -> mark + 1 ]-> type ) {
350+ case EQUAL :
351+ case COMMA :
352+ case RPAR :
353+ case RSQB :
354+ case COLON :
355+ case NEWLINE :
356+ break ;
357+ default :
358+ return 0 ;
359+ }
360+ expr_ty name = _PyPegen_name_token (p );
361+ if (name == NULL ) {
362+ * (void * * )result = NULL ;
363+ return 1 ;
364+ }
365+ expr_ty res = _PyPegen_set_expr_context (p , name , Store );
366+ if (res == NULL ) {
367+ p -> error_indicator = 1 ;
368+ }
369+ * (void * * )result = res ;
370+ return 1 ;
371+ }
372+
244373int
245374_PyPegen_fill_token (Parser * p )
246375{
0 commit comments