Commit 366239b8 authored by Damien George's avatar Damien George
Browse files

py/parse: Factor logic when creating parse node from and-rule.

parent 02041bf2
...@@ -625,11 +625,10 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { ...@@ -625,11 +625,10 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
num_not_nil += 1; num_not_nil += 1;
} }
} }
if (emit_rule) { if (emit_rule || num_not_nil != 1) {
// need to add rule when num_not_nil==0 for, eg, atom_paren, testlist_comp_3b
push_result_rule(&parser, rule_src_line, rule, i); push_result_rule(&parser, rule_src_line, rule, i);
} else if (num_not_nil == 0) { } else {
push_result_rule(&parser, rule_src_line, rule, i); // needed for, eg, atom_paren, testlist_comp_3b
} else if (num_not_nil == 1) {
// single result, leave it on stack // single result, leave it on stack
mp_parse_node_t pn = MP_PARSE_NODE_NULL; mp_parse_node_t pn = MP_PARSE_NODE_NULL;
for (mp_uint_t x = 0; x < i; ++x) { 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) { ...@@ -639,8 +638,6 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
} }
} }
push_result_node(&parser, pn); push_result_node(&parser, pn);
} else {
push_result_rule(&parser, rule_src_line, rule, i);
} }
break; break;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment