diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-08 01:00:27 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-08 01:00:27 -0800 |
| commit | 668c7baf55d07cb429b30b92ea8ce302f9de053a (patch) | |
| tree | b103ad6a8ee1ee29684953f93bd32ea8c875bc73 /grammar.c | |
| parent | 7da6cde0fdecf329de631f8be0c9f38231b3451e (diff) | |
Refactoring, moving visualization and virtual machine code into proper
files
Diffstat (limited to 'grammar.c')
| -rw-r--r-- | grammar.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -98,6 +98,19 @@ void push_backref(grammar_t *g, const char *name, match_t *capture) g->backrefs[i].op = op; } +size_t push_backrefs(grammar_t *g, match_t *m) +{ + if (m->op->op == VM_REF) return 0; + size_t count = 0; + if (m->op->op == VM_CAPTURE && m->op->args.capture.name) { + ++count; + push_backref(g, m->op->args.capture.name, m->child); + } + if (m->child) count += push_backrefs(g, m->child); + if (m->nextsibling) count += push_backrefs(g, m->nextsibling); + return count; +} + void pop_backrefs(grammar_t *g, size_t count) { check(count <= g->backrefcount, "Attempt to pop %ld backrefs when there are only %ld", count, g->backrefcount); |
