Skip to content

Commit 366239b

Browse files
committed
py/parse: Factor logic when creating parse node from and-rule.
1 parent 02041bf commit 366239b

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

py/parse.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,10 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
625625
num_not_nil += 1;
626626
}
627627
}
628-
if (emit_rule) {
628+
if (emit_rule || num_not_nil != 1) {
629+
// need to add rule when num_not_nil==0 for, eg, atom_paren, testlist_comp_3b
629630
push_result_rule(&parser, rule_src_line, rule, i);
630-
} else if (num_not_nil == 0) {
631-
push_result_rule(&parser, rule_src_line, rule, i); // needed for, eg, atom_paren, testlist_comp_3b
632-
} else if (num_not_nil == 1) {
631+
} else {
633632
// single result, leave it on stack
634633
mp_parse_node_t pn = MP_PARSE_NODE_NULL;
635634
for (mp_uint_t x = 0; x < i; ++x) {
@@ -639,8 +638,6 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
639638
}
640639
}
641640
push_result_node(&parser, pn);
642-
} else {
643-
push_result_rule(&parser, rule_src_line, rule, i);
644641
}
645642
break;
646643
}

0 commit comments

Comments
 (0)