summaryrefslogtreecommitdiffstatshomepage
path: root/py/parse.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-07-24 14:35:57 +0000
committerDamien George <damien.p.george@gmail.com>2015-07-24 14:35:57 +0000
commitfa7c61dfab0822619451673d726a5b444d3a9d28 (patch)
tree8de944f13e68c920ff44b43e8f04fef590cb468b /py/parse.c
parentd241c2a5926c0c8147a05b10ad3e7a54d480f55b (diff)
downloadmicropython-fa7c61dfab0822619451673d726a5b444d3a9d28.tar.gz
micropython-fa7c61dfab0822619451673d726a5b444d3a9d28.zip
py/parse: De-duplicate and simplify code for parser "or" rule.
Diffstat (limited to 'py/parse.c')
-rw-r--r--py/parse.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/py/parse.c b/py/parse.c
index c00c590e91..ad13a90309 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -448,36 +448,24 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
} else {
backtrack = false;
}
- for (; i < n - 1; ++i) {
- switch (rule->arg[i] & RULE_ARG_KIND_MASK) {
- case RULE_ARG_TOK:
- if (lex->tok_kind == (rule->arg[i] & RULE_ARG_ARG_MASK)) {
- push_result_token(&parser);
- mp_lexer_to_next(lex);
- goto next_rule;
- }
- break;
- case RULE_ARG_RULE:
- rule_or_no_other_choice:
- push_rule(&parser, rule_src_line, rule, i + 1); // save this or-rule
- push_rule_from_arg(&parser, rule->arg[i]); // push child of or-rule
+ for (; i < n; ++i) {
+ uint16_t kind = rule->arg[i] & RULE_ARG_KIND_MASK;
+ if (kind == RULE_ARG_TOK) {
+ if (lex->tok_kind == (rule->arg[i] & RULE_ARG_ARG_MASK)) {
+ push_result_token(&parser);
+ mp_lexer_to_next(lex);
goto next_rule;
- default:
- assert(0);
- goto rule_or_no_other_choice; // to help flow control analysis
- }
- }
- if ((rule->arg[i] & RULE_ARG_KIND_MASK) == RULE_ARG_TOK) {
- if (lex->tok_kind == (rule->arg[i] & RULE_ARG_ARG_MASK)) {
- push_result_token(&parser);
- mp_lexer_to_next(lex);
+ }
} else {
- backtrack = true;
+ assert(kind == RULE_ARG_RULE);
+ if (i + 1 < n) {
+ push_rule(&parser, rule_src_line, rule, i + 1); // save this or-rule
+ }
+ push_rule_from_arg(&parser, rule->arg[i]); // push child of or-rule
goto next_rule;
}
- } else {
- push_rule_from_arg(&parser, rule->arg[i]);
}
+ backtrack = true;
break;
case RULE_ACT_AND: {